From 573587be847b6119624b90ab06ae18bee6dfd992 Mon Sep 17 00:00:00 2001 From: Koi Date: Sat, 30 Aug 2025 17:33:08 -0500 Subject: [PATCH 1/6] [Windows] Copy/move all Qt dependencies, third party and generated .dll files, and resources to appropriate build output directories. Download/update Packages if they don't exist/differ, respectively. --- SerialPrograms/CMakeLists.txt | 206 +++++++++++++++++++++++++++++----- 1 file changed, 175 insertions(+), 31 deletions(-) diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 79eae532e4..3a9f9a0a9b 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -16,23 +16,69 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) -# Set root dir for convenience -set(PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR}/..") -get_filename_component(PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR}/.." ABSOLUTE) - add_custom_target(build-time-make-directory ALL COMMAND ${CMAKE_COMMAND} -E make_directory Assembly/) # Find repo root folder path -string(FIND "${CMAKE_CURRENT_SOURCE_DIR}" "Arduino-Source-Internal" internal_repro_position) # determine if this is an internal repo - if (internal_repro_position EQUAL -1) # no "Arduino-Source-Internal" substr in the current source dir - # we are building the public repo - set(REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../") +string(FIND "${CMAKE_CURRENT_SOURCE_DIR}" "Arduino-Source-Internal" internal_repo_position) + +# Determine if this is an internal repo and normalize REPO_ROOT_DIR +if (internal_repo_position EQUAL -1) + # We are building the public repo + set(REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../") +else() + # We are building the internal repo + set(REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../") +endif() + +# Determine environment +if(DEFINED ENV{GITHUB_ACTIONS}) + message(STATUS "Detected CI environment, skipping file deployment") + set(DEPLOY_FILES FALSE) +else() + message(STATUS "Detected local dev environment") + set(PACKAGES_DIR "${REPO_ROOT_DIR}/Packages") + message(STATUS "Packages directory: ${PACKAGES_DIR}") + + # Clone or update the Packages repo + if(NOT EXISTS "${PACKAGES_DIR}/.git") + message(STATUS "Packages repo not found. Cloning...") + execute_process( + COMMAND git clone --branch master https://github.com/PokemonAutomation/Packages.git "${PACKAGES_DIR}" + RESULT_VARIABLE result + OUTPUT_VARIABLE out + ERROR_VARIABLE err + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE + ) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Failed to clone Packages repo:\n${err}") + endif() else() - # we are building the internal repo - set(REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../") + message(STATUS "Packages repo exists. Pulling latest changes...") + execute_process( + COMMAND git -C "${PACKAGES_DIR}" pull origin master + RESULT_VARIABLE result + OUTPUT_VARIABLE out + ERROR_VARIABLE err + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE + ) + if(NOT result EQUAL 0) + message(WARNING "Failed to update Packages repo:\n${err}") + endif() endif() + # Set paths for post-build deployment + set(FIRMWARE_DIR "${PACKAGES_DIR}/PABotBase/PABotBase-Switch") + set(SCRIPTS_DIR "${PACKAGES_DIR}/SerialPrograms/Scripts") + set(RESOURCES_DIR "${PACKAGES_DIR}/SerialPrograms/Resources") + set(DEST_DIR "$") + set(DEPLOY_DIR "$/Binaries64") + set(DEPLOY_FILES TRUE) + message(STATUS "Packages repo ready for deployment") +endif() + #Find threads library set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) @@ -41,7 +87,19 @@ find_package(Threads REQUIRED) if(NOT QT_MAJOR) set(QT_MAJOR 6) endif() + find_package(Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED) +# Find windeployqt.exe relative to the Qt bin dir +if (WIN32 AND DEPLOY_FILES) + get_target_property(qt_core_location Qt${QT_MAJOR}::Core LOCATION) + get_filename_component(qt_bin_dir "${qt_core_location}" DIRECTORY) + find_program(WINDEPLOYQT_EXECUTABLE windeployqt + HINTS "${qt_bin_dir}" + PATH_SUFFIXES ../bin bin + REQUIRED + ) +endif() + #disable deprecated Qt APIs add_compile_definitions(QT_DISABLE_DEPRECATED_BEFORE=0x050F00) @@ -2449,7 +2507,7 @@ if (APPLE) # make sure Packages repo, https://github.com/PokemonAutomation/Packages is placed in the same folder as this Arduino-Source repo # so the post-build command can copy the resources folder Packages/SerialPrograms/Resources/ into the built app bundle: - set(RESOURCES_PATH "${REPO_ROOT_DIR}../Packages/SerialPrograms/Resources") + set(RESOURCES_PATH "${REPO_ROOT_DIR}/../Packages/SerialPrograms/Resources") message(STATUS "Set Resources folder path from Packages repo: ${RESOURCES_PATH}") add_custom_command( TARGET SerialPrograms @@ -2480,13 +2538,13 @@ endif() #extract opencv_world4110d.dll from archive on Windows Debug build, extract Discord Social SDK if (WIN32) file(ARCHIVE_EXTRACT - INPUT ${CMAKE_CURRENT_SOURCE_DIR}/../3rdPartyBinaries/opencv_world4110d.zip - DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../3rdPartyBinaries/ + INPUT ${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.zip + DESTINATION ${REPO_ROOT_DIR}/3rdPartyBinaries/ ) file(ARCHIVE_EXTRACT - INPUT ${CMAKE_CURRENT_SOURCE_DIR}/../3rdPartyBinaries/discord_social_sdk_win.zip - DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../3rdPartyBinaries/ + INPUT ${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip + DESTINATION ${REPO_ROOT_DIR}/3rdPartyBinaries/ ) endif() @@ -2796,26 +2854,112 @@ SET_SOURCE_FILES_PROPERTIES( ) endif() +if (WIN32 AND NOT DEPLOY_FILES) + file(GLOB MY_DLLS + "../3rdPartyBinaries/*.dll" +) +file(COPY ${MY_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +endif() +if (WIN32 AND DEPLOY_FILES) + # Ensure the binaries directory exists + add_custom_command( + TARGET SerialPrograms + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPLOY_DIR} + COMMENT "Ensuring binary directory exists" + ) -if (WIN32) -#copy needed dlls -#file(COPY *.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) -file(GLOB MY_DLLS - "../3rdPartyBinaries/*.dll" -) -file(COPY ${MY_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + # Copy the resources folder to build directory + add_custom_command( + TARGET SerialPrograms + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_DIR} "${DEST_DIR}/Resources" + COMMENT "Copying the resources folder to the build directory" + ) -# Copy discord_social_sdk DLL based on build type -add_custom_command( - TARGET SerialPrograms - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - $,"${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"> - $/Binaries64/discord_partner_sdk.dll - COMMENT "Copying Discord SDK DLL to Binaries64" -) + # Copy the firmware folder to build directory + add_custom_command( + TARGET SerialPrograms + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${FIRMWARE_DIR} "${DEST_DIR}/PABotBase" + COMMENT "Copying the firmware folder to the build directory" + ) + + # Copy the scripts folder to build directory + add_custom_command( + TARGET SerialPrograms + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${SCRIPTS_DIR} "${DEST_DIR}/Scripts" + COMMENT "Copying the scripts folder to the build directory" + ) + + # Run windeployqt.exe to deploy Qt dependencies based on build type + if(WINDEPLOYQT_EXECUTABLE) + add_custom_command( + TARGET SerialPrograms + POST_BUILD + COMMAND "${WINDEPLOYQT_EXECUTABLE}" + --dir "${DEPLOY_DIR}" + $,--debug,--release> + $ + COMMENT "Deploying Qt dependencies for $" + ) + else() + message(WARNING "windeployqt not found, skipping Qt deployment.") + endif() + + # Move 3rd party DLLs to binaries folder + file(GLOB THIRD_PARTY_DLLS "${REPO_ROOT_DIR}/3rdPartyBinaries/*.dll") + foreach(DLL ${THIRD_PARTY_DLLS}) + get_filename_component(DLL_NAME ${DLL} NAME) + add_custom_command( + TARGET SerialPrograms + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${DLL} "${DEPLOY_DIR}/${DLL_NAME}" + COMMENT "Moving ${DLL_NAME} to binaries folder" + ) + endforeach() + + # Move binaries generated by CMake to binaries folder + file(GLOB DLL_FILES "${CMAKE_CURRENT_BINARY_DIR}/*.dll") + foreach(DLL ${DLL_FILES}) + get_filename_component(DLL_NAME ${DLL} NAME) + add_custom_command( + TARGET SerialPrograms + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E rename ${DLL} "${DEPLOY_DIR}/${DLL_NAME}" + COMMENT "Moving ${DLL_NAME} to binaries folder" + ) + endforeach() + + # Copy discord_social_sdk DLL based on build type + add_custom_command( + TARGET SerialPrograms + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $,"${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"> + "${DEPLOY_DIR}/discord_partner_sdk.dll" + COMMENT "Copying Discord SDK DLL to the binaries folder" + ) + + # Move the .exe file to Binaries64 + add_custom_command( + TARGET SerialPrograms + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E rename $ "${DEPLOY_DIR}/$" + COMMENT "Moving .exe to the binaries folder" + ) + + # Move the .pdb file to Binaries64 + add_custom_command( + TARGET SerialPrograms + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "${DEPLOY_DIR}" + COMMAND ${CMAKE_COMMAND} -E rename $ "${DEPLOY_DIR}/$" + COMMENT "Moving .pdb to the binaries folder" + ) endif() if (QT_MAJOR GREATER_EQUAL 6) From 879043f4896c13ba5850ca502000678b42e079e1 Mon Sep 17 00:00:00 2001 From: Koi Date: Sun, 7 Sep 2025 01:34:27 -0500 Subject: [PATCH 2/6] Add CMakePresets.json for additional build option to publish (experimental, will squash and force when Qt issues are figured out). --- SerialPrograms/CMakeLists.txt | 74 ++++++++++++++++-------- SerialPrograms/CMakePresets.json | 97 ++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 25 deletions(-) create mode 100644 SerialPrograms/CMakePresets.json diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 3a9f9a0a9b..5904b34e83 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -1,21 +1,10 @@ -#set the minimum cmake version required +# Set the minimum cmake version required cmake_minimum_required(VERSION 3.18.0) -#set the name of the project +# Set the project name project(SerialPrograms) -#enable c++ 23 -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -#produce clang tidy file -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) #set(CMAKE_VERBOSE_MAKEFILE ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - add_custom_target(build-time-make-directory ALL COMMAND ${CMAKE_COMMAND} -E make_directory Assembly/) @@ -23,7 +12,7 @@ add_custom_target(build-time-make-directory ALL string(FIND "${CMAKE_CURRENT_SOURCE_DIR}" "Arduino-Source-Internal" internal_repo_position) # Determine if this is an internal repo and normalize REPO_ROOT_DIR -if (internal_repo_position EQUAL -1) +if(internal_repo_position EQUAL -1) # We are building the public repo set(REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../") else() @@ -31,6 +20,19 @@ else() set(REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../") endif() +# Extract Discord Social SDK +if(WIN32) + message(STATUS "Extracting Social SDK") + set(DISCORD_SDK_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip") + set(DISCORD_SDK_DIR "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win") + if(EXISTS "${DISCORD_SDK_ZIP}" AND NOT EXISTS "${DISCORD_SDK_DIR}") + file(ARCHIVE_EXTRACT + INPUT "${DISCORD_SDK_ZIP}" + DESTINATION "${REPO_ROOT_DIR}/3rdPartyBinaries" + ) + endif() +endif() + # Determine environment if(DEFINED ENV{GITHUB_ACTIONS}) message(STATUS "Detected CI environment, skipping file deployment") @@ -38,7 +40,6 @@ if(DEFINED ENV{GITHUB_ACTIONS}) else() message(STATUS "Detected local dev environment") set(PACKAGES_DIR "${REPO_ROOT_DIR}/Packages") - message(STATUS "Packages directory: ${PACKAGES_DIR}") # Clone or update the Packages repo if(NOT EXISTS "${PACKAGES_DIR}/.git") @@ -51,6 +52,7 @@ else() OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) + if(NOT result EQUAL 0) message(FATAL_ERROR "Failed to clone Packages repo:\n${err}") endif() @@ -64,6 +66,7 @@ else() OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) + if(NOT result EQUAL 0) message(WARNING "Failed to update Packages repo:\n${err}") endif() @@ -73,8 +76,13 @@ else() set(FIRMWARE_DIR "${PACKAGES_DIR}/PABotBase/PABotBase-Switch") set(SCRIPTS_DIR "${PACKAGES_DIR}/SerialPrograms/Scripts") set(RESOURCES_DIR "${PACKAGES_DIR}/SerialPrograms/Resources") - set(DEST_DIR "$") - set(DEPLOY_DIR "$/Binaries64") + set(DEST_DIR "$/Output") + if(PACKAGE_BUILD) + set(DEPLOY_DIR "${DEST_DIR}/Binaries64") + else() + set(DEPLOY_DIR "${DEST_DIR}") + endif() + set(DEPLOY_FILES TRUE) message(STATUS "Packages repo ready for deployment") endif() @@ -83,14 +91,35 @@ endif() set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -#find Qt +# Define the base Qt installation directory +set(QT_BASE_DIR "C:/Qt") + +# Define the major version of Qt to search for if(NOT QT_MAJOR) set(QT_MAJOR 6) endif() +# Find all subdirectories in the Qt base directory +file(GLOB QT_SUBDIRS LIST_DIRECTORIES true "${QT_BASE_DIR}/${QT_MAJOR}*") + +# Filter and sort the directories to find the latest version +list(SORT QT_SUBDIRS) +list(REVERSE QT_SUBDIRS) + +# Get the first directory in the sorted list (latest version) +list(GET QT_SUBDIRS 0 QT_LATEST_DIR) + +# Debug message to verify the latest Qt directory +if(QT_LATEST_DIR) + message(STATUS "Latest Qt directory for Qt${QT_MAJOR}: ${QT_LATEST_DIR}") + set(CMAKE_PREFIX_PATH "${QT_LATEST_DIR}/msvc2022_64/lib/cmake") +else() + message(FATAL_ERROR "No Qt${QT_MAJOR} installation found in ${QT_BASE_DIR}") +endif() + find_package(Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED) # Find windeployqt.exe relative to the Qt bin dir -if (WIN32 AND DEPLOY_FILES) +if(WIN32 AND DEPLOY_FILES) get_target_property(qt_core_location Qt${QT_MAJOR}::Core LOCATION) get_filename_component(qt_bin_dir "${qt_core_location}" DIRECTORY) find_program(WINDEPLOYQT_EXECUTABLE windeployqt @@ -2535,17 +2564,12 @@ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../Internal/SerialPrograms/Internal0. target_sources(SerialPrograms PRIVATE ../../Internal/SerialPrograms/Internal1.cpp) endif() -#extract opencv_world4110d.dll from archive on Windows Debug build, extract Discord Social SDK +#extract opencv_world4110d.dll from archive on Windows Debug build if (WIN32) file(ARCHIVE_EXTRACT INPUT ${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.zip DESTINATION ${REPO_ROOT_DIR}/3rdPartyBinaries/ ) - - file(ARCHIVE_EXTRACT - INPUT ${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip - DESTINATION ${REPO_ROOT_DIR}/3rdPartyBinaries/ - ) endif() #add include directory diff --git a/SerialPrograms/CMakePresets.json b/SerialPrograms/CMakePresets.json new file mode 100644 index 0000000000..34c0f0d2f5 --- /dev/null +++ b/SerialPrograms/CMakePresets.json @@ -0,0 +1,97 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 18, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/../build", + "cacheVariables": { + "CMAKE_CXX_STANDARD": "23", + "CMAKE_CXX_STANDARD_REQUIRED": "ON", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", + "CMAKE_AUTOMOC": "ON", + "CMAKE_AUTORCC": "ON", + "CMAKE_AUTOUIC": "ON", + "PACKAGE_BUILD": "OFF" + } + }, + { + "name": "Debug", + "inherits": "default", + "description": "Build with debug information", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "PACKAGE_BUILD": "OFF" + } + }, + { + "name": "Release", + "inherits": "default", + "description": "Build for release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "PACKAGE_BUILD": "OFF" + } + }, + { + "name": "RelWithDebInfo", + "inherits": "default", + "description": "Build for release with debug information", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "PACKAGE_BUILD": "OFF" + } + }, + { + "name": "MinSizeRel", + "inherits": "default", + "description": "Build for minimum size release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "MinSizeRel", + "PACKAGE_BUILD": "OFF" + } + }, + { + "name": "Publish", + "inherits": "default", + "description": "Build for publishing with debug information and packaging enabled", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "PACKAGE_BUILD": "ON" + } + } + ], + "buildPresets": [ + { + "name": "default", + "hidden": true, + "configurePreset": "default" + }, + { + "name": "Debug", + "configurePreset": "Debug" + }, + { + "name": "Release", + "configurePreset": "Release" + }, + { + "name": "RelWithDebInfo", + "configurePreset": "RelWithDebInfo" + }, + { + "name": "MinSizeRel", + "configurePreset": "MinSizeRel" + }, + { + "name": "Publish", + "configurePreset": "Publish" + } + ] +} From 4b3f0094b9575135186c0f067c7bf6469835003e Mon Sep 17 00:00:00 2001 From: Koi Date: Mon, 8 Sep 2025 00:18:16 -0500 Subject: [PATCH 3/6] - Force Qt to re-run CMake configuration. - Limit Qt checks to Windows (assume default install directory). - Clean. --- SerialPrograms/CMakeLists.txt | 96 ++++++++++++++++++++------------ SerialPrograms/CMakePresets.json | 9 ++- 2 files changed, 68 insertions(+), 37 deletions(-) diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 5904b34e83..78c930ac8c 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -1,10 +1,35 @@ # Set the minimum cmake version required cmake_minimum_required(VERSION 3.18.0) +# Tell CMake to re-run configuration when these files change (get around Qt issues with stale CMake files) +set(_cmake_files_to_watch + "${CMAKE_SOURCE_DIR}/CMakeLists.txt" + "${CMAKE_SOURCE_DIR}/CMakePresets.json" +) + +# Watch any helper .cmake files under cmake/ +file(GLOB_RECURSE _cmake_helper_files "${CMAKE_SOURCE_DIR}/cmake/*.cmake") +list(APPEND _cmake_files_to_watch ${_cmake_helper_files}) + +# Append to the directory property so CMake will reconfigure when these change +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_cmake_files_to_watch}) +#message(STATUS "CMake will reconfigure when these change: ${_cmake_files_to_watch}") + # Set the project name project(SerialPrograms) +# Enable C++23 +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Produce clang tidy file +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) #set(CMAKE_VERBOSE_MAKEFILE ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + add_custom_target(build-time-make-directory ALL COMMAND ${CMAKE_COMMAND} -E make_directory Assembly/) @@ -20,19 +45,6 @@ else() set(REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../") endif() -# Extract Discord Social SDK -if(WIN32) - message(STATUS "Extracting Social SDK") - set(DISCORD_SDK_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip") - set(DISCORD_SDK_DIR "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win") - if(EXISTS "${DISCORD_SDK_ZIP}" AND NOT EXISTS "${DISCORD_SDK_DIR}") - file(ARCHIVE_EXTRACT - INPUT "${DISCORD_SDK_ZIP}" - DESTINATION "${REPO_ROOT_DIR}/3rdPartyBinaries" - ) - endif() -endif() - # Determine environment if(DEFINED ENV{GITHUB_ACTIONS}) message(STATUS "Detected CI environment, skipping file deployment") @@ -76,10 +88,12 @@ else() set(FIRMWARE_DIR "${PACKAGES_DIR}/PABotBase/PABotBase-Switch") set(SCRIPTS_DIR "${PACKAGES_DIR}/SerialPrograms/Scripts") set(RESOURCES_DIR "${PACKAGES_DIR}/SerialPrograms/Resources") - set(DEST_DIR "$/Output") + if(PACKAGE_BUILD) + set(DEST_DIR "$/Output") set(DEPLOY_DIR "${DEST_DIR}/Binaries64") else() + set(DEST_DIR "$") set(DEPLOY_DIR "${DEST_DIR}") endif() @@ -91,35 +105,36 @@ endif() set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -# Define the base Qt installation directory -set(QT_BASE_DIR "C:/Qt") - # Define the major version of Qt to search for if(NOT QT_MAJOR) set(QT_MAJOR 6) endif() -# Find all subdirectories in the Qt base directory -file(GLOB QT_SUBDIRS LIST_DIRECTORIES true "${QT_BASE_DIR}/${QT_MAJOR}*") +find_package(Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED) -# Filter and sort the directories to find the latest version -list(SORT QT_SUBDIRS) -list(REVERSE QT_SUBDIRS) +# Find Qt and windeployqt.exe relative to the Qt bin dir +if(WIN32 AND DEPLOY_FILES) + # Define the base Qt installation directory + set(QT_BASE_DIR "C:/Qt") -# Get the first directory in the sorted list (latest version) -list(GET QT_SUBDIRS 0 QT_LATEST_DIR) + # Find all subdirectories in the Qt base directory + file(GLOB QT_SUBDIRS LIST_DIRECTORIES true "${QT_BASE_DIR}/${QT_MAJOR}*") -# Debug message to verify the latest Qt directory -if(QT_LATEST_DIR) - message(STATUS "Latest Qt directory for Qt${QT_MAJOR}: ${QT_LATEST_DIR}") - set(CMAKE_PREFIX_PATH "${QT_LATEST_DIR}/msvc2022_64/lib/cmake") -else() - message(FATAL_ERROR "No Qt${QT_MAJOR} installation found in ${QT_BASE_DIR}") -endif() + # Filter and sort the directories to find the latest version + list(SORT QT_SUBDIRS) + list(REVERSE QT_SUBDIRS) + + # Get the first directory in the sorted list (latest version) + list(GET QT_SUBDIRS 0 QT_LATEST_DIR) + + # Debug message to verify the latest Qt directory + if(QT_LATEST_DIR) + message(STATUS "Latest Qt directory for Qt${QT_MAJOR}: ${QT_LATEST_DIR}") + set(CMAKE_PREFIX_PATH "${QT_LATEST_DIR}/msvc2022_64/lib/cmake") + else() + message(FATAL_ERROR "No Qt${QT_MAJOR} installation found in ${QT_BASE_DIR}") + endif() -find_package(Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED) -# Find windeployqt.exe relative to the Qt bin dir -if(WIN32 AND DEPLOY_FILES) get_target_property(qt_core_location Qt${QT_MAJOR}::Core LOCATION) get_filename_component(qt_bin_dir "${qt_core_location}" DIRECTORY) find_program(WINDEPLOYQT_EXECUTABLE windeployqt @@ -2564,12 +2579,23 @@ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../Internal/SerialPrograms/Internal0. target_sources(SerialPrograms PRIVATE ../../Internal/SerialPrograms/Internal1.cpp) endif() -#extract opencv_world4110d.dll from archive on Windows Debug build +# Extract opencv_world4110d.dll from archive on Windows Debug build, extract Discord Social SDK for Windows if (WIN32) + message(STATUS "Extracting opencv_world4110d") file(ARCHIVE_EXTRACT INPUT ${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.zip DESTINATION ${REPO_ROOT_DIR}/3rdPartyBinaries/ ) + + set(DISCORD_SDK_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip") + set(DISCORD_SDK_DIR "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win") + if(EXISTS "${DISCORD_SDK_ZIP}" AND NOT EXISTS "${DISCORD_SDK_DIR}") + message(STATUS "Extracting Social SDK") + file(ARCHIVE_EXTRACT + INPUT "${DISCORD_SDK_ZIP}" + DESTINATION "${REPO_ROOT_DIR}/3rdPartyBinaries" + ) + endif() endif() #add include directory diff --git a/SerialPrograms/CMakePresets.json b/SerialPrograms/CMakePresets.json index 34c0f0d2f5..38d63bfdf5 100644 --- a/SerialPrograms/CMakePresets.json +++ b/SerialPrograms/CMakePresets.json @@ -10,7 +10,7 @@ "name": "default", "hidden": true, "generator": "Ninja", - "binaryDir": "${sourceDir}/../build", + "binaryDir": "${sourceParentDir}/build", "cacheVariables": { "CMAKE_CXX_STANDARD": "23", "CMAKE_CXX_STANDARD_REQUIRED": "ON", @@ -25,6 +25,7 @@ "name": "Debug", "inherits": "default", "description": "Build with debug information", + "binaryDir": "${sourceParentDir}/build/${presetName}", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "PACKAGE_BUILD": "OFF" @@ -34,6 +35,7 @@ "name": "Release", "inherits": "default", "description": "Build for release", + "binaryDir": "${sourceParentDir}/build/${presetName}", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", "PACKAGE_BUILD": "OFF" @@ -43,6 +45,7 @@ "name": "RelWithDebInfo", "inherits": "default", "description": "Build for release with debug information", + "binaryDir": "${sourceParentDir}/build/${presetName}", "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo", "PACKAGE_BUILD": "OFF" @@ -52,6 +55,7 @@ "name": "MinSizeRel", "inherits": "default", "description": "Build for minimum size release", + "binaryDir": "${sourceParentDir}/build/${presetName}", "cacheVariables": { "CMAKE_BUILD_TYPE": "MinSizeRel", "PACKAGE_BUILD": "OFF" @@ -61,6 +65,7 @@ "name": "Publish", "inherits": "default", "description": "Build for publishing with debug information and packaging enabled", + "binaryDir": "${sourceParentDir}/build/${presetName}", "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo", "PACKAGE_BUILD": "ON" @@ -94,4 +99,4 @@ "configurePreset": "Publish" } ] -} +} \ No newline at end of file From 84aef504a10561faa853e290012ae6273eae98b6 Mon Sep 17 00:00:00 2001 From: Koi Date: Tue, 9 Sep 2025 01:33:16 -0500 Subject: [PATCH 4/6] Add preferred Qt install path and version configuration in CMakePresets.json. Also allows overriding Qt version per build type. --- SerialPrograms/CMakeLists.txt | 46 +++++++++++++++++++++----------- SerialPrograms/CMakePresets.json | 6 +++-- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 78c930ac8c..bcda559d4b 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -110,31 +110,47 @@ if(NOT QT_MAJOR) set(QT_MAJOR 6) endif() -find_package(Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED) +# Make sure CI builds work without going overboard with per-platform directory shenanigans +if(NOT DEPLOY_FILES) + find_package(Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED) +endif() # Find Qt and windeployqt.exe relative to the Qt bin dir if(WIN32 AND DEPLOY_FILES) # Define the base Qt installation directory - set(QT_BASE_DIR "C:/Qt") + if(PREFERRED_QT_DIR AND PREFERRED_QT_VER) + set(QT_CANDIDATE_DIR "${PREFERRED_QT_DIR}/${PREFERRED_QT_VER}/msvc2022_64/lib/cmake") + endif() - # Find all subdirectories in the Qt base directory - file(GLOB QT_SUBDIRS LIST_DIRECTORIES true "${QT_BASE_DIR}/${QT_MAJOR}*") + # Set default base directory just in case, validate that Qt specified in CMakePresets.json exists + # Otherwise search out the latest available in the default Qt directory. + set(QT_BASE_DIR "C:/Qt") + if(QT_CANDIDATE_DIR AND EXISTS "${QT_CANDIDATE_DIR}") + message(STATUS "Using preferred Qt directory for Qt${QT_MAJOR} ${PREFERRED_QT_VER}: ${QT_CANDIDATE_DIR}") + set(CMAKE_PREFIX_PATH "${QT_CANDIDATE_DIR}") + find_package(Qt${QT_MAJOR} ${PREFERRED_QT_VER} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED) + else() + # Find all subdirectories in the Qt base directory + find_package(Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED) + file(GLOB QT_SUBDIRS LIST_DIRECTORIES true "${QT_BASE_DIR}/${QT_MAJOR}*") - # Filter and sort the directories to find the latest version - list(SORT QT_SUBDIRS) - list(REVERSE QT_SUBDIRS) + # Filter and sort the directories to find the latest version + list(SORT QT_SUBDIRS) + list(REVERSE QT_SUBDIRS) - # Get the first directory in the sorted list (latest version) - list(GET QT_SUBDIRS 0 QT_LATEST_DIR) + # Get the first directory in the sorted list (latest version) + list(GET QT_SUBDIRS 0 QT_LATEST_DIR) - # Debug message to verify the latest Qt directory - if(QT_LATEST_DIR) - message(STATUS "Latest Qt directory for Qt${QT_MAJOR}: ${QT_LATEST_DIR}") - set(CMAKE_PREFIX_PATH "${QT_LATEST_DIR}/msvc2022_64/lib/cmake") - else() - message(FATAL_ERROR "No Qt${QT_MAJOR} installation found in ${QT_BASE_DIR}") + # Debug message to verify the latest Qt directory + if(QT_LATEST_DIR) + message(STATUS "Latest Qt directory for Qt${QT_MAJOR}: ${QT_LATEST_DIR}") + set(CMAKE_PREFIX_PATH "${QT_LATEST_DIR}/msvc2022_64/lib/cmake") + else() + message(FATAL_ERROR "No Qt${QT_MAJOR} installation found in ${QT_BASE_DIR}") + endif() endif() + # Find windeployqt.exe for Qt dependency deployment get_target_property(qt_core_location Qt${QT_MAJOR}::Core LOCATION) get_filename_component(qt_bin_dir "${qt_core_location}" DIRECTORY) find_program(WINDEPLOYQT_EXECUTABLE windeployqt diff --git a/SerialPrograms/CMakePresets.json b/SerialPrograms/CMakePresets.json index 38d63bfdf5..0e9d18c460 100644 --- a/SerialPrograms/CMakePresets.json +++ b/SerialPrograms/CMakePresets.json @@ -18,7 +18,9 @@ "CMAKE_AUTOMOC": "ON", "CMAKE_AUTORCC": "ON", "CMAKE_AUTOUIC": "ON", - "PACKAGE_BUILD": "OFF" + "PACKAGE_BUILD": "OFF", + "PREFERRED_QT_DIR": "C:/Qt", + "PREFERRED_QT_VER": "6.8.3", } }, { @@ -99,4 +101,4 @@ "configurePreset": "Publish" } ] -} \ No newline at end of file +} From f828a8b3bbc19736c20dae8406a566d0e3ff249a Mon Sep 17 00:00:00 2001 From: Koi Date: Fri, 19 Sep 2025 02:45:25 -0500 Subject: [PATCH 5/6] Clone Packages repo and extract .zip files if directories don't exist, make deployment run build-time. Update missing files in the build directory. --- SerialPrograms/CMakeLists.txt | 218 +++++++++++++++------------------- 1 file changed, 96 insertions(+), 122 deletions(-) diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index bcda559d4b..4100297009 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -53,37 +53,26 @@ else() message(STATUS "Detected local dev environment") set(PACKAGES_DIR "${REPO_ROOT_DIR}/Packages") - # Clone or update the Packages repo + # Add a custom command to clone Packages if(NOT EXISTS "${PACKAGES_DIR}/.git") - message(STATUS "Packages repo not found. Cloning...") - execute_process( - COMMAND git clone --branch master https://github.com/PokemonAutomation/Packages.git "${PACKAGES_DIR}" - RESULT_VARIABLE result - OUTPUT_VARIABLE out - ERROR_VARIABLE err - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE - ) - - if(NOT result EQUAL 0) - message(FATAL_ERROR "Failed to clone Packages repo:\n${err}") - endif() - else() - message(STATUS "Packages repo exists. Pulling latest changes...") - execute_process( - COMMAND git -C "${PACKAGES_DIR}" pull origin master - RESULT_VARIABLE result - OUTPUT_VARIABLE out - ERROR_VARIABLE err - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE + add_custom_command( + OUTPUT "${PACKAGES_DIR}/.git" + COMMAND ${CMAKE_COMMAND} -E echo "Cloning Packages repo..." + COMMAND ${CMAKE_COMMAND} -E make_directory "${PACKAGES_DIR}" + COMMAND git clone --branch master https://github.com/PokemonAutomation/Packages "${PACKAGES_DIR}" + WORKING_DIRECTORY "${REPO_ROOT_DIR}" + COMMENT "Cloning Packages repository" + VERBATIM ) - - if(NOT result EQUAL 0) - message(WARNING "Failed to update Packages repo:\n${err}") - endif() endif() + list(APPEND _cmake_files_to_watch "${PACKAGES_DIR}/.git") + # Add a custom target which we will depend on in executable_add() later on + add_custom_target( + PackagesRepo + DEPENDS "${PACKAGES_DIR}/.git" + ) + # Set paths for post-build deployment set(FIRMWARE_DIR "${PACKAGES_DIR}/PABotBase/PABotBase-Switch") set(SCRIPTS_DIR "${PACKAGES_DIR}/SerialPrograms/Scripts") @@ -98,7 +87,6 @@ else() endif() set(DEPLOY_FILES TRUE) - message(STATUS "Packages repo ready for deployment") endif() #Find threads library @@ -2576,7 +2564,28 @@ if (APPLE) "${RESOURCES_PATH}" "$/../Resources" ) -else() # WIN and Linux: +elseif (WIN32) + # Set directories and file dependencies (we HAVE to depend on a file for build-time extraction/git clone to work) + set(OPENCV_DEBUG_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.zip") + set(OPENCV_DEBUG "${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.dll") + + set(DISCORD_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip") + set(DISCORD_LIB_DEBUG "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win/lib/debug/discord_partner_sdk.lib") + set(DISCORD_LIB_RELEASE "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win/lib/release/discord_partner_sdk.lib") + + list(APPEND _cmake_files_to_watch "${DISCORD_LIB_DEBUG}") + list(APPEND _cmake_files_to_watch "${DISCORD_LIB_RELEASE}") + list(APPEND _cmake_files_to_watch "${OPENCV_DEBUG}") + + add_custom_target(ExtractDependencies + COMMENT "Extracting 3rd party dependencies..." + DEPENDS ${DISCORD_LIB_DEBUG} ${DISCORD_LIB_RELEASE} ${OPENCV_DEBUG} + ) + + add_executable(SerialPrograms WIN32 ${MAIN_SOURCES}) + add_dependencies(SerialPrograms ExtractDependencies) + add_dependencies(SerialPrograms PackagesRepo) +else() add_executable(SerialPrograms WIN32 ${MAIN_SOURCES}) endif() @@ -2595,25 +2604,6 @@ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../Internal/SerialPrograms/Internal0. target_sources(SerialPrograms PRIVATE ../../Internal/SerialPrograms/Internal1.cpp) endif() -# Extract opencv_world4110d.dll from archive on Windows Debug build, extract Discord Social SDK for Windows -if (WIN32) - message(STATUS "Extracting opencv_world4110d") - file(ARCHIVE_EXTRACT - INPUT ${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.zip - DESTINATION ${REPO_ROOT_DIR}/3rdPartyBinaries/ - ) - - set(DISCORD_SDK_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip") - set(DISCORD_SDK_DIR "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win") - if(EXISTS "${DISCORD_SDK_ZIP}" AND NOT EXISTS "${DISCORD_SDK_DIR}") - message(STATUS "Extracting Social SDK") - file(ARCHIVE_EXTRACT - INPUT "${DISCORD_SDK_ZIP}" - DESTINATION "${REPO_ROOT_DIR}/3rdPartyBinaries" - ) - endif() -endif() - #add include directory target_include_directories(SerialPrograms SYSTEM PRIVATE ../3rdParty/) target_include_directories(SerialPrograms PRIVATE ../ ../../Internal/ Source/) @@ -2929,103 +2919,87 @@ file(COPY ${MY_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) endif() if (WIN32 AND DEPLOY_FILES) - # Ensure the binaries directory exists - add_custom_command( - TARGET SerialPrograms - POST_BUILD + # Ensure target dirs and copy content folders + set(DEPLOY_CMDS) + list(APPEND DEPLOY_CMDS + COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Ensure deploy dir exists: ${DEPLOY_DIR}" COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPLOY_DIR} - COMMENT "Ensuring binary directory exists" - ) - # Copy the resources folder to build directory - add_custom_command( - TARGET SerialPrograms - POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying resources to destination dir: ${DEST_DIR}/Resources" COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_DIR} "${DEST_DIR}/Resources" - COMMENT "Copying the resources folder to the build directory" - ) - # Copy the firmware folder to build directory - add_custom_command( - TARGET SerialPrograms - POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying firmware to destination dir: ${DEST_DIR}/PABotBase" COMMAND ${CMAKE_COMMAND} -E copy_directory ${FIRMWARE_DIR} "${DEST_DIR}/PABotBase" - COMMENT "Copying the firmware folder to the build directory" - ) - # Copy the scripts folder to build directory - add_custom_command( - TARGET SerialPrograms - POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying scripts to destination dir: ${DEST_DIR}/Scripts" COMMAND ${CMAKE_COMMAND} -E copy_directory ${SCRIPTS_DIR} "${DEST_DIR}/Scripts" - COMMENT "Copying the scripts folder to the build directory" ) - # Run windeployqt.exe to deploy Qt dependencies based on build type + # Run windeployqt for the current config if(WINDEPLOYQT_EXECUTABLE) - add_custom_command( - TARGET SerialPrograms - POST_BUILD + list(APPEND DEPLOY_CMDS + COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Running windeployqt" COMMAND "${WINDEPLOYQT_EXECUTABLE}" - --dir "${DEPLOY_DIR}" - $,--debug,--release> - $ - COMMENT "Deploying Qt dependencies for $" + --dir "${DEPLOY_DIR}" + $,--debug,--release> + $ ) else() message(WARNING "windeployqt not found, skipping Qt deployment.") endif() - # Move 3rd party DLLs to binaries folder - file(GLOB THIRD_PARTY_DLLS "${REPO_ROOT_DIR}/3rdPartyBinaries/*.dll") - foreach(DLL ${THIRD_PARTY_DLLS}) - get_filename_component(DLL_NAME ${DLL} NAME) - add_custom_command( - TARGET SerialPrograms - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${DLL} "${DEPLOY_DIR}/${DLL_NAME}" - COMMENT "Moving ${DLL_NAME} to binaries folder" - ) - endforeach() - - # Move binaries generated by CMake to binaries folder - file(GLOB DLL_FILES "${CMAKE_CURRENT_BINARY_DIR}/*.dll") - foreach(DLL ${DLL_FILES}) - get_filename_component(DLL_NAME ${DLL} NAME) - add_custom_command( - TARGET SerialPrograms - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E rename ${DLL} "${DEPLOY_DIR}/${DLL_NAME}" - COMMENT "Moving ${DLL_NAME} to binaries folder" - ) - endforeach() - - # Copy discord_social_sdk DLL based on build type - add_custom_command( - TARGET SerialPrograms - POST_BUILD + # Copy Discord SDK DLL (config-specific) + list(APPEND DEPLOY_CMDS + COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying Discord SDK DLL" COMMAND ${CMAKE_COMMAND} -E copy - $,"${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"> - "${DEPLOY_DIR}/discord_partner_sdk.dll" - COMMENT "Copying Discord SDK DLL to the binaries folder" + $,${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> + ${DEPLOY_DIR}/discord_partner_sdk.dll ) - # Move the .exe file to Binaries64 - add_custom_command( - TARGET SerialPrograms - POST_BUILD + # Copy all 3rdPartyBinaries *.dll (computed at configure-time) + file(GLOB THIRD_PARTY_DLLS "${REPO_ROOT_DIR}/3rdPartyBinaries/*.dll") + foreach(DLL IN LISTS THIRD_PARTY_DLLS) + message(STATUS "Adding deploy command for 3rd party DLL: ${DLL}") + list(APPEND DEPLOY_CMDS COMMAND ${CMAKE_COMMAND} -E copy "${DLL}" "${DEPLOY_DIR}/") + endforeach() + + # Copy the built exe and pdb (pdb guarded for existence) + list(APPEND DEPLOY_CMDS + COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying built exe and pdb" COMMAND ${CMAKE_COMMAND} -E rename $ "${DEPLOY_DIR}/$" - COMMENT "Moving .exe to the binaries folder" + COMMAND ${CMAKE_COMMAND} -E rename $ "${DEPLOY_DIR}/$" ) - # Move the .pdb file to Binaries64 - add_custom_command( - TARGET SerialPrograms - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory "${DEPLOY_DIR}" - COMMAND ${CMAKE_COMMAND} -E rename $ "${DEPLOY_DIR}/$" - COMMENT "Moving .pdb to the binaries folder" + add_custom_target(DeployRuntime ALL + DEPENDS SerialPrograms ExtractDependencies PackagesRepo + COMMENT "Deploying runtime (Qt, packages, DLLs) to ${DEPLOY_DIR}" + VERBATIM + ${DEPLOY_CMDS} ) + + # Extract Discord SDK build-time, if it doesn't already exist + if (NOT EXISTS "${DISCORD_LIB_DEBUG}" OR NOT EXISTS "${DISCORD_LIB_RELEASE}") + message(STATUS "Discord SDK not found, extracting from zip...") + add_custom_command( + OUTPUT "${DISCORD_LIB_DEBUG}" "${DISCORD_LIB_RELEASE}" + COMMAND ${CMAKE_COMMAND} -E tar xf "${DISCORD_ZIP}" + WORKING_DIRECTORY "${REPO_ROOT_DIR}/3rdPartyBinaries" + DEPENDS "${DISCORD_ZIP}" + COMMENT "Extracting Discord SDK" + ) + endif() + + # Extract OpenCV debug DLL build-time, if it doesn't already exist + if (NOT EXISTS "${OPENCV_DEBUG}") + message(STATUS "OpenCV debug DLL not found, extracting from zip...") + add_custom_command( + OUTPUT "${OPENCV_DEBUG}" + COMMAND ${CMAKE_COMMAND} -E tar xf "${OPENCV_DEBUG_ZIP}" + WORKING_DIRECTORY "${REPO_ROOT_DIR}/3rdPartyBinaries" + DEPENDS "${OPENCV_DEBUG_ZIP}" + COMMENT "Extracting OpenCV debug DLL" + ) + endif() endif() if (QT_MAJOR GREATER_EQUAL 6) From 77010523bd9d7fe88b66fb5c37871e6bd6ac24e1 Mon Sep 17 00:00:00 2001 From: Koi Date: Fri, 19 Sep 2025 17:37:27 -0500 Subject: [PATCH 6/6] Hide extraction and Packages clone for CI. --- SerialPrograms/CMakeLists.txt | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 4100297009..1f068d81a8 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -2564,7 +2564,7 @@ if (APPLE) "${RESOURCES_PATH}" "$/../Resources" ) -elseif (WIN32) +elseif (WIN32 AND DEPLOY_FILES) # Set directories and file dependencies (we HAVE to depend on a file for build-time extraction/git clone to work) set(OPENCV_DEBUG_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.zip") set(OPENCV_DEBUG "${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.dll") @@ -2913,9 +2913,24 @@ endif() if (WIN32 AND NOT DEPLOY_FILES) file(GLOB MY_DLLS "../3rdPartyBinaries/*.dll" -) + ) + file(COPY ${MY_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + + message(STATUS "Extracting opencv_world4110d") + file(ARCHIVE_EXTRACT + INPUT ${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.zip + DESTINATION ${REPO_ROOT_DIR}/3rdPartyBinaries/ + ) -file(COPY ${MY_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + set(DISCORD_SDK_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip") + set(DISCORD_SDK_DIR "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win") + if(EXISTS "${DISCORD_SDK_ZIP}" AND NOT EXISTS "${DISCORD_SDK_DIR}") + message(STATUS "Extracting Social SDK") + file(ARCHIVE_EXTRACT + INPUT "${DISCORD_SDK_ZIP}" + DESTINATION "${REPO_ROOT_DIR}/3rdPartyBinaries" + ) + endif() endif() if (WIN32 AND DEPLOY_FILES)