11# Set the minimum cmake version required
22cmake_minimum_required (VERSION 3.18.0)
3-
3+
44# Tell CMake to re-run configuration when these files change (get around Qt issues with stale CMake files)
55set (_cmake_files_to_watch
66 "${CMAKE_SOURCE_DIR} /CMakeLists.txt"
@@ -51,32 +51,6 @@ if(DEFINED ENV{GITHUB_ACTIONS})
5151 set (DEPLOY_FILES FALSE )
5252else ()
5353 message (STATUS "Detected local dev environment" )
54- set (PACKAGES_DIR "${REPO_ROOT_DIR} /Packages" )
55-
56- # Add a custom command to clone Packages
57- if (NOT EXISTS "${PACKAGES_DIR} /.git" )
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
66- )
67- endif ()
68-
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-
76- # Set paths for post-build deployment
77- set (FIRMWARE_DIR "${PACKAGES_DIR} /PABotBase/PABotBase-Switch" )
78- set (SCRIPTS_DIR "${PACKAGES_DIR} /SerialPrograms/Scripts" )
79- set (RESOURCES_DIR "${PACKAGES_DIR} /SerialPrograms/Resources" )
8054 if (PACKAGE_BUILD)
8155 set (DEST_DIR "$<TARGET_FILE_DIR:SerialPrograms>/Output" )
8256 set (DEPLOY_DIR "${DEST_DIR} /Binaries64" )
@@ -96,12 +70,7 @@ if(NOT QT_MAJOR)
9670 set (QT_MAJOR 6)
9771endif ()
9872
99- # Make sure CI builds work without going overboard with per-platform directory shenanigans
100- if (NOT WIN32 OR NOT DEPLOY_FILES)
101- find_package (Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED)
102- endif ()
103-
104- # Find Qt and windeployqt.exe relative to the Qt bin dir
73+ # Find Qt and windeployqt.exe relative to the Qt bin dir. If CI, not Windows, or not deploying, just find_package()
10574if (WIN32 AND DEPLOY_FILES)
10675 # Define the base Qt installation directory
10776 if (PREFERRED_QT_DIR AND PREFERRED_QT_VER)
@@ -144,6 +113,8 @@ if(WIN32 AND DEPLOY_FILES)
144113 PATH_SUFFIXES ../bin bin
145114 REQUIRED
146115 )
116+ else ()
117+ find_package (Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED)
147118endif ()
148119
149120#disable deprecated Qt APIs
@@ -187,27 +158,6 @@ if (APPLE)
187158 "${RESOURCES_PATH} "
188159 "$<TARGET_FILE_DIR:SerialPrograms>/../Resources"
189160 )
190- elseif (WIN32 AND DEPLOY_FILES)
191- # Set directories and file dependencies (we HAVE to depend on a file for build-time extraction/git clone to work)
192- set (OPENCV_DEBUG_ZIP "${REPO_ROOT_DIR} /3rdPartyBinaries/opencv_world4110d.zip" )
193- set (OPENCV_DEBUG "${REPO_ROOT_DIR} /3rdPartyBinaries/opencv_world4110d.dll" )
194-
195- set (DISCORD_ZIP "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win.zip" )
196- set (DISCORD_LIB_DEBUG "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win/lib/debug/discord_partner_sdk.lib" )
197- set (DISCORD_LIB_RELEASE "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win/lib/release/discord_partner_sdk.lib" )
198-
199- list (APPEND _cmake_files_to_watch "${DISCORD_LIB_DEBUG} " )
200- list (APPEND _cmake_files_to_watch "${DISCORD_LIB_RELEASE} " )
201- list (APPEND _cmake_files_to_watch "${OPENCV_DEBUG} " )
202-
203- add_custom_target (ExtractDependencies
204- COMMENT "Extracting 3rd party dependencies..."
205- DEPENDS ${DISCORD_LIB_DEBUG} ${DISCORD_LIB_RELEASE} ${OPENCV_DEBUG}
206- )
207-
208- add_executable (SerialPrograms WIN32 ${MAIN_SOURCES} )
209- add_dependencies (SerialPrograms ExtractDependencies)
210- add_dependencies (SerialPrograms PackagesRepo)
211161else ()
212162 add_executable (SerialPrograms WIN32 ${MAIN_SOURCES} )
213163endif ()
@@ -557,87 +507,125 @@ if (WIN32 AND NOT DEPLOY_FILES)
557507endif ()
558508
559509if (WIN32 AND DEPLOY_FILES)
560- # Ensure target dirs and copy content folders
561- set (DEPLOY_CMDS)
562- list (APPEND DEPLOY_CMDS
563- COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Ensure deploy dir exists: ${DEPLOY_DIR} "
564- COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPLOY_DIR}
510+ set (PACKAGES_DIR "${REPO_ROOT_DIR} /Packages" )
511+ set (OPENCV_DEBUG_ZIP "${REPO_ROOT_DIR} /3rdPartyBinaries/opencv_world4110d.zip" )
512+ set (OPENCV_DEBUG_DLL "${REPO_ROOT_DIR} /3rdPartyBinaries/opencv_world4110d.dll" )
565513
566- COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying resources to destination dir: ${DEST_DIR} /Resources"
567- COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_DIR} "${DEST_DIR} /Resources"
514+ set (DISCORD_ZIP "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win.zip" )
515+ set (DISCORD_DIR "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win" )
516+ set (DISCORD_DLL_DEBUG "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win/bin/debug/discord_partner_sdk.dll" )
517+ set (DISCORD_DLL_RELEASE "${REPO_ROOT_DIR} /3rdPartyBinaries/discord_social_sdk_win/bin/release/discord_partner_sdk.dll" )
568518
569- COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying firmware to destination dir: ${DEST_DIR} /PABotBase"
570- COMMAND ${CMAKE_COMMAND} -E copy_directory ${FIRMWARE_DIR} "${DEST_DIR} /PABotBase"
519+ set (FIRMWARE_DIR "${PACKAGES_DIR} /PABotBase/PABotBase-Switch" )
520+ set (SCRIPTS_DIR "${PACKAGES_DIR} /SerialPrograms/Scripts" )
521+ set (RESOURCES_DIR "${PACKAGES_DIR} /SerialPrograms/Resources" )
571522
572- COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying scripts to destination dir: ${DEST_DIR} /Scripts"
573- COMMAND ${CMAKE_COMMAND} -E copy_directory ${SCRIPTS_DIR} "${DEST_DIR} /Scripts"
574- )
523+ # Clone Packages repo if not already present
524+ if (NOT EXISTS "${PACKAGES_DIR} " )
525+ message (STATUS "Cloning Packages repo at configure time..." )
526+ execute_process (
527+ COMMAND git clone --branch master https://github.com/PokemonAutomation/Packages "${PACKAGES_DIR} "
528+ WORKING_DIRECTORY "${REPO_ROOT_DIR} "
529+ )
530+ add_custom_target (clone_packages DEPENDS "${PACKAGES_DIR} " )
531+ add_dependencies (SerialPrograms clone_packages)
532+ else ()
533+ add_custom_target (clone_packages COMMENT "Packages repo already present, skipping clone." )
534+ endif ()
535+
536+ # Copy resources if not already present
537+ if (NOT EXISTS "${DEST_DIR} /Resources" )
538+ add_custom_command (
539+ TARGET SerialPrograms POST_BUILD
540+ COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying resources"
541+ COMMAND ${CMAKE_COMMAND} -E copy_directory "${RESOURCES_DIR} " "${DEST_DIR} /Resources"
542+ )
543+ endif ()
544+
545+ # Copy firmware if not already present
546+ if (NOT EXISTS "${DEST_DIR} /Firmware" )
547+ add_custom_command (
548+ TARGET SerialPrograms POST_BUILD
549+ COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying firmware"
550+ COMMAND ${CMAKE_COMMAND} -E copy_directory "${FIRMWARE_DIR} " "${DEST_DIR} /Firmware"
551+ )
552+ endif ()
575553
576- # Run windeployqt for the current config
577- if (WINDEPLOYQT_EXECUTABLE)
578- list (APPEND DEPLOY_CMDS
554+ # Copy scripts if not already present
555+ if (NOT EXISTS "${DEST_DIR} /Scripts" )
556+ add_custom_command (
557+ TARGET SerialPrograms POST_BUILD
558+ COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying scripts"
559+ COMMAND ${CMAKE_COMMAND} -E copy_directory "${SCRIPTS_DIR} " "${DEST_DIR} /Scripts"
560+ )
561+ endif ()
562+
563+ # Run windeployqt if Qt DLLs are missing
564+ if (WINDEPLOYQT_EXECUTABLE AND NOT EXISTS "${DEPLOY_DIR} /Qt6Core.dll" )
565+ add_custom_command (
566+ TARGET SerialPrograms POST_BUILD
579567 COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Running windeployqt"
580568 COMMAND "${WINDEPLOYQT_EXECUTABLE} "
581569 --dir "${DEPLOY_DIR} "
582570 $<IF:$<CONFIG:Debug>,--debug,--release>
583571 $<TARGET_FILE:SerialPrograms>
584572 )
573+ add_custom_target (run_windeployqt DEPENDS $<TARGET_FILE:SerialPrograms>)
585574 else ()
586575 message (WARNING "windeployqt not found, skipping Qt deployment." )
587576 endif ()
588577
589- # Copy Discord SDK DLL (config-specific)
590- list (APPEND DEPLOY_CMDS
578+ # Copy Discord SDK DLL
579+ add_custom_command (
580+ TARGET SerialPrograms POST_BUILD
591581 COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying Discord SDK DLL"
592- COMMAND ${CMAKE_COMMAND} -E copy
593- $<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>
594- ${DEPLOY_DIR} /discord_partner_sdk.dll
582+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
583+ " $<IF:$<CONFIG:Debug>,${DISCORD_DLL_DEBUG} ,${DISCORD_DLL_RELEASE} >"
584+ " ${DEPLOY_DIR} /discord_partner_sdk.dll"
595585 )
596586
597- # Copy all 3rdPartyBinaries *.dll (computed at configure-time)
587+ # Copy 3rd party DLLs if missing/different
598588 file (GLOB THIRD_PARTY_DLLS "${REPO_ROOT_DIR} /3rdPartyBinaries/*.dll" )
599589 foreach (DLL IN LISTS THIRD_PARTY_DLLS)
600- message (STATUS "Adding deploy command for 3rd party DLL: ${DLL} " )
601- list (APPEND DEPLOY_CMDS COMMAND ${CMAKE_COMMAND} -E copy "${DLL} " "${DEPLOY_DIR} /" )
590+ get_filename_component (DLL_NAME "${DLL} " NAME )
591+ add_custom_command (
592+ TARGET SerialPrograms POST_BUILD
593+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "${DLL} " "${DEPLOY_DIR} /${DLL_NAME} "
594+ )
602595 endforeach ()
603596
604- # Copy the built exe and pdb (pdb guarded for existence)
605- list (APPEND DEPLOY_CMDS
606- COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying built exe and pdb"
597+ # Move built .exe and .pdb to deploy folder
598+ add_custom_command (
599+ TARGET SerialPrograms POST_BUILD
600+ COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Moving built exe and pdb"
607601 COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE:SerialPrograms> "${DEPLOY_DIR} /$<TARGET_FILE_NAME:SerialPrograms>"
608602 COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_PDB_FILE:SerialPrograms> "${DEPLOY_DIR} /$<TARGET_PDB_FILE_NAME:SerialPrograms>"
609603 )
610604
611- add_custom_target (DeployRuntime ALL
612- DEPENDS SerialPrograms ExtractDependencies PackagesRepo
613- COMMENT "Deploying runtime (Qt, packages, DLLs) to ${DEPLOY_DIR} "
614- VERBATIM
615- ${DEPLOY_CMDS}
616- )
617-
618- # Extract Discord SDK build-time, if it doesn't already exist
619- if (NOT EXISTS "${DISCORD_LIB_DEBUG} " OR NOT EXISTS "${DISCORD_LIB_RELEASE} " )
605+ # Extract Discord SDK if missing
606+ if (NOT EXISTS "${DISCORD_DIR} " )
620607 message (STATUS "Discord SDK not found, extracting from zip..." )
621- add_custom_command (
622- OUTPUT "${DISCORD_LIB_DEBUG} " "${DISCORD_LIB_RELEASE} "
608+ execute_process (
623609 COMMAND ${CMAKE_COMMAND} -E tar xf "${DISCORD_ZIP} "
624610 WORKING_DIRECTORY "${REPO_ROOT_DIR} /3rdPartyBinaries"
625- DEPENDS "${DISCORD_ZIP} "
626- COMMENT "Extracting Discord SDK"
627611 )
628612 endif ()
629613
630- # Extract OpenCV debug DLL build-time, if it doesn't already exist
631- if (NOT EXISTS "${OPENCV_DEBUG } " )
614+ # Extract OpenCV debug DLL if missing
615+ if (NOT EXISTS "${OPENCV_DEBUG_DLL } " )
632616 message (STATUS "OpenCV debug DLL not found, extracting from zip..." )
633- add_custom_command (
634- OUTPUT "${OPENCV_DEBUG} "
617+ execute_process (
635618 COMMAND ${CMAKE_COMMAND} -E tar xf "${OPENCV_DEBUG_ZIP} "
636619 WORKING_DIRECTORY "${REPO_ROOT_DIR} /3rdPartyBinaries"
637- DEPENDS "${OPENCV_DEBUG_ZIP} "
638- COMMENT "Extracting OpenCV debug DLL"
639620 )
640621 endif ()
622+
623+ # Final target that depends on all deployment steps
624+ add_custom_target (DeployRuntime ALL
625+ DEPENDS SerialPrograms clone_packages run_windeployqt
626+ COMMENT "Deploying runtime (Qt, packages, DLLs) to ${DEPLOY_DIR} "
627+ VERBATIM
628+ )
641629endif ()
642630
643631if (QT_MAJOR GREATER_EQUAL 6)
0 commit comments