Skip to content

Commit f828a8b

Browse files
committed
Clone Packages repo and extract .zip files if directories don't exist, make deployment run build-time. Update missing files in the build directory.
1 parent 84aef50 commit f828a8b

File tree

1 file changed

+96
-122
lines changed

1 file changed

+96
-122
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 96 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -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")
@@ -98,7 +87,6 @@ else()
9887
endif()
9988

10089
set(DEPLOY_FILES TRUE)
101-
message(STATUS "Packages repo ready for deployment")
10290
endif()
10391

10492
#Find threads library
@@ -2576,7 +2564,28 @@ if (APPLE)
25762564
"${RESOURCES_PATH}"
25772565
"$<TARGET_FILE_DIR:SerialPrograms>/../Resources"
25782566
)
2579-
else() # WIN and Linux:
2567+
elseif (WIN32)
2568+
# Set directories and file dependencies (we HAVE to depend on a file for build-time extraction/git clone to work)
2569+
set(OPENCV_DEBUG_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.zip")
2570+
set(OPENCV_DEBUG "${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.dll")
2571+
2572+
set(DISCORD_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip")
2573+
set(DISCORD_LIB_DEBUG "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win/lib/debug/discord_partner_sdk.lib")
2574+
set(DISCORD_LIB_RELEASE "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win/lib/release/discord_partner_sdk.lib")
2575+
2576+
list(APPEND _cmake_files_to_watch "${DISCORD_LIB_DEBUG}")
2577+
list(APPEND _cmake_files_to_watch "${DISCORD_LIB_RELEASE}")
2578+
list(APPEND _cmake_files_to_watch "${OPENCV_DEBUG}")
2579+
2580+
add_custom_target(ExtractDependencies
2581+
COMMENT "Extracting 3rd party dependencies..."
2582+
DEPENDS ${DISCORD_LIB_DEBUG} ${DISCORD_LIB_RELEASE} ${OPENCV_DEBUG}
2583+
)
2584+
2585+
add_executable(SerialPrograms WIN32 ${MAIN_SOURCES})
2586+
add_dependencies(SerialPrograms ExtractDependencies)
2587+
add_dependencies(SerialPrograms PackagesRepo)
2588+
else()
25802589
add_executable(SerialPrograms WIN32 ${MAIN_SOURCES})
25812590
endif()
25822591

@@ -2595,25 +2604,6 @@ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../Internal/SerialPrograms/Internal0.
25952604
target_sources(SerialPrograms PRIVATE ../../Internal/SerialPrograms/Internal1.cpp)
25962605
endif()
25972606

2598-
# Extract opencv_world4110d.dll from archive on Windows Debug build, extract Discord Social SDK for Windows
2599-
if (WIN32)
2600-
message(STATUS "Extracting opencv_world4110d")
2601-
file(ARCHIVE_EXTRACT
2602-
INPUT ${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.zip
2603-
DESTINATION ${REPO_ROOT_DIR}/3rdPartyBinaries/
2604-
)
2605-
2606-
set(DISCORD_SDK_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip")
2607-
set(DISCORD_SDK_DIR "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win")
2608-
if(EXISTS "${DISCORD_SDK_ZIP}" AND NOT EXISTS "${DISCORD_SDK_DIR}")
2609-
message(STATUS "Extracting Social SDK")
2610-
file(ARCHIVE_EXTRACT
2611-
INPUT "${DISCORD_SDK_ZIP}"
2612-
DESTINATION "${REPO_ROOT_DIR}/3rdPartyBinaries"
2613-
)
2614-
endif()
2615-
endif()
2616-
26172607
#add include directory
26182608
target_include_directories(SerialPrograms SYSTEM PRIVATE ../3rdParty/)
26192609
target_include_directories(SerialPrograms PRIVATE ../ ../../Internal/ Source/)
@@ -2929,103 +2919,87 @@ file(COPY ${MY_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
29292919
endif()
29302920

29312921
if (WIN32 AND DEPLOY_FILES)
2932-
# Ensure the binaries directory exists
2933-
add_custom_command(
2934-
TARGET SerialPrograms
2935-
POST_BUILD
2922+
# Ensure target dirs and copy content folders
2923+
set(DEPLOY_CMDS)
2924+
list(APPEND DEPLOY_CMDS
2925+
COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Ensure deploy dir exists: ${DEPLOY_DIR}"
29362926
COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPLOY_DIR}
2937-
COMMENT "Ensuring binary directory exists"
2938-
)
29392927

2940-
# Copy the resources folder to build directory
2941-
add_custom_command(
2942-
TARGET SerialPrograms
2943-
POST_BUILD
2928+
COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying resources to destination dir: ${DEST_DIR}/Resources"
29442929
COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_DIR} "${DEST_DIR}/Resources"
2945-
COMMENT "Copying the resources folder to the build directory"
2946-
)
29472930

2948-
# Copy the firmware folder to build directory
2949-
add_custom_command(
2950-
TARGET SerialPrograms
2951-
POST_BUILD
2931+
COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying firmware to destination dir: ${DEST_DIR}/PABotBase"
29522932
COMMAND ${CMAKE_COMMAND} -E copy_directory ${FIRMWARE_DIR} "${DEST_DIR}/PABotBase"
2953-
COMMENT "Copying the firmware folder to the build directory"
2954-
)
29552933

2956-
# Copy the scripts folder to build directory
2957-
add_custom_command(
2958-
TARGET SerialPrograms
2959-
POST_BUILD
2934+
COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying scripts to destination dir: ${DEST_DIR}/Scripts"
29602935
COMMAND ${CMAKE_COMMAND} -E copy_directory ${SCRIPTS_DIR} "${DEST_DIR}/Scripts"
2961-
COMMENT "Copying the scripts folder to the build directory"
29622936
)
29632937

2964-
# Run windeployqt.exe to deploy Qt dependencies based on build type
2938+
# Run windeployqt for the current config
29652939
if(WINDEPLOYQT_EXECUTABLE)
2966-
add_custom_command(
2967-
TARGET SerialPrograms
2968-
POST_BUILD
2940+
list(APPEND DEPLOY_CMDS
2941+
COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Running windeployqt"
29692942
COMMAND "${WINDEPLOYQT_EXECUTABLE}"
2970-
--dir "${DEPLOY_DIR}"
2971-
$<IF:$<CONFIG:Debug>,--debug,--release>
2972-
$<TARGET_FILE:SerialPrograms>
2973-
COMMENT "Deploying Qt dependencies for $<CONFIG>"
2943+
--dir "${DEPLOY_DIR}"
2944+
$<IF:$<CONFIG:Debug>,--debug,--release>
2945+
$<TARGET_FILE:SerialPrograms>
29742946
)
29752947
else()
29762948
message(WARNING "windeployqt not found, skipping Qt deployment.")
29772949
endif()
29782950

2979-
# Move 3rd party DLLs to binaries folder
2980-
file(GLOB THIRD_PARTY_DLLS "${REPO_ROOT_DIR}/3rdPartyBinaries/*.dll")
2981-
foreach(DLL ${THIRD_PARTY_DLLS})
2982-
get_filename_component(DLL_NAME ${DLL} NAME)
2983-
add_custom_command(
2984-
TARGET SerialPrograms
2985-
POST_BUILD
2986-
COMMAND ${CMAKE_COMMAND} -E copy ${DLL} "${DEPLOY_DIR}/${DLL_NAME}"
2987-
COMMENT "Moving ${DLL_NAME} to binaries folder"
2988-
)
2989-
endforeach()
2990-
2991-
# Move binaries generated by CMake to binaries folder
2992-
file(GLOB DLL_FILES "${CMAKE_CURRENT_BINARY_DIR}/*.dll")
2993-
foreach(DLL ${DLL_FILES})
2994-
get_filename_component(DLL_NAME ${DLL} NAME)
2995-
add_custom_command(
2996-
TARGET SerialPrograms
2997-
POST_BUILD
2998-
COMMAND ${CMAKE_COMMAND} -E rename ${DLL} "${DEPLOY_DIR}/${DLL_NAME}"
2999-
COMMENT "Moving ${DLL_NAME} to binaries folder"
3000-
)
3001-
endforeach()
3002-
3003-
# Copy discord_social_sdk DLL based on build type
3004-
add_custom_command(
3005-
TARGET SerialPrograms
3006-
POST_BUILD
2951+
# Copy Discord SDK DLL (config-specific)
2952+
list(APPEND DEPLOY_CMDS
2953+
COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying Discord SDK DLL"
30072954
COMMAND ${CMAKE_COMMAND} -E copy
3008-
$<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">
3009-
"${DEPLOY_DIR}/discord_partner_sdk.dll"
3010-
COMMENT "Copying Discord SDK DLL to the binaries folder"
2955+
$<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>
2956+
${DEPLOY_DIR}/discord_partner_sdk.dll
30112957
)
30122958

3013-
# Move the .exe file to Binaries64
3014-
add_custom_command(
3015-
TARGET SerialPrograms
3016-
POST_BUILD
2959+
# Copy all 3rdPartyBinaries *.dll (computed at configure-time)
2960+
file(GLOB THIRD_PARTY_DLLS "${REPO_ROOT_DIR}/3rdPartyBinaries/*.dll")
2961+
foreach(DLL IN LISTS THIRD_PARTY_DLLS)
2962+
message(STATUS "Adding deploy command for 3rd party DLL: ${DLL}")
2963+
list(APPEND DEPLOY_CMDS COMMAND ${CMAKE_COMMAND} -E copy "${DLL}" "${DEPLOY_DIR}/")
2964+
endforeach()
2965+
2966+
# Copy the built exe and pdb (pdb guarded for existence)
2967+
list(APPEND DEPLOY_CMDS
2968+
COMMAND ${CMAKE_COMMAND} -E echo "[Deploy] Copying built exe and pdb"
30172969
COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE:SerialPrograms> "${DEPLOY_DIR}/$<TARGET_FILE_NAME:SerialPrograms>"
3018-
COMMENT "Moving .exe to the binaries folder"
2970+
COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_PDB_FILE:SerialPrograms> "${DEPLOY_DIR}/$<TARGET_PDB_FILE_NAME:SerialPrograms>"
30192971
)
30202972

3021-
# Move the .pdb file to Binaries64
3022-
add_custom_command(
3023-
TARGET SerialPrograms
3024-
POST_BUILD
3025-
COMMAND ${CMAKE_COMMAND} -E make_directory "${DEPLOY_DIR}"
3026-
COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_PDB_FILE:SerialPrograms> "${DEPLOY_DIR}/$<TARGET_PDB_FILE_NAME:SerialPrograms>"
3027-
COMMENT "Moving .pdb to the binaries folder"
2973+
add_custom_target(DeployRuntime ALL
2974+
DEPENDS SerialPrograms ExtractDependencies PackagesRepo
2975+
COMMENT "Deploying runtime (Qt, packages, DLLs) to ${DEPLOY_DIR}"
2976+
VERBATIM
2977+
${DEPLOY_CMDS}
30282978
)
2979+
2980+
# Extract Discord SDK build-time, if it doesn't already exist
2981+
if (NOT EXISTS "${DISCORD_LIB_DEBUG}" OR NOT EXISTS "${DISCORD_LIB_RELEASE}")
2982+
message(STATUS "Discord SDK not found, extracting from zip...")
2983+
add_custom_command(
2984+
OUTPUT "${DISCORD_LIB_DEBUG}" "${DISCORD_LIB_RELEASE}"
2985+
COMMAND ${CMAKE_COMMAND} -E tar xf "${DISCORD_ZIP}"
2986+
WORKING_DIRECTORY "${REPO_ROOT_DIR}/3rdPartyBinaries"
2987+
DEPENDS "${DISCORD_ZIP}"
2988+
COMMENT "Extracting Discord SDK"
2989+
)
2990+
endif()
2991+
2992+
# Extract OpenCV debug DLL build-time, if it doesn't already exist
2993+
if (NOT EXISTS "${OPENCV_DEBUG}")
2994+
message(STATUS "OpenCV debug DLL not found, extracting from zip...")
2995+
add_custom_command(
2996+
OUTPUT "${OPENCV_DEBUG}"
2997+
COMMAND ${CMAKE_COMMAND} -E tar xf "${OPENCV_DEBUG_ZIP}"
2998+
WORKING_DIRECTORY "${REPO_ROOT_DIR}/3rdPartyBinaries"
2999+
DEPENDS "${OPENCV_DEBUG_ZIP}"
3000+
COMMENT "Extracting OpenCV debug DLL"
3001+
)
3002+
endif()
30293003
endif()
30303004

30313005
if (QT_MAJOR GREATER_EQUAL 6)

0 commit comments

Comments
 (0)