| 1 |
cmake_minimum_required(VERSION 3.17.0 FATAL_ERROR) |
| 2 |
|
| 3 |
# check whether the required project meta-data has been set before including this module |
| 4 |
if (NOT META_PROJECT_NAME) |
| 5 |
message(FATAL_ERROR "No project name (META_PROJECT_NAME) specified.") |
| 6 |
endif () |
| 7 |
if (NOT META_APP_NAME) |
| 8 |
message(FATAL_ERROR "No project name (META_APP_NAME) specified.") |
| 9 |
endif () |
| 10 |
if (NOT META_APP_AUTHOR) |
| 11 |
message(FATAL_ERROR "No project name (META_APP_AUTHOR) specified.") |
| 12 |
endif () |
| 13 |
if (NOT META_APP_DESCRIPTION) |
| 14 |
message(FATAL_ERROR "No project name (META_APP_DESCRIPTION) specified.") |
| 15 |
endif () |
| 16 |
|
| 17 |
# set project name (displayed in Qt Creator) note: The project name is at least shown in Qt Creator this way but |
| 18 |
# unfortunately setting project() from an included file is not sufficient (see |
| 19 |
# https://cmake.org/cmake/help/latest/command/project.html#usage). |
| 20 |
message(STATUS "Configuring project ${META_PROJECT_NAME}") |
| 21 |
project(${META_PROJECT_NAME}) |
| 22 |
|
| 23 |
# set META_PROJECT_VARNAME and META_PROJECT_VARNAME_UPPER if not specified explicitly |
| 24 |
if (NOT META_PROJECT_VARNAME) |
| 25 |
set(META_PROJECT_VARNAME "${META_PROJECT_NAME}") |
| 26 |
endif () |
| 27 |
if (NOT META_PROJECT_VARNAME_UPPER) |
| 28 |
string(TOUPPER ${META_PROJECT_VARNAME} META_PROJECT_VARNAME_UPPER) |
| 29 |
endif () |
| 30 |
if (NOT META_PROJECT_VARNAME_LOWER) |
| 31 |
string(REGEX REPLACE "_+" "" META_PROJECT_VARNAME_LOWER "${META_PROJECT_VARNAME}") |
| 32 |
string(TOLOWER "${META_PROJECT_VARNAME_LOWER}" META_PROJECT_VARNAME_LOWER) |
| 33 |
endif () |
| 34 |
|
| 35 |
# allow setting a configuration name to allow installing multiple differently configured versions within the same prefix |
| 36 |
# (intended to be used for installing Qt 5 and Qt 6 version or shared and static version within the same prefix) |
| 37 |
set(${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_NAME |
| 38 |
"" |
| 39 |
CACHE STRING "sets the configuration name for ${META_PROJECT_NAME}") |
| 40 |
set(CONFIGURATION_NAME |
| 41 |
"" |
| 42 |
CACHE STRING "sets the configuration name for all projects within the current build") |
| 43 |
set(CONFIGURATION_DISPLAY_NAME |
| 44 |
"${CONFIGURATION_NAME}" |
| 45 |
CACHE STRING |
| 46 |
"sets the display name for the configuration; incorporated in META_APP_NAME; defaults to CONFIGURATION_NAME") |
| 47 |
if (${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_NAME STREQUAL "none") |
| 48 |
set(META_CONFIG_NAME "") |
| 49 |
elseif (${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_NAME) |
| 50 |
set(META_CONFIG_NAME "${${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_NAME}") |
| 51 |
else () |
| 52 |
set(META_CONFIG_NAME "${CONFIGURATION_NAME}") |
| 53 |
endif () |
| 54 |
if (META_CONFIG_NAME) |
| 55 |
set(META_CONFIG_SUFFIX "-${META_CONFIG_NAME}") |
| 56 |
endif () |
| 57 |
set(META_APP_BASE_NAME "${META_APP_NAME}") |
| 58 |
if (CONFIGURATION_DISPLAY_NAME) |
| 59 |
set(META_APP_NAME "${META_APP_NAME} (${CONFIGURATION_DISPLAY_NAME})") |
| 60 |
endif () |
| 61 |
|
| 62 |
set(NAMESPACE |
| 63 |
"" |
| 64 |
CACHE STRING "adds a prefix to files and folders installed in the OS toplevel") |
| 65 |
if (NAMESPACE) |
| 66 |
set(NAMESPACE_PREFIX "${NAMESPACE}-") |
| 67 |
set(TARGET_PREFIX "${NAMESPACE}-") |
| 68 |
endif () |
| 69 |
|
| 70 |
# allow setting a library/application target suffix - A different configuration name might not require a different target |
| 71 |
# name since it might differ anyways (e.g. library extensions for static and shared configuration). Hence there's not simply |
| 72 |
# the configuration name used to distinguish targets as well. |
| 73 |
if (NOT DEFINED ${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_TARGET_SUFFIX) |
| 74 |
# wrap this within "if (NOT DEFINED" so absence of a target suffix can be enforced within certain project files |
| 75 |
set(${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_TARGET_SUFFIX |
| 76 |
"" |
| 77 |
CACHE STRING "sets a target suffix for ${META_PROJECT_NAME}") |
| 78 |
endif () |
| 79 |
set(CONFIGURATION_TARGET_SUFFIX |
| 80 |
"" |
| 81 |
CACHE STRING "sets the target suffix for all projects within the current build") |
| 82 |
if (${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_TARGET_SUFFIX STREQUAL "none") |
| 83 |
set(TARGET_SUFFIX "") |
| 84 |
elseif (${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_TARGET_SUFFIX) |
| 85 |
set(TARGET_SUFFIX "-${${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_TARGET_SUFFIX}") |
| 86 |
elseif (CONFIGURATION_TARGET_SUFFIX) |
| 87 |
set(TARGET_SUFFIX "-${CONFIGURATION_TARGET_SUFFIX}") |
| 88 |
endif () |
| 89 |
|
| 90 |
# disable linking against default Qt plugins by default |
| 91 |
if (NOT DEFINED META_QT_DEFAULT_PLUGINS) |
| 92 |
# note: The CMake modules in qtutilities take care of linking against static plugins on their own because old Qt versions |
| 93 |
# did not provide any support and one had to do it manually. Considering that with Qt's default my projects end up |
| 94 |
# pulling in needlessly many plugins I prefer to keep my current approach and disable Qt's defaults. |
| 95 |
set(META_QT_DEFAULT_PLUGINS 0) # needs to be exactly 0, Qt's code uses STREQUAL 0 |
| 96 |
endif () |
| 97 |
|
| 98 |
include(DevelUtilities) |
| 99 |
|
| 100 |
# find standard installation directories - note: Allow overriding CMAKE_INSTALL_LIBDIR and LIB_INSTALL_DIR but don't use the |
| 101 |
# default from GNUInstallDirs (as an Arch Linux user this feels odd and I also want to avoid breaking existing build |
| 102 |
# scripts). |
| 103 |
set(LIB_INSTALL_DIR |
| 104 |
"lib" |
| 105 |
CACHE STRING "sets the directory to install libraries to (within the prefix)") |
| 106 |
set(CMAKE_INSTALL_LIBDIR |
| 107 |
"${LIB_INSTALL_DIR}" |
| 108 |
CACHE STRING "sets the directory to install libraries to (within the prefix)") |
| 109 |
include(GNUInstallDirs) |
| 110 |
|
| 111 |
# define a few variables |
| 112 |
set(META_TARGET_NAME "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}") |
| 113 |
set(META_DATA_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}") |
| 114 |
set(META_DATA_DIR_ABSOLUTE "${CMAKE_INSTALL_FULL_DATAROOTDIR}/${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}") |
| 115 |
string(TOUPPER "${CMAKE_BUILD_TYPE}" META_CURRENT_CONFIGURATION) |
| 116 |
|
| 117 |
# set META_GENERIC_NAME to META_APP_NAME if not specified explicitly |
| 118 |
if (NOT META_GENERIC_NAME) |
| 119 |
set(META_GENERIC_NAME "${META_APP_NAME}") |
| 120 |
endif () |
| 121 |
|
| 122 |
# set default CXX_STANDARD for all library, application and test targets |
| 123 |
if (NOT META_CXX_STANDARD) |
| 124 |
if (MSVC) |
| 125 |
set(META_CXX_STANDARD 20) # MSVC needs C++ 20 mode for designated initializers |
| 126 |
else () |
| 127 |
set(META_CXX_STANDARD 17) |
| 128 |
endif () |
| 129 |
endif () |
| 130 |
|
| 131 |
# set version to 0.0.0 if not specified explicitly |
| 132 |
if (NOT META_VERSION_MAJOR) |
| 133 |
set(META_VERSION_MAJOR 0) |
| 134 |
endif () |
| 135 |
if (NOT META_VERSION_MINOR) |
| 136 |
set(META_VERSION_MINOR 0) |
| 137 |
endif () |
| 138 |
if (NOT META_VERSION_PATCH) |
| 139 |
set(META_VERSION_PATCH 0) |
| 140 |
endif () |
| 141 |
|
| 142 |
# set META_ID to target name if not specified |
| 143 |
if (NOT META_ID) |
| 144 |
set(META_ID "${META_TARGET_NAME}") |
| 145 |
endif () |
| 146 |
|
| 147 |
# set VCS browser URL and bugtracker URL |
| 148 |
if (NOT META_APP_VCS_BROWSER_URL) |
| 149 |
set(META_APP_VCS_BROWSER_URL "${META_APP_URL}") |
| 150 |
endif () |
| 151 |
if (NOT META_APP_BUGTRACKER_URL) |
| 152 |
if (META_APP_VCS_BROWSER_URL MATCHES "https://(github.com|gitlab.com|.*/(gogs|gitea)|(gogs|gitea).*)/.*") |
| 153 |
set(META_APP_BUGTRACKER_URL "${META_APP_VCS_BROWSER_URL}/issues") |
| 154 |
else () |
| 155 |
set(META_APP_BUGTRACKER_URL "${META_APP_VCS_BROWSER_URL}") |
| 156 |
endif () |
| 157 |
endif () |
| 158 |
|
| 159 |
# determine license automatically from LICENSE file |
| 160 |
if (NOT META_PROJECT_LICENSE) |
| 161 |
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") |
| 162 |
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" META_PROJECT_LICENSE_FILE) |
| 163 |
elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE") |
| 164 |
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE" META_PROJECT_LICENSE_FILE) |
| 165 |
elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../LICENSE") |
| 166 |
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../../LICENSE" META_PROJECT_LICENSE_FILE) |
| 167 |
endif () |
| 168 |
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/README.md") |
| 169 |
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/README.md" META_PROJECT_README_FILE) |
| 170 |
elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../README.md") |
| 171 |
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../README.md" META_PROJECT_README_FILE) |
| 172 |
elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../README.md") |
| 173 |
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../../README.md" META_PROJECT_README_FILE) |
| 174 |
endif () |
| 175 |
if (META_PROJECT_LICENSE_FILE MATCHES "GNU GENERAL PUBLIC LICENSE.*Version ([1-9\\.]*)") |
| 176 |
set(META_PROJECT_LICENSE "GPL-${CMAKE_MATCH_1}") |
| 177 |
set(OR_LATER_REGEX "\\[${META_PROJECT_LICENSE}-or-later\\]\\(LICENSE\\)") |
| 178 |
if (NOT META_PROJECT_LICENSE MATCHES "\\.") |
| 179 |
set(META_PROJECT_LICENSE "${META_PROJECT_LICENSE}.0") |
| 180 |
endif () |
| 181 |
if (META_PROJECT_README_FILE MATCHES "${OR_LATER_REGEX}") |
| 182 |
set(META_PROJECT_LICENSE "${META_PROJECT_LICENSE}+") |
| 183 |
endif () |
| 184 |
elseif (META_PROJECT_LICENSE_FILE MATCHES "GNU LESSER GENERAL PUBLIC LICENSE.*Version ([1-9\\.]*)") |
| 185 |
set(META_PROJECT_LICENSE "LGPL-${CMAKE_MATCH_1}") |
| 186 |
elseif (META_PROJECT_LICENSE_FILE MATCHES "MIT License") |
| 187 |
set(META_PROJECT_LICENSE "MIT") |
| 188 |
elseif (META_PROJECT_LICENSE_FILE MATCHES "Mozilla Public License Version ([1-9\\.]*)") |
| 189 |
set(META_PROJECT_LICENSE "MPL-${CMAKE_MATCH_1}") |
| 190 |
else () |
| 191 |
message( |
| 192 |
WARNING |
| 193 |
"Unable to detect license of ${META_PROJECT_NAME}. Set META_PROJECT_LICENSE manually to silence this warning." |
| 194 |
) |
| 195 |
endif () |
| 196 |
endif () |
| 197 |
|
| 198 |
# determine RDNS automatically from other meta-data and allow override |
| 199 |
set(${META_PROJECT_VARNAME_UPPER}_RDNS_OVERRIDE |
| 200 |
"" |
| 201 |
CACHE STRING "overrides the RDNS used in AppStream meta-data files for ${META_PROJECT_NAME}") |
| 202 |
if (${META_PROJECT_VARNAME_UPPER}_RDNS_OVERRIDE) |
| 203 |
set(META_PROJECT_RDNS ${${META_PROJECT_VARNAME_UPPER}_RDNS_OVERRIDE}) |
| 204 |
endif () |
| 205 |
set(${META_PROJECT_VARNAME_UPPER}_DEVELOPER_ID_OVERRIDE |
| 206 |
"" |
| 207 |
CACHE STRING "overrides the developer ID used in AppStream meta-data files for ${META_PROJECT_NAME}") |
| 208 |
if (${META_PROJECT_VARNAME_UPPER}_DEVELOPER_ID_OVERRIDE) |
| 209 |
set(META_DEVELOPER_ID ${${META_PROJECT_VARNAME_UPPER}_DEVELOPER_ID_OVERRIDE}) |
| 210 |
endif () |
| 211 |
if (${META_PROJECT_VARNAME_UPPER}_RDNS_OVERRIDE OR ${META_PROJECT_VARNAME_UPPER}_DEVELOPER_ID_OVERRIDE) |
| 212 |
message( |
| 213 |
WARNING |
| 214 |
"Overriding the RDNS or developer ID is NOT recommended. This feature is only intended to ease " |
| 215 |
"transitioning when a change is required and to create alternative packaging for development and private use.") |
| 216 |
endif () |
| 217 |
if (NOT META_PROJECT_RDNS OR NOT META_DEVELOPER_ID) |
| 218 |
string(TOLOWER "${META_APP_AUTHOR}" META_APP_AUTHOR_LOWER) |
| 219 |
if (NOT META_PROJECT_RDNS_BASE) |
| 220 |
if (META_APP_URL MATCHES ".*github\\.(com|io).*") |
| 221 |
set(META_PROJECT_RDNS_BASE "io.github") # assume GitHub pages |
| 222 |
else () |
| 223 |
set(META_PROJECT_RDNS_BASE "org") |
| 224 |
endif () |
| 225 |
endif () |
| 226 |
set(META_PROJECT_RDNS "${META_PROJECT_RDNS_BASE}.${META_APP_AUTHOR_LOWER}.${META_PROJECT_NAME}${TARGET_SUFFIX}") |
| 227 |
endif () |
| 228 |
if (NOT META_DEVELOPER_ID) |
| 229 |
set(META_DEVELOPER_ID "${META_PROJECT_RDNS_BASE}.${META_APP_AUTHOR_LOWER}") |
| 230 |
endif () |
| 231 |
|
| 232 |
# provide variables for other projects built as part of the same subdirs project to access files from this project |
| 233 |
get_directory_property(HAS_PARENT PARENT_DIRECTORY) |
| 234 |
if (HAS_PARENT) |
| 235 |
set(${META_PROJECT_VARNAME_UPPER}_SOURCE_DIR |
| 236 |
"${CMAKE_CURRENT_SOURCE_DIR}" |
| 237 |
PARENT_SCOPE) |
| 238 |
set(${META_PROJECT_VARNAME_UPPER}_BINARY_DIR |
| 239 |
"${CMAKE_CURRENT_BINARY_DIR}" |
| 240 |
PARENT_SCOPE) |
| 241 |
set(${META_PROJECT_NAME}_DIR |
| 242 |
"${CMAKE_CURRENT_BINARY_DIR}" |
| 243 |
PARENT_SCOPE) |
| 244 |
set(RUNTIME_LIBRARY_PATH |
| 245 |
"${CMAKE_CURRENT_BINARY_DIR}" ${RUNTIME_LIBRARY_PATH} |
| 246 |
PARENT_SCOPE) |
| 247 |
endif () |
| 248 |
|
| 249 |
# determine version |
| 250 |
set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}) |
| 251 |
option( |
| 252 |
APPEND_GIT_REVISION |
| 253 |
"whether the build script should attempt to append the Git revision and latest commit to the version displayed via --help" |
| 254 |
ON) |
| 255 |
if (APPEND_GIT_REVISION AND (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git" OR EXISTS "${CMAKE_SOURCE_DIR}/.git")) |
| 256 |
find_program(GIT_BIN git) |
| 257 |
execute_process( |
| 258 |
COMMAND ${GIT_BIN} rev-list --count HEAD |
| 259 |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 260 |
OUTPUT_VARIABLE META_GIT_REV_COUNT) |
| 261 |
execute_process( |
| 262 |
COMMAND ${GIT_BIN} rev-parse --short HEAD |
| 263 |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 264 |
OUTPUT_VARIABLE META_GIT_LAST_COMMIT_ID) |
| 265 |
string(REPLACE "\n" "" META_GIT_REV_COUNT "${META_GIT_REV_COUNT}") |
| 266 |
string(REPLACE "\n" "" META_GIT_LAST_COMMIT_ID "${META_GIT_LAST_COMMIT_ID}") |
| 267 |
if (META_GIT_REV_COUNT AND META_GIT_LAST_COMMIT_ID) |
| 268 |
set(META_APP_VERSION ${META_APP_VERSION}-${META_GIT_REV_COUNT}.${META_GIT_LAST_COMMIT_ID}) |
| 269 |
endif () |
| 270 |
endif () |
| 271 |
|
| 272 |
# set TARGET_EXECUTABLE which is used to refer to the target executable at its installation location |
| 273 |
set(TARGET_EXECUTABLE "${CMAKE_INSTALL_FULL_BINDIR}/${META_TARGET_NAME}") |
| 274 |
|
| 275 |
# create header for feature detection (TODO: remove this in v6 as WriteCompilerDetectionHeader has been deprecated) |
| 276 |
if (META_FEATURES_FOR_COMPILER_DETECTION_HEADER) |
| 277 |
include(WriteCompilerDetectionHeader) |
| 278 |
write_compiler_detection_header( |
| 279 |
FILE "${CMAKE_CURRENT_BINARY_DIR}/resources/features.h" PREFIX "${META_PROJECT_VARNAME_UPPER}" |
| 280 |
COMPILERS GNU Clang AppleClang |
| 281 |
FEATURES ${META_FEATURES_FOR_COMPILER_DETECTION_HEADER}) |
| 282 |
endif () |
| 283 |
|
| 284 |
# disable new ABI |
| 285 |
option(FORCE_OLD_ABI "specifies whether usage of libstdc++'s old ABI should be forced" OFF) |
| 286 |
if (FORCE_OLD_ABI) |
| 287 |
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS _GLIBCXX_USE_CXX11_ABI=0) |
| 288 |
message(STATUS "Forcing usage of old CXX11-ABI of libstdc++ (has no effect when a different standard library is used).") |
| 289 |
else () |
| 290 |
message(STATUS "Using default CXX11-ABI (not forcing old CXX11-ABI of libstdc++).") |
| 291 |
endif () |
| 292 |
|
| 293 |
# enable debug-only code when doing a debug build |
| 294 |
if (CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 295 |
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS CPP_UTILITIES_DEBUG_BUILD) |
| 296 |
message(STATUS "Debug build enabled.") |
| 297 |
endif () |
| 298 |
|
| 299 |
# enable logging when option is set |
| 300 |
option(LOGGING_ENABLED "specifies whether logging is enabled" OFF) |
| 301 |
if (LOGGING_ENABLED) |
| 302 |
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS LOGGING_ENABLED) |
| 303 |
message(STATUS "Logging is enabled.") |
| 304 |
endif () |
| 305 |
|
| 306 |
# determine whether the project is a header-only library |
| 307 |
if (SRC_FILES |
| 308 |
OR GUI_SRC_FILES |
| 309 |
OR WIDGETS_SRC_FILES |
| 310 |
OR WIDGETS_UI_FILES |
| 311 |
OR QML_SRC_FILES |
| 312 |
OR RES_FILES) |
| 313 |
set(META_HEADER_ONLY_LIB NO) |
| 314 |
else () |
| 315 |
set(META_HEADER_ONLY_LIB YES) |
| 316 |
if ("${META_PROJECT_TYPE}" STREQUAL "application") |
| 317 |
message(FATAL_ERROR "Project ${META_PROJECT_NAME} is supposed to be an application but has only header files.") |
| 318 |
endif () |
| 319 |
message(STATUS "Project ${META_PROJECT_NAME} is header-only library.") |
| 320 |
endif () |
| 321 |
|
| 322 |
# ensure 3rdParty has been included to configure BUILD_SHARED_LIBS and STATIC_LINKAGE/STATIC_LIBRARY_LINKAGE |
| 323 |
include(3rdParty) |
| 324 |
|
| 325 |
# options for enabling/disabling Qt GUI (if available) |
| 326 |
if (WIDGETS_HEADER_FILES |
| 327 |
OR WIDGETS_SRC_FILES |
| 328 |
OR WIDGETS_UI_FILES |
| 329 |
OR META_HAS_WIDGETS_GUI) |
| 330 |
if (META_GUI_OPTIONAL OR META_WIDGETS_GUI_OPTIONAL) |
| 331 |
option(WIDGETS_GUI "enables/disables building the Qt Widgets GUI: yes (default) or no" ON) |
| 332 |
else () |
| 333 |
set(WIDGETS_GUI ON) |
| 334 |
endif () |
| 335 |
else () |
| 336 |
set(WIDGETS_GUI OFF) |
| 337 |
endif () |
| 338 |
if (QML_HEADER_FILES |
| 339 |
OR QML_SRC_FILES |
| 340 |
OR META_HAS_QUICK_GUI) |
| 341 |
if (META_GUI_OPTIONAL OR META_QUICK_GUI_OPTIONAL) |
| 342 |
option(QUICK_GUI "enables/disables building the Qt Quick GUI: yes (default) or no" ON) |
| 343 |
else () |
| 344 |
set(QUICK_GUI ON) |
| 345 |
endif () |
| 346 |
else () |
| 347 |
set(QUICK_GUI OFF) |
| 348 |
endif () |
| 349 |
|
| 350 |
# find coding style (use style from c++utilities if none included in own project dir) |
| 351 |
if (NOT META_NO_TIDY) |
| 352 |
set(CLANG_FORMAT_RULES "${CMAKE_CURRENT_SOURCE_DIR}/coding-style.clang-format") |
| 353 |
if (CPP_UTILITIES_SOURCE_DIR AND NOT EXISTS "${CLANG_FORMAT_RULES}") |
| 354 |
set(CLANG_FORMAT_RULES "${CPP_UTILITIES_SOURCE_DIR}/coding-style.clang-format") |
| 355 |
endif () |
| 356 |
if (NOT EXISTS "${CLANG_FORMAT_RULES}") |
| 357 |
set(CLANG_FORMAT_RULES "${CPP_UTILITIES_DATA_DIRS}/codingstyle.clang-format") |
| 358 |
endif () |
| 359 |
endif () |
| 360 |
|
| 361 |
# enable testing |
| 362 |
enable_testing() |
| 363 |
get_directory_property(HAS_PARENT PARENT_DIRECTORY) |
| 364 |
if (HAS_PARENT) |
| 365 |
message(STATUS "For the check target to work, it is required to call enable_testing() on the source directory root.") |
| 366 |
endif () |
| 367 |
|
| 368 |
# make finding testfiles in out-of-source-tree build more convenient by adding a reference to the source directory (not only |
| 369 |
# useful if there's a test target; this is for instance also used in mocked configuration of syncthingtray) -> add a file |
| 370 |
# called "srcdirref" to the build directory; this file contains the path of the sources so tests can easily find test files |
| 371 |
# contained in the source directory |
| 372 |
if (NOT META_SRCDIR_REFS) |
| 373 |
set(META_SRCDIR_REFS "${CMAKE_CURRENT_SOURCE_DIR}") |
| 374 |
endif () |
| 375 |
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/srcdirref" "${META_SRCDIR_REFS}") |
| 376 |
# -> ensure the directory "testfiles" exists in the build directory; tests of my projects use it by default to create working |
| 377 |
# copies of testfiles |
| 378 |
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/testfiles") |
| 379 |
|
| 380 |
# determine source files which might be passed to clang-format or clang-tidy |
| 381 |
set(FORMATABLE_FILES |
| 382 |
${HEADER_FILES} |
| 383 |
${SRC_FILES} |
| 384 |
${TEST_HEADER_FILES} |
| 385 |
${TEST_SRC_FILES} |
| 386 |
${GUI_HEADER_FILES} |
| 387 |
${GUI_SRC_FILES} |
| 388 |
${WIDGETS_HEADER_FILES} |
| 389 |
${WIDGETS_SRC_FILES} |
| 390 |
${QML_HEADER_FILES} |
| 391 |
${QML_SRC_FILES} |
| 392 |
${EXCLUDED_FILES}) |
| 393 |
if (QT_TESTS) |
| 394 |
foreach (QT_TEST ${QT_TESTS}) |
| 395 |
list(APPEND FORMATABLE_FILES "tests/${QT_TEST}.cpp") |
| 396 |
endforeach () |
| 397 |
endif () |
| 398 |
# only format C/C++ files (and not eg. QML files) |
| 399 |
if (FORMATABLE_FILES) |
| 400 |
list(FILTER FORMATABLE_FILES INCLUDE REGEX ".*\\.(c|cc|cpp|h|hh|hpp)") |
| 401 |
if (FORMATABLE_FILES AND META_TIDY_EXCLUDE_REGEX) |
| 402 |
list(FILTER FORMATABLE_FILES EXCLUDE REGEX "${META_TIDY_EXCLUDE_REGEX}") |
| 403 |
endif () |
| 404 |
endif () |
| 405 |
|
| 406 |
# determine source files which might be passed to cmake-format |
| 407 |
set(FORMATABLE_FILES_CMAKE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_MODULE_FILES}) |
| 408 |
|
| 409 |
# add command for symlinking clang-{format,tidy} rules so the tools can find it |
| 410 |
if (EXISTS "${CLANG_FORMAT_RULES}") |
| 411 |
add_custom_command( |
| 412 |
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/.clang-format" |
| 413 |
COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CLANG_FORMAT_RULES}" "${CMAKE_CURRENT_SOURCE_DIR}/.clang-format" |
| 414 |
COMMENT "Linking coding style from ${CLANG_FORMAT_RULES}") |
| 415 |
else () |
| 416 |
message(WARNING "Format rules for clang-format not found.") |
| 417 |
endif () |
| 418 |
|
| 419 |
# allow user to configure creation of tidy targets unless the project disables this via META_NO_TIDY |
| 420 |
if (NOT META_NO_TIDY) |
| 421 |
find_program(CLANG_FORMAT_BIN clang-format) |
| 422 |
find_program(CMAKE_FORMAT_BIN cmake-format) |
| 423 |
set(CLANG_FORMAT_ENABLED_DEFAULT OFF) |
| 424 |
set(CMAKE_FORMAT_ENABLED_DEFAULT OFF) |
| 425 |
if (CLANG_FORMAT_BIN) |
| 426 |
set(CLANG_FORMAT_ENABLED_DEFAULT ON) |
| 427 |
endif () |
| 428 |
if (CMAKE_FORMAT_BIN) |
| 429 |
set(CMAKE_FORMAT_ENABLED_DEFAULT ON) |
| 430 |
endif () |
| 431 |
set(TIDY_TESTS_ENABLED_DEFAULT OFF) |
| 432 |
if (ENABLE_DEVEL_DEFAULTS AND CLANG_FORMAT_ENABLED_DEFAULT) |
| 433 |
set(TIDY_TESTS_ENABLED_DEFAULT ON) |
| 434 |
endif () |
| 435 |
option(CLANG_FORMAT_ENABLED "enables creation of tidy target using clang-format" "${CLANG_FORMAT_ENABLED_DEFAULT}") |
| 436 |
option(CMAKE_FORMAT_ENABLED "enables creation of tidy target using cmake-format" "${CMAKE_FORMAT_ENABLED_DEFAULT}") |
| 437 |
option(TIDY_TESTS_ENABLED "enables tests for checking whether code is well-formatted using clang-format" |
| 438 |
"${TIDY_TESTS_ENABLED_DEFAULT}") |
| 439 |
endif () |
| 440 |
|
| 441 |
# add target for tidying with clang-format |
| 442 |
if (NOT META_NO_TIDY |
| 443 |
AND CLANG_FORMAT_ENABLED |
| 444 |
AND FORMATABLE_FILES |
| 445 |
AND EXISTS "${CLANG_FORMAT_RULES}") |
| 446 |
if (NOT CLANG_FORMAT_BIN) |
| 447 |
message(FATAL_ERROR "Unable to add tidy target; clang-format not found") |
| 448 |
endif () |
| 449 |
add_custom_target( |
| 450 |
"${META_TARGET_NAME}_tidy" |
| 451 |
COMMAND "${CLANG_FORMAT_BIN}" -style=file -i ${FORMATABLE_FILES} |
| 452 |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 453 |
COMMENT "Tidying ${META_PROJECT_NAME} sources using clang-format" |
| 454 |
DEPENDS "${FORMATABLE_FILES};${CMAKE_CURRENT_SOURCE_DIR}/.clang-format") |
| 455 |
if (NOT TARGET tidy) |
| 456 |
add_custom_target(tidy) |
| 457 |
endif () |
| 458 |
add_dependencies(tidy "${META_TARGET_NAME}_tidy") |
| 459 |
|
| 460 |
# also add a test to verify whether sources are tidy |
| 461 |
if (TIDY_TESTS_ENABLED) |
| 462 |
add_test( |
| 463 |
NAME "${META_TARGET_NAME}_tidy_test" |
| 464 |
COMMAND "${CLANG_FORMAT_BIN}" -output-replacements-xml -style=file ${FORMATABLE_FILES} |
| 465 |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") |
| 466 |
list(APPEND CHECK_TARGET_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/.clang-format") |
| 467 |
set_tests_properties( |
| 468 |
"${META_TARGET_NAME}_tidy_test" PROPERTIES FAIL_REGULAR_EXPRESSION "<replacement.*>.*</replacement>" |
| 469 |
REQUIRED_FILES "${CMAKE_CURRENT_SOURCE_DIR}/.clang-format") |
| 470 |
endif () |
| 471 |
endif () |
| 472 |
|
| 473 |
# add target for tidying with cmake-format |
| 474 |
if (NOT META_NO_TIDY |
| 475 |
AND CMAKE_FORMAT_ENABLED |
| 476 |
AND FORMATABLE_FILES_CMAKE) |
| 477 |
if (NOT CMAKE_FORMAT_BIN) |
| 478 |
message(FATAL_ERROR "Unable to add tidy target; cmake-format not found") |
| 479 |
endif () |
| 480 |
if (NOT META_CMAKE_FORMAT_OPTIONS) |
| 481 |
set(META_CMAKE_FORMAT_OPTIONS --tab-size=4 --separate-ctrl-name-with-space=True --line-width=125 --autosort=False) |
| 482 |
endif () |
| 483 |
set(CMAKE_FORMAT_COMMANDS) |
| 484 |
foreach (FILE_TO_FORMAT ${FORMATABLE_FILES_CMAKE}) |
| 485 |
list( |
| 486 |
APPEND |
| 487 |
CMAKE_FORMAT_COMMANDS |
| 488 |
COMMAND |
| 489 |
"${CMAKE_FORMAT_BIN}" |
| 490 |
--in-place |
| 491 |
${META_CMAKE_FORMAT_OPTIONS} |
| 492 |
"${FILE_TO_FORMAT}") |
| 493 |
endforeach () |
| 494 |
add_custom_target( |
| 495 |
"${META_TARGET_NAME}_cmake_tidy" |
| 496 |
${CMAKE_FORMAT_COMMANDS} |
| 497 |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 498 |
COMMENT "Tidying ${META_PROJECT_NAME} sources using cmake-format" |
| 499 |
DEPENDS "${FORMATABLE_FILES_CMAKE}") |
| 500 |
if (NOT TARGET tidy) |
| 501 |
add_custom_target(tidy) |
| 502 |
endif () |
| 503 |
add_dependencies(tidy "${META_TARGET_NAME}_cmake_tidy") |
| 504 |
endif () |
| 505 |
|
| 506 |
# add target for static code analysis using clang-tidy |
| 507 |
if (NOT META_NO_STATIC_ANALYSIS AND FORMATABLE_FILES) |
| 508 |
option(CLANG_TIDY_ENABLED "enables creation of static-check target using clang-tidy" "${ENABLE_DEVEL_DEFAULTS}") |
| 509 |
set(CLANG_TIDY_CHECKS |
| 510 |
"" |
| 511 |
CACHE STRING |
| 512 |
"-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,performance-*,portability-*,readability-*,android-*") |
| 513 |
if (CLANG_TIDY_ENABLED) |
| 514 |
find_program(CLANG_TIDY_BIN clang-tidy) |
| 515 |
if (NOT CLANG_TIDY_BIN) |
| 516 |
message(FATAL_ERROR "Unable to add tidy target; clang-tidy not found") |
| 517 |
endif () |
| 518 |
|
| 519 |
set(CLANG_TIDY_DEPENDS ${FORMATABLE_FILES}) |
| 520 |
|
| 521 |
# compose options for clang-tidy |
| 522 |
set(CLANG_TIDY_OPTIONS -checks="${CLANG_TIDY_CHECKS}" -header-filter="^${META_PROJECT_NAME}/") |
| 523 |
if (EXISTS "${CLANG_FORMAT_RULES}") |
| 524 |
list(APPEND CLANG_TIDY_OPTIONS "-format-style=file") |
| 525 |
list(APPEND CLANG_TIDY_DPENDS "${CMAKE_CURRENT_SOURCE_DIR}/.clang-format") |
| 526 |
endif () |
| 527 |
|
| 528 |
# compose CXX flags for clang-tidy |
| 529 |
set(CLANG_TIDY_CXX_FLAGS "") |
| 530 |
if (NOT META_HEADER_ONLY_LIB) |
| 531 |
# deduce flags from target, set c++ standard |
| 532 |
list(APPEND CLANG_TIDY_CXX_FLAGS "-std=c++$<TARGET_PROPERTY:${META_TARGET_NAME},CXX_STANDARD>") |
| 533 |
# add compile flags |
| 534 |
set(PROP "$<TARGET_PROPERTY:${META_TARGET_NAME},COMPILE_FLAGS>") |
| 535 |
list(APPEND CLANG_TIDY_CXX_FLAGS "$<$<BOOL:${PROP}>:$<JOIN:${PROP},$<SEMICOLON>>>") |
| 536 |
# add compile definitions |
| 537 |
set(PROP "$<TARGET_PROPERTY:${META_TARGET_NAME},COMPILE_DEFINITIONS>") |
| 538 |
list(APPEND CLANG_TIDY_CXX_FLAGS "$<$<BOOL:${PROP}>:-D$<JOIN:${PROP},$<SEMICOLON>-D>>") |
| 539 |
# add include directories |
| 540 |
set(PROP "$<TARGET_PROPERTY:${META_TARGET_NAME},INCLUDE_DIRECTORIES>") |
| 541 |
list(APPEND CLANG_TIDY_CXX_FLAGS "$<$<BOOL:${PROP}>:-I$<JOIN:${PROP},$<SEMICOLON>-I>>") |
| 542 |
else () |
| 543 |
# set at least c++ standard for header-only libs |
| 544 |
list(APPEND CLANG_TIDY_CXX_FLAGS "-std=c++${META_CXX_STANDARD}") |
| 545 |
endif () |
| 546 |
|
| 547 |
# add a custom command for each source file |
| 548 |
set(CLANG_TIDY_SYMBOLIC_OUTPUT_FILES "") |
| 549 |
foreach (FILE ${FORMATABLE_FILES}) |
| 550 |
# skip header files |
| 551 |
if (${FILE} MATCHES ".*\.h") |
| 552 |
continue() |
| 553 |
endif () |
| 554 |
|
| 555 |
# use symbolic output file since there's no actual output file (we're just interested in the log) |
| 556 |
set(SYMBOLIC_OUTPUT_FILE "${FILE}.clang-tidy-output") |
| 557 |
list(APPEND CLANG_TIDY_SYMBOLIC_OUTPUT_FILES "${SYMBOLIC_OUTPUT_FILE}") |
| 558 |
|
| 559 |
add_custom_command( |
| 560 |
OUTPUT "${SYMBOLIC_OUTPUT_FILE}" |
| 561 |
COMMAND "${CLANG_TIDY_BIN}" ${FILE} -- ${CLANG_TIDY_CXX_FLAGS} |
| 562 |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 563 |
COMMENT "Linting ${FILE} using clang-tidy" |
| 564 |
DEPENDS "${FILE}" |
| 565 |
COMMAND_EXPAND_LISTS VERBATIM) |
| 566 |
endforeach () |
| 567 |
|
| 568 |
# mark all symbolic output files actually as symbolic |
| 569 |
set_source_files_properties(${CLANG_TIDY_SYMBOLIC_OUTPUT_FILES} PROPERTIES SYMBOLIC YES) |
| 570 |
|
| 571 |
# add targets |
| 572 |
add_custom_target( |
| 573 |
"${META_TARGET_NAME}_static_check" |
| 574 |
DEPENDS ${CLANG_TIDY_SYMBOLIC_OUTPUT_FILES} |
| 575 |
COMMENT "Linting ${META_TARGET_NAME} sources using clang-tidy") |
| 576 |
if (NOT TARGET static-check) |
| 577 |
add_custom_target(static-check) |
| 578 |
endif () |
| 579 |
add_dependencies(static-check "${META_TARGET_NAME}_static_check") |
| 580 |
endif () |
| 581 |
endif () |
| 582 |
|
| 583 |
# add autotools-style check target |
| 584 |
if (NOT TARGET check) |
| 585 |
set(CMAKE_CTEST_COMMAND ${CMAKE_CTEST_COMMAND} -V) |
| 586 |
add_custom_target( |
| 587 |
check |
| 588 |
COMMAND ${CMAKE_CTEST_COMMAND} |
| 589 |
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
| 590 |
DEPENDS "${CHECK_TARGET_DEPENDS}" |
| 591 |
USES_TERMINAL) |
| 592 |
endif () |
| 593 |
|
| 594 |
# enable source code based coverage analysis using clang |
| 595 |
option(CLANG_SOURCE_BASED_COVERAGE_ENABLED "enables creation of coverage targets for source-based coverage with clang" OFF) |
| 596 |
if (CLANG_SOURCE_BASED_COVERAGE_ENABLED) |
| 597 |
if (NOT CMAKE_HOST_UNIX OR NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
| 598 |
message(FATAL_ERROR "Source-based coverage only available under UNIX with Clang") |
| 599 |
endif () |
| 600 |
set(CLANG_SOURCE_BASED_COVERAGE_AVAILABLE YES) |
| 601 |
set(CLANG_SOURCE_BASED_COVERAGE_FLAGS -fprofile-instr-generate -fcoverage-mapping) |
| 602 |
list(APPEND META_PRIVATE_COMPILE_OPTIONS ${CLANG_SOURCE_BASED_COVERAGE_FLAGS}) |
| 603 |
list(APPEND META_ADDITIONAL_LINK_FLAGS ${CLANG_SOURCE_BASED_COVERAGE_FLAGS}) |
| 604 |
endif () |
| 605 |
|
| 606 |
# enable coverage analysis with GCC and gcov |
| 607 |
option(GCOV_COVERAGE_ENABLED "enables creation of coverage targets utilizing gcov" OFF) |
| 608 |
if (GCOV_COVERAGE_ENABLED) |
| 609 |
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 610 |
message(FATAL_ERROR "gcov coverage only available under GCC, current compiler is ${CMAKE_CXX_COMPILER_ID}") |
| 611 |
endif () |
| 612 |
set(GCC_COVERAGE_AVAILABLE YES) |
| 613 |
set(GCC_COVERAGE_FLAGS --coverage -fprofile-arcs -ftest-coverage) |
| 614 |
list(APPEND META_PRIVATE_COMPILE_OPTIONS ${GCC_COVERAGE_FLAGS}) |
| 615 |
list(APPEND META_ADDITIONAL_LINK_FLAGS ${GCC_COVERAGE_FLAGS}) |
| 616 |
endif () |
| 617 |
|
| 618 |
# configure creation of install targets |
| 619 |
if (NOT META_NO_INSTALL_TARGETS) |
| 620 |
# install targets have not been disabled on project level check whether install targets are disabled by the user this |
| 621 |
# might be useful since install targets seem to cause problems under MacOS |
| 622 |
option(ENABLE_INSTALL_TARGETS "enables creation of install targets" ON) |
| 623 |
endif () |
| 624 |
|
| 625 |
# add install target for extra files |
| 626 |
if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS) |
| 627 |
foreach (EXTRA_FILE ${EXTRA_FILES}) |
| 628 |
get_filename_component(EXTRA_DIR ${EXTRA_FILE} DIRECTORY) |
| 629 |
install( |
| 630 |
FILES ${EXTRA_FILE} |
| 631 |
DESTINATION "${META_DATA_DIR}/${EXTRA_DIR}" |
| 632 |
COMPONENT extra-files) |
| 633 |
endforeach () |
| 634 |
if (NOT TARGET install-extra-files) |
| 635 |
add_custom_target(install-extra-files COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=extra-files -P |
| 636 |
"${CMAKE_BINARY_DIR}/cmake_install.cmake") |
| 637 |
endif () |
| 638 |
endif () |
| 639 |
|
| 640 |
# determine library directory suffix - Applications might be built as libraries under some platforms (eg. Android). Hence |
| 641 |
# this is part of BasicConfig and not LibraryTarget. |
| 642 |
set(LIB_SUFFIX |
| 643 |
"" |
| 644 |
CACHE STRING "specifies the general suffix for the library directory") |
| 645 |
set(SELECTED_LIB_SUFFIX "${LIB_SUFFIX}") |
| 646 |
set(LIB_SUFFIX_32 |
| 647 |
"" |
| 648 |
CACHE STRING "specifies the suffix for the library directory to be used when building 32-bit library") |
| 649 |
set(LIB_SUFFIX_64 |
| 650 |
"" |
| 651 |
CACHE STRING "specifies the suffix for the library directory to be used when building 64-bit library") |
| 652 |
if (LIB_SUFFIX_64 AND CMAKE_SIZEOF_VOID_P MATCHES "8") |
| 653 |
set(SELECTED_LIB_SUFFIX "${LIB_SUFFIX_64}") |
| 654 |
elseif (LIB_SUFFIX_32 AND CMAKE_SIZEOF_VOID_P MATCHES "4") |
| 655 |
set(SELECTED_LIB_SUFFIX "${LIB_SUFFIX_32}") |
| 656 |
endif () |
| 657 |
|
| 658 |
# ignore LIB_SUFFIX variables if CMAKE_INSTALL_LIBDIR ends with that suffix anyways (%cmake RPM macro apparently passes |
| 659 |
# LIB_SUFFIX and CMAKE_INSTALL_LIBDIR/LIB_INSTALL_DIR at the same time) |
| 660 |
if (CMAKE_INSTALL_LIBDIR MATCHES ".*${SELECTED_LIB_SUFFIX}$") |
| 661 |
set(SELECTED_LIB_SUFFIX "") |
| 662 |
endif () |
| 663 |
|
| 664 |
set(BIN_INSTALL_DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") |
| 665 |
set(LIB_INSTALL_DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}${SELECTED_LIB_SUFFIX}") |
| 666 |
|
| 667 |
# allow user to specify additional libraries to link against (see buildvariables.md for details) |
| 668 |
set(USER_DEFINED_ADDITIONAL_LIBRARIES |
| 669 |
"" |
| 670 |
CACHE STRING "specifies additional libraries to link against (added after any other libraries to the linker line)") |
| 671 |
function (append_user_defined_additional_libraries) |
| 672 |
if (NOT USER_DEFINED_ADDITIONAL_LIBRARIES) |
| 673 |
return() |
| 674 |
endif () |
| 675 |
|
| 676 |
# find the last library |
| 677 |
set(LIBS PRIVATE_LIBRARIES) |
| 678 |
list(LENGTH ${LIBS} LIB_COUNT) |
| 679 |
if (LIB_COUNT LESS_EQUAL 0) |
| 680 |
set(LIBS PUBLIC_LIBRARIES) |
| 681 |
list(LENGTH ${LIBS} LIB_COUNT) |
| 682 |
endif () |
| 683 |
if (LIB_COUNT LESS_EQUAL 0) |
| 684 |
# just add the additional libs to PRIVATE_LIBRARIES if there are no libs yet anyways |
| 685 |
set(PRIVATE_LIBRARIES |
| 686 |
"${USER_DEFINED_ADDITIONAL_LIBRARIES}" |
| 687 |
PARENT_SCOPE) |
| 688 |
endif () |
| 689 |
math(EXPR LAST_LIB_INDEX "${LIB_COUNT} - 1") |
| 690 |
list(GET ${LIBS} ${LAST_LIB_INDEX} LAST_LIB) |
| 691 |
|
| 692 |
# add the additional libs as INTERFACE_LINK_LIBRARIES of the last lib if it is a target |
| 693 |
if (TARGET "${LAST_LIB}") |
| 694 |
# note: Otherwise the INTERFACE_LINK_LIBRARIES of the last target might still come after the |
| 695 |
# USER_DEFINED_ADDITIONAL_LIBRARIES on the linker line. |
| 696 |
set_property( |
| 697 |
TARGET "${LAST_LIB}" |
| 698 |
APPEND |
| 699 |
PROPERTY INTERFACE_LINK_LIBRARIES ${USER_DEFINED_ADDITIONAL_LIBRARIES}) |
| 700 |
|
| 701 |
return() |
| 702 |
endif () |
| 703 |
|
| 704 |
# fall back to simply append the library to PRIVATE_LIBRARIES |
| 705 |
set(PRIVATE_LIBRARIES |
| 706 |
"${USER_DEFINED_ADDITIONAL_LIBRARIES}" |
| 707 |
PARENT_SCOPE) |
| 708 |
endfunction () |
| 709 |
|
| 710 |
# locate PNG icon which used for generating icons for the Windows executable and the macOS bundle |
| 711 |
if (PNG_ICON_PATH) |
| 712 |
if (NOT EXISTS "${PNG_ICON_PATH}") |
| 713 |
message(FATAL_ERROR "The specified PNG_ICON_PATH \"${PNG_ICON_PATH}\" is invalid.") |
| 714 |
endif () |
| 715 |
else () |
| 716 |
if (PNG_ICON_SIZE) |
| 717 |
set(PNG_ICON_SIZES_TO_TEST "${PNG_ICON_SIZE}") |
| 718 |
else () |
| 719 |
set(PNG_ICON_SIZES_TO_TEST 256 128 64 32 16) |
| 720 |
endif () |
| 721 |
foreach (POSSIBLE_PNG_ICON_SIZE ${PNG_ICON_SIZES_TO_TEST}) |
| 722 |
set(PNG_ICON_PATH |
| 723 |
"${CMAKE_CURRENT_SOURCE_DIR}/resources/icons/hicolor/${POSSIBLE_PNG_ICON_SIZE}x${POSSIBLE_PNG_ICON_SIZE}/apps/${META_PROJECT_NAME}.png" |
| 724 |
) |
| 725 |
if (EXISTS "${PNG_ICON_PATH}") |
| 726 |
set(PNG_ICON_SIZE "${POSSIBLE_PNG_ICON_SIZE}") |
| 727 |
message(STATUS "Using PNG icon from \"${PNG_ICON_PATH}\".") |
| 728 |
break() |
| 729 |
endif () |
| 730 |
unset(PNG_ICON_PATH) |
| 731 |
endforeach () |
| 732 |
endif () |
| 733 |
|
| 734 |
# configure warnings |
| 735 |
configure_development_warnings(APPEND_OUTPUT_VAR META_PRIVATE_COMPILE_OPTIONS) |
| 736 |
if (MSVC) |
| 737 |
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS _CRT_SECURE_NO_WARNINGS=1) |
| 738 |
endif () |
| 739 |
|
| 740 |
# add target to symlink compile_commands.json into source directory |
| 741 |
if (ENABLE_EXPORT_COMPILE_COMMANDS) |
| 742 |
set(COMPILE_COMMANDS_SOURCE "${CMAKE_BINARY_DIR}/compile_commands.json") |
| 743 |
set(COMPILE_COMMANDS_DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json") |
| 744 |
add_custom_command( |
| 745 |
OUTPUT "${COMPILE_COMMANDS_DESTINATION}" |
| 746 |
COMMAND "${CMAKE_COMMAND}" -E create_symlink "${COMPILE_COMMANDS_SOURCE}" "${COMPILE_COMMANDS_DESTINATION}" |
| 747 |
COMMENT "Linking compile_commands.json ${COMPILE_COMMANDS_DESTINATION}") |
| 748 |
add_custom_target( |
| 749 |
"${META_TARGET_NAME}_link_compile_commands" |
| 750 |
COMMENT "Linking compile_commands.json for ${META_PROJECT_NAME}" |
| 751 |
DEPENDS "${COMPILE_COMMANDS_DESTINATION}") |
| 752 |
if (NOT TARGET link_compile_commands) |
| 753 |
add_custom_target(link_compile_commands) |
| 754 |
endif () |
| 755 |
add_dependencies(link_compile_commands "${META_TARGET_NAME}_link_compile_commands") |
| 756 |
endif () |
| 757 |
|
| 758 |
set(BASIC_PROJECT_CONFIG_DONE YES) |