Skip to content

Commit dec15e1

Browse files
committed
Add CMakePresets.json for additional build option to publish (experimental, will squash and force when Qt issues are figured out).
1 parent fbf8b8d commit dec15e1

File tree

2 files changed

+146
-25
lines changed

2 files changed

+146
-25
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
1-
#set the minimum cmake version required
1+
# Set the minimum cmake version required
22
cmake_minimum_required(VERSION 3.18.0)
33

4-
#set the name of the project
4+
# Set the project name
55
project(SerialPrograms)
66

7-
#enable c++ 23
8-
set(CMAKE_CXX_STANDARD 23)
9-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10-
11-
#produce clang tidy file
12-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
137
#set(CMAKE_VERBOSE_MAKEFILE ON)
14-
15-
set(CMAKE_AUTOMOC ON)
16-
set(CMAKE_AUTORCC ON)
17-
set(CMAKE_AUTOUIC ON)
18-
198
add_custom_target(build-time-make-directory ALL
209
COMMAND ${CMAKE_COMMAND} -E make_directory Assembly/)
2110

2211
# Find repo root folder path
2312
string(FIND "${CMAKE_CURRENT_SOURCE_DIR}" "Arduino-Source-Internal" internal_repo_position)
2413

2514
# Determine if this is an internal repo and normalize REPO_ROOT_DIR
26-
if (internal_repo_position EQUAL -1)
15+
if(internal_repo_position EQUAL -1)
2716
# We are building the public repo
2817
set(REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../")
2918
else()
3019
# We are building the internal repo
3120
set(REPO_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../")
3221
endif()
3322

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+
3436
# Determine environment
3537
if(DEFINED ENV{GITHUB_ACTIONS})
3638
message(STATUS "Detected CI environment, skipping file deployment")
3739
set(DEPLOY_FILES FALSE)
3840
else()
3941
message(STATUS "Detected local dev environment")
4042
set(PACKAGES_DIR "${REPO_ROOT_DIR}/Packages")
41-
message(STATUS "Packages directory: ${PACKAGES_DIR}")
4243

4344
# Clone or update the Packages repo
4445
if(NOT EXISTS "${PACKAGES_DIR}/.git")
@@ -51,6 +52,7 @@ else()
5152
OUTPUT_STRIP_TRAILING_WHITESPACE
5253
ERROR_STRIP_TRAILING_WHITESPACE
5354
)
55+
5456
if(NOT result EQUAL 0)
5557
message(FATAL_ERROR "Failed to clone Packages repo:\n${err}")
5658
endif()
@@ -64,6 +66,7 @@ else()
6466
OUTPUT_STRIP_TRAILING_WHITESPACE
6567
ERROR_STRIP_TRAILING_WHITESPACE
6668
)
69+
6770
if(NOT result EQUAL 0)
6871
message(WARNING "Failed to update Packages repo:\n${err}")
6972
endif()
@@ -73,8 +76,13 @@ else()
7376
set(FIRMWARE_DIR "${PACKAGES_DIR}/PABotBase/PABotBase-Switch")
7477
set(SCRIPTS_DIR "${PACKAGES_DIR}/SerialPrograms/Scripts")
7578
set(RESOURCES_DIR "${PACKAGES_DIR}/SerialPrograms/Resources")
76-
set(DEST_DIR "$<TARGET_FILE_DIR:SerialPrograms>")
77-
set(DEPLOY_DIR "$<TARGET_FILE_DIR:SerialPrograms>/Binaries64")
79+
set(DEST_DIR "$<TARGET_FILE_DIR:SerialPrograms>/Output")
80+
if(PACKAGE_BUILD)
81+
set(DEPLOY_DIR "${DEST_DIR}/Binaries64")
82+
else()
83+
set(DEPLOY_DIR "${DEST_DIR}")
84+
endif()
85+
7886
set(DEPLOY_FILES TRUE)
7987
message(STATUS "Packages repo ready for deployment")
8088
endif()
@@ -83,14 +91,35 @@ endif()
8391
set(THREADS_PREFER_PTHREAD_FLAG ON)
8492
find_package(Threads REQUIRED)
8593

86-
#find Qt
94+
# Define the base Qt installation directory
95+
set(QT_BASE_DIR "C:/Qt")
96+
97+
# Define the major version of Qt to search for
8798
if(NOT QT_MAJOR)
8899
set(QT_MAJOR 6)
89100
endif()
90101

102+
# Find all subdirectories in the Qt base directory
103+
file(GLOB QT_SUBDIRS LIST_DIRECTORIES true "${QT_BASE_DIR}/${QT_MAJOR}*")
104+
105+
# Filter and sort the directories to find the latest version
106+
list(SORT QT_SUBDIRS)
107+
list(REVERSE QT_SUBDIRS)
108+
109+
# Get the first directory in the sorted list (latest version)
110+
list(GET QT_SUBDIRS 0 QT_LATEST_DIR)
111+
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()
119+
91120
find_package(Qt${QT_MAJOR} COMPONENTS Widgets SerialPort Multimedia MultimediaWidgets REQUIRED)
92121
# Find windeployqt.exe relative to the Qt bin dir
93-
if (WIN32 AND DEPLOY_FILES)
122+
if(WIN32 AND DEPLOY_FILES)
94123
get_target_property(qt_core_location Qt${QT_MAJOR}::Core LOCATION)
95124
get_filename_component(qt_bin_dir "${qt_core_location}" DIRECTORY)
96125
find_program(WINDEPLOYQT_EXECUTABLE windeployqt
@@ -2511,17 +2540,12 @@ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../Internal/SerialPrograms/Internal0.
25112540
target_sources(SerialPrograms PRIVATE ../../Internal/SerialPrograms/Internal1.cpp)
25122541
endif()
25132542

2514-
#extract opencv_world4110d.dll from archive on Windows Debug build, extract Discord Social SDK
2543+
#extract opencv_world4110d.dll from archive on Windows Debug build
25152544
if (WIN32)
25162545
file(ARCHIVE_EXTRACT
25172546
INPUT ${REPO_ROOT_DIR}/3rdPartyBinaries/opencv_world4110d.zip
25182547
DESTINATION ${REPO_ROOT_DIR}/3rdPartyBinaries/
25192548
)
2520-
2521-
file(ARCHIVE_EXTRACT
2522-
INPUT ${REPO_ROOT_DIR}/3rdPartyBinaries/discord_social_sdk_win.zip
2523-
DESTINATION ${REPO_ROOT_DIR}/3rdPartyBinaries/
2524-
)
25252549
endif()
25262550

25272551
#add include directory

SerialPrograms/CMakePresets.json

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"version": 3,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 18,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "default",
11+
"hidden": true,
12+
"generator": "Ninja",
13+
"binaryDir": "${sourceDir}/../build",
14+
"cacheVariables": {
15+
"CMAKE_CXX_STANDARD": "23",
16+
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
17+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
18+
"CMAKE_AUTOMOC": "ON",
19+
"CMAKE_AUTORCC": "ON",
20+
"CMAKE_AUTOUIC": "ON",
21+
"PACKAGE_BUILD": "OFF"
22+
}
23+
},
24+
{
25+
"name": "Debug",
26+
"inherits": "default",
27+
"description": "Build with debug information",
28+
"cacheVariables": {
29+
"CMAKE_BUILD_TYPE": "Debug",
30+
"PACKAGE_BUILD": "OFF"
31+
}
32+
},
33+
{
34+
"name": "Release",
35+
"inherits": "default",
36+
"description": "Build for release",
37+
"cacheVariables": {
38+
"CMAKE_BUILD_TYPE": "Release",
39+
"PACKAGE_BUILD": "OFF"
40+
}
41+
},
42+
{
43+
"name": "RelWithDebInfo",
44+
"inherits": "default",
45+
"description": "Build for release with debug information",
46+
"cacheVariables": {
47+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
48+
"PACKAGE_BUILD": "OFF"
49+
}
50+
},
51+
{
52+
"name": "MinSizeRel",
53+
"inherits": "default",
54+
"description": "Build for minimum size release",
55+
"cacheVariables": {
56+
"CMAKE_BUILD_TYPE": "MinSizeRel",
57+
"PACKAGE_BUILD": "OFF"
58+
}
59+
},
60+
{
61+
"name": "Publish",
62+
"inherits": "default",
63+
"description": "Build for publishing with debug information and packaging enabled",
64+
"cacheVariables": {
65+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
66+
"PACKAGE_BUILD": "ON"
67+
}
68+
}
69+
],
70+
"buildPresets": [
71+
{
72+
"name": "default",
73+
"hidden": true,
74+
"configurePreset": "default"
75+
},
76+
{
77+
"name": "Debug",
78+
"configurePreset": "Debug"
79+
},
80+
{
81+
"name": "Release",
82+
"configurePreset": "Release"
83+
},
84+
{
85+
"name": "RelWithDebInfo",
86+
"configurePreset": "RelWithDebInfo"
87+
},
88+
{
89+
"name": "MinSizeRel",
90+
"configurePreset": "MinSizeRel"
91+
},
92+
{
93+
"name": "Publish",
94+
"configurePreset": "Publish"
95+
}
96+
]
97+
}

0 commit comments

Comments
 (0)