@@ -53,37 +53,26 @@ else()
5353 message (STATUS "Detected local dev environment" )
5454 set (PACKAGES_DIR "${REPO_ROOT_DIR} /Packages" )
5555
56- # Clone or update the Packages repo
56+ # Add a custom command to clone Packages
5757 if (NOT EXISTS "${PACKAGES_DIR} /.git" )
58- message (STATUS "Packages repo not found. Cloning..." )
59- execute_process (
60- COMMAND git clone --branch master https://github.com/PokemonAutomation/Packages.git "${PACKAGES_DIR} "
61- RESULT_VARIABLE result
62- OUTPUT_VARIABLE out
63- ERROR_VARIABLE err
64- OUTPUT_STRIP_TRAILING_WHITESPACE
65- ERROR_STRIP_TRAILING_WHITESPACE
66- )
67-
68- if (NOT result EQUAL 0)
69- message (FATAL_ERROR "Failed to clone Packages repo:\n ${err} " )
70- endif ()
71- else ()
72- message (STATUS "Packages repo exists. Pulling latest changes..." )
73- execute_process (
74- COMMAND git -C "${PACKAGES_DIR} " pull origin master
75- RESULT_VARIABLE result
76- OUTPUT_VARIABLE out
77- ERROR_VARIABLE err
78- OUTPUT_STRIP_TRAILING_WHITESPACE
79- ERROR_STRIP_TRAILING_WHITESPACE
58+ add_custom_command (
59+ OUTPUT "${PACKAGES_DIR} /.git"
60+ COMMAND ${CMAKE_COMMAND} -E echo "Cloning Packages repo..."
61+ COMMAND ${CMAKE_COMMAND} -E make_directory "${PACKAGES_DIR} "
62+ COMMAND git clone --branch master https://github.com/PokemonAutomation/Packages "${PACKAGES_DIR} "
63+ WORKING_DIRECTORY "${REPO_ROOT_DIR} "
64+ COMMENT "Cloning Packages repository"
65+ VERBATIM
8066 )
81-
82- if (NOT result EQUAL 0)
83- message (WARNING "Failed to update Packages repo:\n ${err} " )
84- endif ()
8567 endif ()
8668
69+ list (APPEND _cmake_files_to_watch "${PACKAGES_DIR} /.git" )
70+ # Add a custom target which we will depend on in executable_add() later on
71+ add_custom_target (
72+ PackagesRepo
73+ DEPENDS "${PACKAGES_DIR} /.git"
74+ )
75+
8776 # Set paths for post-build deployment
8877 set (FIRMWARE_DIR "${PACKAGES_DIR} /PABotBase/PABotBase-Switch" )
8978 set (SCRIPTS_DIR "${PACKAGES_DIR} /SerialPrograms/Scripts" )
9887 endif ()
9988
10089 set (DEPLOY_FILES TRUE )
101- message (STATUS "Packages repo ready for deployment" )
10290endif ()
10391
10492#Find threads library
@@ -2552,7 +2540,28 @@ if (APPLE)
25522540 "${RESOURCES_PATH} "
25532541 "$<TARGET_FILE_DIR:SerialPrograms>/../Resources"
25542542 )
2555- else () # WIN and Linux:
2543+ elseif (WIN32 )
2544+ # Set directories and file dependencies (we HAVE to depend on a file for build-time extraction/git clone to work)
2545+ set (OPENCV_DEBUG_ZIP "${REPO_ROOT_DIR} /3rdPartyBinaries/opencv_world4110d.zip" )
2546+ set (OPENCV_DEBUG "${REPO_ROOT_DIR} /3rdPartyBinaries/opencv_world4110d.dll" )
2547+
2548+ set (DISCORD_ZIP "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win.zip" )
2549+ set (DISCORD_LIB_DEBUG "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win/lib/debug/discord_partner_sdk.lib" )
2550+ set (DISCORD_LIB_RELEASE "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win/lib/release/discord_partner_sdk.lib" )
2551+
2552+ list (APPEND _cmake_files_to_watch "${DISCORD_LIB_DEBUG} " )
2553+ list (APPEND _cmake_files_to_watch "${DISCORD_LIB_RELEASE} " )
2554+ list (APPEND _cmake_files_to_watch "${OPENCV_DEBUG} " )
2555+
2556+ add_custom_target (ExtractDependencies
2557+ COMMENT "Extracting 3rd party dependencies..."
2558+ DEPENDS ${DISCORD_LIB_DEBUG} ${DISCORD_LIB_RELEASE} ${OPENCV_DEBUG}
2559+ )
2560+
2561+ add_executable (SerialPrograms WIN32 ${MAIN_SOURCES} )
2562+ add_dependencies (SerialPrograms ExtractDependencies)
2563+ add_dependencies (SerialPrograms PackagesRepo)
2564+ else ()
25562565 add_executable (SerialPrograms WIN32 ${MAIN_SOURCES} )
25572566endif ()
25582567
@@ -2571,25 +2580,6 @@ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../Internal/SerialPrograms/Internal0.
25712580 target_sources (SerialPrograms PRIVATE ../../Internal /SerialPrograms/Internal1.cpp)
25722581endif ()
25732582
2574- # Extract opencv_world4110d.dll from archive on Windows Debug build, extract Discord Social SDK for Windows
2575- if (WIN32 )
2576- message (STATUS "Extracting opencv_world4110d" )
2577- file (ARCHIVE_EXTRACT
2578- INPUT ${REPO_ROOT_DIR} /3rdPartyBinaries/opencv_world4110d.zip
2579- DESTINATION ${REPO_ROOT_DIR} /3rdPartyBinaries/
2580- )
2581-
2582- set (DISCORD_SDK_ZIP "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win.zip" )
2583- set (DISCORD_SDK_DIR "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win" )
2584- if (EXISTS "${DISCORD_SDK_ZIP} " AND NOT EXISTS "${DISCORD_SDK_DIR} " )
2585- message (STATUS "Extracting Social SDK" )
2586- file (ARCHIVE_EXTRACT
2587- INPUT "${DISCORD_SDK_ZIP} "
2588- DESTINATION "${REPO_ROOT_DIR} /3rdPartyBinaries"
2589- )
2590- endif ()
2591- endif ()
2592-
25932583#add include directory
25942584target_include_directories (SerialPrograms SYSTEM PRIVATE ../3rdParty/)
25952585target_include_directories (SerialPrograms PRIVATE ../ ../../Internal / Source /)
@@ -2917,103 +2907,87 @@ file(COPY ${MY_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
29172907endif ()
29182908
29192909if (WIN32 AND DEPLOY_FILES)
2920- # Ensure the binaries directory exists
2921- add_custom_command (
2922- TARGET SerialPrograms
2923- POST_BUILD
2910+ # Ensure target dirs and copy content folders
2911+ set (DEPLOY_CMDS)
2912+ list ( APPEND DEPLOY_CMDS
2913+ COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Ensure deploy dir exists: ${DEPLOY_DIR} "
29242914 COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPLOY_DIR}
2925- COMMENT "Ensuring binary directory exists"
2926- )
29272915
2928- # Copy the resources folder to build directory
2929- add_custom_command (
2930- TARGET SerialPrograms
2931- POST_BUILD
2916+ COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying resources to destination dir: ${DEST_DIR} /Resources"
29322917 COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_DIR} "${DEST_DIR} /Resources"
2933- COMMENT "Copying the resources folder to the build directory"
2934- )
29352918
2936- # Copy the firmware folder to build directory
2937- add_custom_command (
2938- TARGET SerialPrograms
2939- POST_BUILD
2919+ COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying firmware to destination dir: ${DEST_DIR} /PABotBase"
29402920 COMMAND ${CMAKE_COMMAND} -E copy_directory ${FIRMWARE_DIR} "${DEST_DIR} /PABotBase"
2941- COMMENT "Copying the firmware folder to the build directory"
2942- )
29432921
2944- # Copy the scripts folder to build directory
2945- add_custom_command (
2946- TARGET SerialPrograms
2947- POST_BUILD
2922+ COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying scripts to destination dir: ${DEST_DIR} /Scripts"
29482923 COMMAND ${CMAKE_COMMAND} -E copy_directory ${SCRIPTS_DIR} "${DEST_DIR} /Scripts"
2949- COMMENT "Copying the scripts folder to the build directory"
29502924 )
29512925
2952- # Run windeployqt.exe to deploy Qt dependencies based on build type
2926+ # Run windeployqt for the current config
29532927 if (WINDEPLOYQT_EXECUTABLE)
2954- add_custom_command (
2955- TARGET SerialPrograms
2956- POST_BUILD
2928+ list (APPEND DEPLOY_CMDS
2929+ COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Running windeployqt"
29572930 COMMAND "${WINDEPLOYQT_EXECUTABLE} "
2958- --dir "${DEPLOY_DIR} "
2959- $<IF:$<CONFIG:Debug>,--debug,--release>
2960- $<TARGET_FILE:SerialPrograms>
2961- COMMENT "Deploying Qt dependencies for $<CONFIG>"
2931+ --dir "${DEPLOY_DIR} "
2932+ $<IF:$<CONFIG:Debug>,--debug,--release>
2933+ $<TARGET_FILE:SerialPrograms>
29622934 )
29632935 else ()
29642936 message (WARNING "windeployqt not found, skipping Qt deployment." )
29652937 endif ()
29662938
2967- # Move 3rd party DLLs to binaries folder
2968- file (GLOB THIRD_PARTY_DLLS "${REPO_ROOT_DIR} /3rdPartyBinaries/*.dll" )
2969- foreach (DLL ${THIRD_PARTY_DLLS} )
2970- get_filename_component (DLL_NAME ${DLL} NAME )
2971- add_custom_command (
2972- TARGET SerialPrograms
2973- POST_BUILD
2974- COMMAND ${CMAKE_COMMAND} -E copy ${DLL} "${DEPLOY_DIR} /${DLL_NAME} "
2975- COMMENT "Moving ${DLL_NAME} to binaries folder"
2976- )
2977- endforeach ()
2978-
2979- # Move binaries generated by CMake to binaries folder
2980- file (GLOB DLL_FILES "${CMAKE_CURRENT_BINARY_DIR} /*.dll" )
2981- foreach (DLL ${DLL_FILES} )
2982- get_filename_component (DLL_NAME ${DLL} NAME )
2983- add_custom_command (
2984- TARGET SerialPrograms
2985- POST_BUILD
2986- COMMAND ${CMAKE_COMMAND} -E rename ${DLL} "${DEPLOY_DIR} /${DLL_NAME} "
2987- COMMENT "Moving ${DLL_NAME} to binaries folder"
2988- )
2989- endforeach ()
2990-
2991- # Copy discord_social_sdk DLL based on build type
2992- add_custom_command (
2993- TARGET SerialPrograms
2994- POST_BUILD
2939+ # Copy Discord SDK DLL (config-specific)
2940+ list (APPEND DEPLOY_CMDS
2941+ COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying Discord SDK DLL"
29952942 COMMAND ${CMAKE_COMMAND} -E copy
2996- $<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" >
2997- "${DEPLOY_DIR} /discord_partner_sdk.dll"
2998- COMMENT "Copying Discord SDK DLL to the binaries folder"
2943+ $<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>
2944+ ${DEPLOY_DIR} /discord_partner_sdk.dll
29992945 )
30002946
3001- # Move the .exe file to Binaries64
3002- add_custom_command (
3003- TARGET SerialPrograms
3004- POST_BUILD
2947+ # Copy all 3rdPartyBinaries *.dll (computed at configure-time)
2948+ file (GLOB THIRD_PARTY_DLLS "${REPO_ROOT_DIR} /3rdPartyBinaries/*.dll" )
2949+ foreach (DLL IN LISTS THIRD_PARTY_DLLS)
2950+ message (STATUS "Adding deploy command for 3rd party DLL: ${DLL} " )
2951+ list (APPEND DEPLOY_CMDS COMMAND ${CMAKE_COMMAND} -E copy "${DLL} " "${DEPLOY_DIR} /" )
2952+ endforeach ()
2953+
2954+ # Copy the built exe and pdb (pdb guarded for existence)
2955+ list (APPEND DEPLOY_CMDS
2956+ COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying built exe and pdb"
30052957 COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE:SerialPrograms> "${DEPLOY_DIR} /$<TARGET_FILE_NAME:SerialPrograms>"
3006- COMMENT "Moving .exe to the binaries folder "
2958+ COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_PDB_FILE:SerialPrograms> " ${DEPLOY_DIR} /$<TARGET_PDB_FILE_NAME:SerialPrograms> "
30072959 )
30082960
3009- # Move the .pdb file to Binaries64
3010- add_custom_command (
3011- TARGET SerialPrograms
3012- POST_BUILD
3013- COMMAND ${CMAKE_COMMAND} -E make_directory "${DEPLOY_DIR} "
3014- COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_PDB_FILE:SerialPrograms> "${DEPLOY_DIR} /$<TARGET_PDB_FILE_NAME:SerialPrograms>"
3015- COMMENT "Moving .pdb to the binaries folder"
2961+ add_custom_target (DeployRuntime ALL
2962+ DEPENDS SerialPrograms ExtractDependencies PackagesRepo
2963+ COMMENT "Deploying runtime (Qt, packages, DLLs) to ${DEPLOY_DIR} "
2964+ VERBATIM
2965+ ${DEPLOY_CMDS}
30162966 )
2967+
2968+ # Extract Discord SDK build-time, if it doesn't already exist
2969+ if (NOT EXISTS "${DISCORD_LIB_DEBUG} " OR NOT EXISTS "${DISCORD_LIB_RELEASE} " )
2970+ message (STATUS "Discord SDK not found, extracting from zip..." )
2971+ add_custom_command (
2972+ OUTPUT "${DISCORD_LIB_DEBUG} " "${DISCORD_LIB_RELEASE} "
2973+ COMMAND ${CMAKE_COMMAND} -E tar xf "${DISCORD_ZIP} "
2974+ WORKING_DIRECTORY "${REPO_ROOT_DIR} /3rdPartyBinaries"
2975+ DEPENDS "${DISCORD_ZIP} "
2976+ COMMENT "Extracting Discord SDK"
2977+ )
2978+ endif ()
2979+
2980+ # Extract OpenCV debug DLL build-time, if it doesn't already exist
2981+ if (NOT EXISTS "${OPENCV_DEBUG} " )
2982+ message (STATUS "OpenCV debug DLL not found, extracting from zip..." )
2983+ add_custom_command (
2984+ OUTPUT "${OPENCV_DEBUG} "
2985+ COMMAND ${CMAKE_COMMAND} -E tar xf "${OPENCV_DEBUG_ZIP} "
2986+ WORKING_DIRECTORY "${REPO_ROOT_DIR} /3rdPartyBinaries"
2987+ DEPENDS "${OPENCV_DEBUG_ZIP} "
2988+ COMMENT "Extracting OpenCV debug DLL"
2989+ )
2990+ endif ()
30172991endif ()
30182992
30192993if (QT_MAJOR GREATER_EQUAL 6)
0 commit comments