@@ -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
@@ -2425,7 +2483,7 @@ if (APPLE)
24252483
24262484 # make sure Packages repo, https://github.com/PokemonAutomation/Packages is placed in the same folder as this Arduino-Source repo
24272485 # so the post-build command can copy the resources folder Packages/SerialPrograms/Resources/ into the built app bundle:
2428- set (RESOURCES_PATH "${REPO_ROOT_DIR} ../Packages/SerialPrograms/Resources" )
2486+ set (RESOURCES_PATH "${REPO_ROOT_DIR} / ../Packages/SerialPrograms/Resources" )
24292487 message (STATUS "Set Resources folder path from Packages repo: ${RESOURCES_PATH} " )
24302488 add_custom_command (
24312489 TARGET SerialPrograms
@@ -2456,13 +2514,13 @@ endif()
24562514#extract opencv_world4110d.dll from archive on Windows Debug build, extract Discord Social SDK
24572515if (WIN32 )
24582516 file (ARCHIVE_EXTRACT
2459- INPUT ${CMAKE_CURRENT_SOURCE_DIR} /.. /3rdPartyBinaries/opencv_world4110d.zip
2460- DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} /.. /3rdPartyBinaries/
2517+ INPUT ${REPO_ROOT_DIR} /3rdPartyBinaries/opencv_world4110d.zip
2518+ DESTINATION ${REPO_ROOT_DIR} /3rdPartyBinaries/
24612519 )
24622520
24632521 file (ARCHIVE_EXTRACT
2464- INPUT ${CMAKE_CURRENT_SOURCE_DIR} /.. /3rdPartyBinaries/discord_social_sdk_win.zip
2465- DESTINATION ${CMAKE_CURRENT_SOURCE_DIR} /.. /3rdPartyBinaries/
2522+ INPUT ${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win.zip
2523+ DESTINATION ${REPO_ROOT_DIR} /3rdPartyBinaries/
24662524 )
24672525endif ()
24682526
@@ -2784,26 +2842,112 @@ SET_SOURCE_FILES_PROPERTIES(
27842842)
27852843endif ()
27862844
2845+ if (WIN32 AND NOT DEPLOY_FILES)
2846+ file (GLOB MY_DLLS
2847+ "../3rdPartyBinaries/*.dll"
2848+ )
27872849
2850+ file (COPY ${MY_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )
2851+ endif ()
27882852
2853+ if (WIN32 AND DEPLOY_FILES)
2854+ # Ensure the binaries directory exists
2855+ add_custom_command (
2856+ TARGET SerialPrograms
2857+ POST_BUILD
2858+ COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPLOY_DIR}
2859+ COMMENT "Ensuring binary directory exists"
2860+ )
27892861
2790- if ( WIN32 )
2791- #copy needed dlls
2792- #file(COPY *.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
2793- file (GLOB MY_DLLS
2794- "../3rdPartyBinaries/*.dll "
2795- )
2796- file (COPY ${MY_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )
2862+ # Copy the resources folder to build directory
2863+ add_custom_command (
2864+ TARGET SerialPrograms
2865+ POST_BUILD
2866+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_DIR} " ${DEST_DIR} /Resources "
2867+ COMMENT "Copying the resources folder to the build directory"
2868+ )
27972869
2798- # Copy discord_social_sdk DLL based on build type
2799- add_custom_command (
2800- TARGET SerialPrograms
2801- POST_BUILD
2802- COMMAND ${CMAKE_COMMAND} -E copy
2803- $<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" >
2804- $<TARGET_FILE_DIR:SerialPrograms>/Binaries64/discord_partner_sdk.dll
2805- COMMENT "Copying Discord SDK DLL to Binaries64"
2806- )
2870+ # Copy the firmware folder to build directory
2871+ add_custom_command (
2872+ TARGET SerialPrograms
2873+ POST_BUILD
2874+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${FIRMWARE_DIR} "${DEST_DIR} /PABotBase"
2875+ COMMENT "Copying the firmware folder to the build directory"
2876+ )
2877+
2878+ # Copy the scripts folder to build directory
2879+ add_custom_command (
2880+ TARGET SerialPrograms
2881+ POST_BUILD
2882+ COMMAND ${CMAKE_COMMAND} -E copy_directory ${SCRIPTS_DIR} "${DEST_DIR} /Scripts"
2883+ COMMENT "Copying the scripts folder to the build directory"
2884+ )
2885+
2886+ # Run windeployqt.exe to deploy Qt dependencies based on build type
2887+ if (WINDEPLOYQT_EXECUTABLE)
2888+ add_custom_command (
2889+ TARGET SerialPrograms
2890+ POST_BUILD
2891+ COMMAND "${WINDEPLOYQT_EXECUTABLE} "
2892+ --dir "${DEPLOY_DIR} "
2893+ $<IF:$<CONFIG:Debug>,--debug,--release>
2894+ $<TARGET_FILE:SerialPrograms>
2895+ COMMENT "Deploying Qt dependencies for $<CONFIG>"
2896+ )
2897+ else ()
2898+ message (WARNING "windeployqt not found, skipping Qt deployment." )
2899+ endif ()
2900+
2901+ # Move 3rd party DLLs to binaries folder
2902+ file (GLOB THIRD_PARTY_DLLS "${REPO_ROOT_DIR} /3rdPartyBinaries/*.dll" )
2903+ foreach (DLL ${THIRD_PARTY_DLLS} )
2904+ get_filename_component (DLL_NAME ${DLL} NAME )
2905+ add_custom_command (
2906+ TARGET SerialPrograms
2907+ POST_BUILD
2908+ COMMAND ${CMAKE_COMMAND} -E copy ${DLL} "${DEPLOY_DIR} /${DLL_NAME} "
2909+ COMMENT "Moving ${DLL_NAME} to binaries folder"
2910+ )
2911+ endforeach ()
2912+
2913+ # Move binaries generated by CMake to binaries folder
2914+ file (GLOB DLL_FILES "${CMAKE_CURRENT_BINARY_DIR} /*.dll" )
2915+ foreach (DLL ${DLL_FILES} )
2916+ get_filename_component (DLL_NAME ${DLL} NAME )
2917+ add_custom_command (
2918+ TARGET SerialPrograms
2919+ POST_BUILD
2920+ COMMAND ${CMAKE_COMMAND} -E rename ${DLL} "${DEPLOY_DIR} /${DLL_NAME} "
2921+ COMMENT "Moving ${DLL_NAME} to binaries folder"
2922+ )
2923+ endforeach ()
2924+
2925+ # Copy discord_social_sdk DLL based on build type
2926+ add_custom_command (
2927+ TARGET SerialPrograms
2928+ POST_BUILD
2929+ COMMAND ${CMAKE_COMMAND} -E copy
2930+ $<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" >
2931+ "${DEPLOY_DIR} /discord_partner_sdk.dll"
2932+ COMMENT "Copying Discord SDK DLL to the binaries folder"
2933+ )
2934+
2935+ # Move the .exe file to Binaries64
2936+ add_custom_command (
2937+ TARGET SerialPrograms
2938+ POST_BUILD
2939+ COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE:SerialPrograms> "${DEPLOY_DIR} /$<TARGET_FILE_NAME:SerialPrograms>"
2940+ COMMENT "Moving .exe to the binaries folder"
2941+ )
2942+
2943+ # Move the .pdb file to Binaries64
2944+ add_custom_command (
2945+ TARGET SerialPrograms
2946+ POST_BUILD
2947+ COMMAND ${CMAKE_COMMAND} -E make_directory "${DEPLOY_DIR} "
2948+ COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_PDB_FILE:SerialPrograms> "${DEPLOY_DIR} /$<TARGET_PDB_FILE_NAME:SerialPrograms>"
2949+ COMMENT "Moving .pdb to the binaries folder"
2950+ )
28072951endif ()
28082952
28092953if (QT_MAJOR GREATER_EQUAL 6)
0 commit comments