@@ -16,23 +16,69 @@ set(CMAKE_AUTOMOC ON)
1616set (CMAKE_AUTORCC ON )
1717set (CMAKE_AUTOUIC ON )
1818
19- # Set root dir for convenience
20- set (PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR} /.." )
21- get_filename_component (PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR} /.." ABSOLUTE )
22-
2319add_custom_target (build -time-make-directory ALL
2420 COMMAND ${CMAKE_COMMAND} -E make_directory Assembly/)
2521
2622# Find repo root folder path
27- string (FIND "${CMAKE_CURRENT_SOURCE_DIR} " "Arduino-Source-Internal" internal_repro_position) # determine if this is an internal repo
28- if (internal_repro_position EQUAL -1) # no "Arduino-Source-Internal" substr in the current source dir
29- # we are building the public repo
30- set (REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR} /../" )
23+ string (FIND "${CMAKE_CURRENT_SOURCE_DIR} " "Arduino-Source-Internal" internal_repo_position)
24+
25+ # Determine if this is an internal repo and normalize REPO_ROOT_DIR
26+ if (internal_repo_position EQUAL -1)
27+ # We are building the public repo
28+ set (REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR} /../" )
29+ else ()
30+ # We are building the internal repo
31+ set (REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR} /../../../" )
32+ endif ()
33+
34+ # Determine environment
35+ if (DEFINED ENV{GITHUB_ACTIONS})
36+ message (STATUS "Detected CI environment, skipping file deployment" )
37+ set (DEPLOY_FILES FALSE )
38+ else ()
39+ message (STATUS "Detected local dev environment" )
40+ set (PACKAGES_DIR "${REPO_ROOT_DIR} /Packages" )
41+ message (STATUS "Packages directory: ${PACKAGES_DIR} " )
42+
43+ # Clone or update the Packages repo
44+ if (NOT EXISTS "${PACKAGES_DIR} /.git" )
45+ message (STATUS "Packages repo not found. Cloning..." )
46+ execute_process (
47+ COMMAND git clone --branch master https://github.com/PokemonAutomation/Packages.git "${PACKAGES_DIR} "
48+ RESULT_VARIABLE result
49+ OUTPUT_VARIABLE out
50+ ERROR_VARIABLE err
51+ OUTPUT_STRIP_TRAILING_WHITESPACE
52+ ERROR_STRIP_TRAILING_WHITESPACE
53+ )
54+ if (NOT result EQUAL 0)
55+ message (FATAL_ERROR "Failed to clone Packages repo:\n ${err} " )
56+ endif ()
3157 else ()
32- # we are building the internal repo
33- set (REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR} /../../../" )
58+ message (STATUS "Packages repo exists. Pulling latest changes..." )
59+ execute_process (
60+ COMMAND git -C "${PACKAGES_DIR} " pull origin master
61+ RESULT_VARIABLE result
62+ OUTPUT_VARIABLE out
63+ ERROR_VARIABLE err
64+ OUTPUT_STRIP_TRAILING_WHITESPACE
65+ ERROR_STRIP_TRAILING_WHITESPACE
66+ )
67+ if (NOT result EQUAL 0)
68+ message (WARNING "Failed to update Packages repo:\n ${err} " )
69+ endif ()
3470 endif ()
3571
72+ # Set paths for post-build deployment
73+ set (FIRMWARE_DIR "${PACKAGES_DIR} /PABotBase/PABotBase-Switch" )
74+ set (SCRIPTS_DIR "${PACKAGES_DIR} /SerialPrograms/Scripts" )
75+ set (RESOURCES_DIR "${PACKAGES_DIR} /SerialPrograms/Resources" )
76+ set (DEST_DIR "$<TARGET_FILE_DIR:SerialPrograms>" )
77+ set (DEPLOY_DIR "$<TARGET_FILE_DIR:SerialPrograms>/Binaries64" )
78+ set (DEPLOY_FILES TRUE )
79+ message (STATUS "Packages repo ready for deployment" )
80+ endif ()
81+
3682#Find threads library
3783set (THREADS_PREFER_PTHREAD_FLAG ON )
3884find_package (Threads REQUIRED)
@@ -41,7 +87,19 @@ find_package(Threads REQUIRED)
4187if (NOT QT_MAJOR)
4288 set (QT_MAJOR 6)
4389endif ()
90+
4491find_package (Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED)
92+ # Find windeployqt.exe relative to the Qt bin dir
93+ if (WIN32 AND DEPLOY_FILES)
94+ get_target_property (qt_core_location Qt${QT_MAJOR} ::Core LOCATION )
95+ get_filename_component (qt_bin_dir "${qt_core_location} " DIRECTORY )
96+ find_program (WINDEPLOYQT_EXECUTABLE windeployqt
97+ HINTS "${qt_bin_dir} "
98+ PATH_SUFFIXES ../bin bin
99+ REQUIRED
100+ )
101+ endif ()
102+
45103#disable deprecated Qt APIs
46104add_compile_definitions (QT_DISABLE_DEPRECATED_BEFORE=0x050F00)
47105
@@ -2449,7 +2507,7 @@ if (APPLE)
24492507
24502508 # make sure Packages repo, https://github.com/PokemonAutomation/Packages is placed in the same folder as this Arduino-Source repo
24512509 # so the post-build command can copy the resources folder Packages/SerialPrograms/Resources/ into the built app bundle:
2452- set (RESOURCES_PATH "${REPO_ROOT_DIR} ../Packages/SerialPrograms/Resources" )
2510+ set (RESOURCES_PATH "${REPO_ROOT_DIR} / ../Packages/SerialPrograms/Resources" )
24532511 message (STATUS "Set Resources folder path from Packages repo: ${RESOURCES_PATH} " )
24542512 add_custom_command (
24552513 TARGET SerialPrograms
@@ -2480,13 +2538,13 @@ endif()
24802538#extract opencv_world4110d.dll from archive on Windows Debug build, extract Discord Social SDK
24812539if (WIN32 )
24822540 file (ARCHIVE_EXTRACT
2483- INPUT ${CMAKE_CURRENT_SOURCE_DIR} /.. /3rdPartyBinaries/opencv_world4110d.zip
2484- DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} /.. /3rdPartyBinaries/
2541+ INPUT ${REPO_ROOT_DIR} /3rdPartyBinaries/opencv_world4110d.zip
2542+ DESTINATION ${REPO_ROOT_DIR} /3rdPartyBinaries/
24852543 )
24862544
24872545 file (ARCHIVE_EXTRACT
2488- INPUT ${CMAKE_CURRENT_SOURCE_DIR} /.. /3rdPartyBinaries/discord_social_sdk_win.zip
2489- DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} /.. /3rdPartyBinaries/
2546+ INPUT ${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win.zip
2547+ DESTINATION ${REPO_ROOT_DIR} /3rdPartyBinaries/
24902548 )
24912549endif ()
24922550
@@ -2796,26 +2854,112 @@ SET_SOURCE_FILES_PROPERTIES(
27962854)
27972855endif ()
27982856
2857+ if (WIN32 AND NOT DEPLOY_FILES)
2858+ file (GLOB MY_DLLS
2859+ "../3rdPartyBinaries/*.dll"
2860+ )
27992861
2862+ file (COPY ${MY_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )
2863+ endif ()
28002864
2865+ if (WIN32 AND DEPLOY_FILES)
2866+ # Ensure the binaries directory exists
2867+ add_custom_command (
2868+ TARGET SerialPrograms
2869+ POST_BUILD
2870+ COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPLOY_DIR}
2871+ COMMENT "Ensuring binary directory exists"
2872+ )
28012873
2802- if ( WIN32 )
2803- #copy needed dlls
2804- #file(COPY *.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
2805- file (GLOB MY_DLLS
2806- "../3rdPartyBinaries/*.dll "
2807- )
2808- file (COPY ${MY_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )
2874+ # Copy the resources folder to build directory
2875+ add_custom_command (
2876+ TARGET SerialPrograms
2877+ POST_BUILD
2878+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_DIR} " ${DEST_DIR} /Resources "
2879+ COMMENT "Copying the resources folder to the build directory"
2880+ )
28092881
2810- # Copy discord_social_sdk DLL based on build type
2811- add_custom_command (
2812- TARGET SerialPrograms
2813- POST_BUILD
2814- COMMAND ${CMAKE_COMMAND} -E copy
2815- $<IF:$<CONFIG:Debug>,"${PROJECT_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win/bin/debug/discord_partner_sdk.dll" ,"${PROJECT_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win/bin/release/discord_partner_sdk.dll" >
2816- $<TARGET_FILE_DIR:SerialPrograms>/Binaries64/discord_partner_sdk.dll
2817- COMMENT "Copying Discord SDK DLL to Binaries64"
2818- )
2882+ # Copy the firmware folder to build directory
2883+ add_custom_command (
2884+ TARGET SerialPrograms
2885+ POST_BUILD
2886+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${FIRMWARE_DIR} "${DEST_DIR} /PABotBase"
2887+ COMMENT "Copying the firmware folder to the build directory"
2888+ )
2889+
2890+ # Copy the scripts folder to build directory
2891+ add_custom_command (
2892+ TARGET SerialPrograms
2893+ POST_BUILD
2894+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${SCRIPTS_DIR} "${DEST_DIR} /Scripts"
2895+ COMMENT "Copying the scripts folder to the build directory"
2896+ )
2897+
2898+ # Run windeployqt.exe to deploy Qt dependencies based on build type
2899+ if (WINDEPLOYQT_EXECUTABLE)
2900+ add_custom_command (
2901+ TARGET SerialPrograms
2902+ POST_BUILD
2903+ COMMAND "${WINDEPLOYQT_EXECUTABLE} "
2904+ --dir "${DEPLOY_DIR} "
2905+ $<IF:$<CONFIG:Debug>,--debug,--release>
2906+ $<TARGET_FILE:SerialPrograms>
2907+ COMMENT "Deploying Qt dependencies for $<CONFIG>"
2908+ )
2909+ else ()
2910+ message (WARNING "windeployqt not found, skipping Qt deployment." )
2911+ endif ()
2912+
2913+ # Move 3rd party DLLs to binaries folder
2914+ file (GLOB THIRD_PARTY_DLLS "${REPO_ROOT_DIR} /3rdPartyBinaries/*.dll" )
2915+ foreach (DLL ${THIRD_PARTY_DLLS} )
2916+ get_filename_component (DLL_NAME ${DLL} NAME )
2917+ add_custom_command (
2918+ TARGET SerialPrograms
2919+ POST_BUILD
2920+ COMMAND ${CMAKE_COMMAND} -E copy ${DLL} "${DEPLOY_DIR} /${DLL_NAME} "
2921+ COMMENT "Moving ${DLL_NAME} to binaries folder"
2922+ )
2923+ endforeach ()
2924+
2925+ # Move binaries generated by CMake to binaries folder
2926+ file (GLOB DLL_FILES "${CMAKE_CURRENT_BINARY_DIR} /*.dll" )
2927+ foreach (DLL ${DLL_FILES} )
2928+ get_filename_component (DLL_NAME ${DLL} NAME )
2929+ add_custom_command (
2930+ TARGET SerialPrograms
2931+ POST_BUILD
2932+ COMMAND ${CMAKE_COMMAND} -E rename ${DLL} "${DEPLOY_DIR} /${DLL_NAME} "
2933+ COMMENT "Moving ${DLL_NAME} to binaries folder"
2934+ )
2935+ endforeach ()
2936+
2937+ # Copy discord_social_sdk DLL based on build type
2938+ add_custom_command (
2939+ TARGET SerialPrograms
2940+ POST_BUILD
2941+ COMMAND ${CMAKE_COMMAND} -E copy
2942+ $<IF:$<CONFIG:Debug>,"${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win/bin/debug/discord_partner_sdk.dll" ,"${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win/bin/release/discord_partner_sdk.dll" >
2943+ "${DEPLOY_DIR} /discord_partner_sdk.dll"
2944+ COMMENT "Copying Discord SDK DLL to the binaries folder"
2945+ )
2946+
2947+ # Move the .exe file to Binaries64
2948+ add_custom_command (
2949+ TARGET SerialPrograms
2950+ POST_BUILD
2951+ COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE:SerialPrograms> "${DEPLOY_DIR} /$<TARGET_FILE_NAME:SerialPrograms>"
2952+ COMMENT "Moving .exe to the binaries folder"
2953+ )
2954+
2955+ # Move the .pdb file to Binaries64
2956+ add_custom_command (
2957+ TARGET SerialPrograms
2958+ POST_BUILD
2959+ COMMAND ${CMAKE_COMMAND} -E make_directory "${DEPLOY_DIR} "
2960+ COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_PDB_FILE:SerialPrograms> "${DEPLOY_DIR} /$<TARGET_PDB_FILE_NAME:SerialPrograms>"
2961+ COMMENT "Moving .pdb to the binaries folder"
2962+ )
28192963endif ()
28202964
28212965if (QT_MAJOR GREATER_EQUAL 6)
0 commit comments