Skip to content

Commit 31e1a93

Browse files
committed
- Force Qt to re-run CMake configuration.
- Limit Qt checks to Windows (assume default install directory). - Clean.
1 parent dec15e1 commit 31e1a93

File tree

2 files changed

+68
-37
lines changed

2 files changed

+68
-37
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 61 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
# Set the minimum cmake version required
22
cmake_minimum_required(VERSION 3.18.0)
33

4+
# Tell CMake to re-run configuration when these files change (get around Qt issues with stale CMake files)
5+
set(_cmake_files_to_watch
6+
"${CMAKE_SOURCE_DIR}/CMakeLists.txt"
7+
"${CMAKE_SOURCE_DIR}/CMakePresets.json"
8+
)
9+
10+
# Watch any helper .cmake files under cmake/
11+
file(GLOB_RECURSE _cmake_helper_files "${CMAKE_SOURCE_DIR}/cmake/*.cmake")
12+
list(APPEND _cmake_files_to_watch ${_cmake_helper_files})
13+
14+
# Append to the directory property so CMake will reconfigure when these change
15+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_cmake_files_to_watch})
16+
#message(STATUS "CMake will reconfigure when these change: ${_cmake_files_to_watch}")
17+
418
# Set the project name
519
project(SerialPrograms)
620

21+
# Enable C++23
22+
set(CMAKE_CXX_STANDARD 23)
23+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
24+
25+
# Produce clang tidy file
26+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
727
#set(CMAKE_VERBOSE_MAKEFILE ON)
28+
29+
set(CMAKE_AUTOMOC ON)
30+
set(CMAKE_AUTORCC ON)
31+
set(CMAKE_AUTOUIC ON)
32+
833
add_custom_target(build-time-make-directory ALL
934
COMMAND ${CMAKE_COMMAND} -E make_directory Assembly/)
1035

@@ -20,19 +45,6 @@ else()
2045
set(REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../")
2146
endif()
2247

23-
# Extract Discord Social SDK
24-
if(WIN32)
25-
message(STATUS "Extracting Social SDK")
26-
set(DISCORD_SDK_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip")
27-
set(DISCORD_SDK_DIR "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win")
28-
if(EXISTS "${DISCORD_SDK_ZIP}" AND NOT EXISTS "${DISCORD_SDK_DIR}")
29-
file(ARCHIVE_EXTRACT
30-
INPUT "${DISCORD_SDK_ZIP}"
31-
DESTINATION "${REPO_ROOT_DIR}/3rdPartyBinaries"
32-
)
33-
endif()
34-
endif()
35-
3648
# Determine environment
3749
if(DEFINED ENV{GITHUB_ACTIONS})
3850
message(STATUS "Detected CI environment, skipping file deployment")
@@ -76,10 +88,12 @@ else()
7688
set(FIRMWARE_DIR "${PACKAGES_DIR}/PABotBase/PABotBase-Switch")
7789
set(SCRIPTS_DIR "${PACKAGES_DIR}/SerialPrograms/Scripts")
7890
set(RESOURCES_DIR "${PACKAGES_DIR}/SerialPrograms/Resources")
79-
set(DEST_DIR "$<TARGET_FILE_DIR:SerialPrograms>/Output")
91+
8092
if(PACKAGE_BUILD)
93+
set(DEST_DIR "$<TARGET_FILE_DIR:SerialPrograms>/Output")
8194
set(DEPLOY_DIR "${DEST_DIR}/Binaries64")
8295
else()
96+
set(DEST_DIR "$<TARGET_FILE_DIR:SerialPrograms>")
8397
set(DEPLOY_DIR "${DEST_DIR}")
8498
endif()
8599

@@ -91,35 +105,36 @@ endif()
91105
set(THREADS_PREFER_PTHREAD_FLAG ON)
92106
find_package(Threads REQUIRED)
93107

94-
# Define the base Qt installation directory
95-
set(QT_BASE_DIR "C:/Qt")
96-
97108
# Define the major version of Qt to search for
98109
if(NOT QT_MAJOR)
99110
set(QT_MAJOR 6)
100111
endif()
101112

102-
# Find all subdirectories in the Qt base directory
103-
file(GLOB QT_SUBDIRS LIST_DIRECTORIES true "${QT_BASE_DIR}/${QT_MAJOR}*")
113+
find_package(Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED)
104114

105-
# Filter and sort the directories to find the latest version
106-
list(SORT QT_SUBDIRS)
107-
list(REVERSE QT_SUBDIRS)
115+
# Find Qt and windeployqt.exe relative to the Qt bin dir
116+
if(WIN32 AND DEPLOY_FILES)
117+
# Define the base Qt installation directory
118+
set(QT_BASE_DIR "C:/Qt")
108119

109-
# Get the first directory in the sorted list (latest version)
110-
list(GET QT_SUBDIRS 0 QT_LATEST_DIR)
120+
# Find all subdirectories in the Qt base directory
121+
file(GLOB QT_SUBDIRS LIST_DIRECTORIES true "${QT_BASE_DIR}/${QT_MAJOR}*")
111122

112-
# Debug message to verify the latest Qt directory
113-
if(QT_LATEST_DIR)
114-
message(STATUS "Latest Qt directory for Qt${QT_MAJOR}: ${QT_LATEST_DIR}")
115-
set(CMAKE_PREFIX_PATH "${QT_LATEST_DIR}/msvc2022_64/lib/cmake")
116-
else()
117-
message(FATAL_ERROR "No Qt${QT_MAJOR} installation found in ${QT_BASE_DIR}")
118-
endif()
123+
# Filter and sort the directories to find the latest version
124+
list(SORT QT_SUBDIRS)
125+
list(REVERSE QT_SUBDIRS)
126+
127+
# Get the first directory in the sorted list (latest version)
128+
list(GET QT_SUBDIRS 0 QT_LATEST_DIR)
129+
130+
# Debug message to verify the latest Qt directory
131+
if(QT_LATEST_DIR)
132+
message(STATUS "Latest Qt directory for Qt${QT_MAJOR}: ${QT_LATEST_DIR}")
133+
set(CMAKE_PREFIX_PATH "${QT_LATEST_DIR}/msvc2022_64/lib/cmake")
134+
else()
135+
message(FATAL_ERROR "No Qt${QT_MAJOR} installation found in ${QT_BASE_DIR}")
136+
endif()
119137

120-
find_package(Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED)
121-
# Find windeployqt.exe relative to the Qt bin dir
122-
if(WIN32 AND DEPLOY_FILES)
123138
get_target_property(qt_core_location Qt${QT_MAJOR}::Core LOCATION)
124139
get_filename_component(qt_bin_dir "${qt_core_location}" DIRECTORY)
125140
find_program(WINDEPLOYQT_EXECUTABLE windeployqt
@@ -2540,12 +2555,23 @@ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../Internal/SerialPrograms/Internal0.
25402555
target_sources(SerialPrograms PRIVATE ../../Internal/SerialPrograms/Internal1.cpp)
25412556
endif()
25422557

2543-
#extract opencv_world4110d.dll from archive on Windows Debug build
2558+
# Extract opencv_world4110d.dll from archive on Windows Debug build, extract Discord Social SDK for Windows
25442559
if (WIN32)
2560+
message(STATUS "Extracting opencv_world4110d")
25452561
file(ARCHIVE_EXTRACT
25462562
INPUT ${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.zip
25472563
DESTINATION ${REPO_ROOT_DIR}/3rdPartyBinaries/
25482564
)
2565+
2566+
set(DISCORD_SDK_ZIP "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip")
2567+
set(DISCORD_SDK_DIR "${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win")
2568+
if(EXISTS "${DISCORD_SDK_ZIP}" AND NOT EXISTS "${DISCORD_SDK_DIR}")
2569+
message(STATUS "Extracting Social SDK")
2570+
file(ARCHIVE_EXTRACT
2571+
INPUT "${DISCORD_SDK_ZIP}"
2572+
DESTINATION "${REPO_ROOT_DIR}/3rdPartyBinaries"
2573+
)
2574+
endif()
25492575
endif()
25502576

25512577
#add include directory

SerialPrograms/CMakePresets.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"name": "default",
1111
"hidden": true,
1212
"generator": "Ninja",
13-
"binaryDir": "${sourceDir}/../build",
13+
"binaryDir": "${sourceParentDir}/build",
1414
"cacheVariables": {
1515
"CMAKE_CXX_STANDARD": "23",
1616
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
@@ -25,6 +25,7 @@
2525
"name": "Debug",
2626
"inherits": "default",
2727
"description": "Build with debug information",
28+
"binaryDir": "${sourceParentDir}/build/${presetName}",
2829
"cacheVariables": {
2930
"CMAKE_BUILD_TYPE": "Debug",
3031
"PACKAGE_BUILD": "OFF"
@@ -34,6 +35,7 @@
3435
"name": "Release",
3536
"inherits": "default",
3637
"description": "Build for release",
38+
"binaryDir": "${sourceParentDir}/build/${presetName}",
3739
"cacheVariables": {
3840
"CMAKE_BUILD_TYPE": "Release",
3941
"PACKAGE_BUILD": "OFF"
@@ -43,6 +45,7 @@
4345
"name": "RelWithDebInfo",
4446
"inherits": "default",
4547
"description": "Build for release with debug information",
48+
"binaryDir": "${sourceParentDir}/build/${presetName}",
4649
"cacheVariables": {
4750
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
4851
"PACKAGE_BUILD": "OFF"
@@ -52,6 +55,7 @@
5255
"name": "MinSizeRel",
5356
"inherits": "default",
5457
"description": "Build for minimum size release",
58+
"binaryDir": "${sourceParentDir}/build/${presetName}",
5559
"cacheVariables": {
5660
"CMAKE_BUILD_TYPE": "MinSizeRel",
5761
"PACKAGE_BUILD": "OFF"
@@ -61,6 +65,7 @@
6165
"name": "Publish",
6266
"inherits": "default",
6367
"description": "Build for publishing with debug information and packaging enabled",
68+
"binaryDir": "${sourceParentDir}/build/${presetName}",
6469
"cacheVariables": {
6570
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
6671
"PACKAGE_BUILD": "ON"
@@ -94,4 +99,4 @@
9499
"configurePreset": "Publish"
95100
}
96101
]
97-
}
102+
}

0 commit comments

Comments
 (0)