diff --git a/CMakeLists.txt b/CMakeLists.txt index 95d0a27f..1294249e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,7 @@ -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.29) + +# Disable modules support, this is broken with clang-tidy at the moment +cmake_policy(SET CMP0155 OLD) # This template attempts to be "fetch_content"-able # so that it works well with tools like CPM or other @@ -17,7 +20,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) # Set the project name and language project( myproject - VERSION 0.0.1 + VERSION 0.0.2 DESCRIPTION "" HOMEPAGE_URL "%%myurl%%" LANGUAGES CXX C) diff --git a/Dependencies.cmake b/Dependencies.cmake index e5008c4a..821366ac 100644 --- a/Dependencies.cmake +++ b/Dependencies.cmake @@ -9,7 +9,7 @@ function(myproject_setup_dependencies) # already been provided to us by a parent project if(NOT TARGET fmtlib::fmtlib) - cpmaddpackage("gh:fmtlib/fmt#11.1.4") + cpmaddpackage("gh:fmtlib/fmt#12.1.0") endif() if(NOT TARGET spdlog::spdlog) @@ -17,7 +17,7 @@ function(myproject_setup_dependencies) NAME spdlog VERSION - 1.15.2 + 1.17.0 GITHUB_REPOSITORY "gabime/spdlog" OPTIONS @@ -25,15 +25,15 @@ function(myproject_setup_dependencies) endif() if(NOT TARGET Catch2::Catch2WithMain) - cpmaddpackage("gh:catchorg/Catch2@3.8.1") + cpmaddpackage("gh:catchorg/Catch2@3.12.0") endif() if(NOT TARGET CLI11::CLI11) - cpmaddpackage("gh:CLIUtils/CLI11@2.5.0") + cpmaddpackage("gh:CLIUtils/CLI11@2.6.1") endif() if(NOT TARGET ftxui::screen) - cpmaddpackage("gh:ArthurSonzogni/FTXUI@6.0.2") + cpmaddpackage("gh:ArthurSonzogni/FTXUI@6.1.9") endif() if(NOT TARGET tools::tools) diff --git a/ProjectOptions.cmake b/ProjectOptions.cmake index fcd472bd..0d03d975 100644 --- a/ProjectOptions.cmake +++ b/ProjectOptions.cmake @@ -73,7 +73,6 @@ macro(myproject_setup_options) if(NOT PROJECT_IS_TOP_LEVEL OR myproject_PACKAGING_MAINTAINER_MODE) option(myproject_ENABLE_IPO "Enable IPO/LTO" OFF) option(myproject_WARNINGS_AS_ERRORS "Treat Warnings As Errors" OFF) - option(myproject_ENABLE_USER_LINKER "Enable user-selected linker" OFF) option(myproject_ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" OFF) option(myproject_ENABLE_SANITIZER_LEAK "Enable leak sanitizer" OFF) option(myproject_ENABLE_SANITIZER_UNDEFINED "Enable undefined sanitizer" OFF) @@ -87,7 +86,6 @@ macro(myproject_setup_options) else() option(myproject_ENABLE_IPO "Enable IPO/LTO" ON) option(myproject_WARNINGS_AS_ERRORS "Treat Warnings As Errors" ON) - option(myproject_ENABLE_USER_LINKER "Enable user-selected linker" OFF) option(myproject_ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" ${SUPPORTS_ASAN}) option(myproject_ENABLE_SANITIZER_LEAK "Enable leak sanitizer" OFF) option(myproject_ENABLE_SANITIZER_UNDEFINED "Enable undefined sanitizer" ${SUPPORTS_UBSAN}) @@ -104,7 +102,6 @@ macro(myproject_setup_options) mark_as_advanced( myproject_ENABLE_IPO myproject_WARNINGS_AS_ERRORS - myproject_ENABLE_USER_LINKER myproject_ENABLE_SANITIZER_ADDRESS myproject_ENABLE_SANITIZER_LEAK myproject_ENABLE_SANITIZER_UNDEFINED @@ -170,13 +167,10 @@ macro(myproject_local_options) "" "") - # Linker and sanitizers not supported in Emscripten - if(NOT EMSCRIPTEN) - if(myproject_ENABLE_USER_LINKER) - include(cmake/Linker.cmake) - myproject_configure_linker(myproject_options) - endif() + include(cmake/Linker.cmake) + # Must configure each target with linker options, we're avoiding setting it globally for now + if(NOT EMSCRIPTEN) include(cmake/Sanitizers.cmake) myproject_enable_sanitizers( myproject_options diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 9c27c51c..9a66dd83 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -2,8 +2,8 @@ # # SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors -set(CPM_DOWNLOAD_VERSION 0.40.8) -set(CPM_HASH_SUM "78ba32abdf798bc616bab7c73aac32a17bbd7b06ad9e26a6add69de8f3ae4791") +set(CPM_DOWNLOAD_VERSION 0.42.1) +set(CPM_HASH_SUM "f3a6dcc6a04ce9e7f51a127307fa4f699fb2bade357a8eb4c5b45df76e1dc6a5") if(CPM_SOURCE_CACHE) set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") diff --git a/cmake/Linker.cmake b/cmake/Linker.cmake index c1c19ebe..d5f10daa 100644 --- a/cmake/Linker.cmake +++ b/cmake/Linker.cmake @@ -1,31 +1,20 @@ macro(myproject_configure_linker project_name) - include(CheckCXXCompilerFlag) - - set(USER_LINKER_OPTION - "lld" + set(myproject_USER_LINKER_OPTION + "DEFAULT" CACHE STRING "Linker to be used") - set(USER_LINKER_OPTION_VALUES "lld" "gold" "bfd" "mold") - set_property(CACHE USER_LINKER_OPTION PROPERTY STRINGS ${USER_LINKER_OPTION_VALUES}) + set(myproject_USER_LINKER_OPTION_VALUES "DEFAULT" "SYSTEM" "LLD" "GOLD" "BFD" "MOLD" "SOLD" "APPLE_CLASSIC" "MSVC") + set_property(CACHE myproject_USER_LINKER_OPTION PROPERTY STRINGS ${myproject_USER_LINKER_OPTION_VALUES}) list( FIND - USER_LINKER_OPTION_VALUES - ${USER_LINKER_OPTION} - USER_LINKER_OPTION_INDEX) + myproject_USER_LINKER_OPTION_VALUES + ${myproject_USER_LINKER_OPTION} + myproject_USER_LINKER_OPTION_INDEX) - if(${USER_LINKER_OPTION_INDEX} EQUAL -1) + if(${myproject_USER_LINKER_OPTION_INDEX} EQUAL -1) message( STATUS - "Using custom linker: '${USER_LINKER_OPTION}', explicitly supported entries are ${USER_LINKER_OPTION_VALUES}") - endif() - - if(NOT myproject_ENABLE_USER_LINKER) - return() + "Using custom linker: '${myproject_USER_LINKER_OPTION}', explicitly supported entries are ${myproject_USER_LINKER_OPTION_VALUES}") endif() - set(LINKER_FLAG "-fuse-ld=${USER_LINKER_OPTION}") - - check_cxx_compiler_flag(${LINKER_FLAG} CXX_SUPPORTS_USER_LINKER) - if(CXX_SUPPORTS_USER_LINKER) - target_compile_options(${project_name} INTERFACE ${LINKER_FLAG}) - endif() + set_target_properties(${project_name} PROPERTIES LINKER_TYPE "${myproject_USER_LINKER_OPTION}") endmacro() diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index b9f4123e..aa193008 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -19,20 +19,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Enhance error reporting and compiler messages if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") - if(WIN32) - # On Windows cuda nvcc uses cl and not clang add_compile_options($<$:-fcolor-diagnostics> $<$:-fcolor-diagnostics>) - else() - add_compile_options(-fcolor-diagnostics) - endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if(WIN32) - # On Windows cuda nvcc uses cl and not gcc add_compile_options($<$:-fdiagnostics-color=always> $<$:-fdiagnostics-color=always>) - else() - add_compile_options(-fdiagnostics-color=always) - endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER 1900) add_compile_options(/diagnostics:column) else() @@ -42,4 +32,4 @@ endif() # run vcvarsall when msvc is used include("${CMAKE_CURRENT_LIST_DIR}/VCEnvironment.cmake") -run_vcvarsall() +myproject_run_vcvarsall() diff --git a/cmake/StaticAnalyzers.cmake b/cmake/StaticAnalyzers.cmake index 652c538e..37d43ee5 100644 --- a/cmake/StaticAnalyzers.cmake +++ b/cmake/StaticAnalyzers.cmake @@ -47,7 +47,7 @@ macro(myproject_enable_cppcheck WARNINGS_AS_ERRORS CPPCHECK_OPTIONS) list(APPEND CMAKE_CXX_CPPCHECK --error-exitcode=2) endif() else() - message(${WARNING_MESSAGE} "cppcheck requested but executable not found") + message(WARNING "cppcheck requested but executable not found") endif() endmacro() @@ -100,7 +100,7 @@ macro(myproject_enable_clang_tidy target WARNINGS_AS_ERRORS) message("Also setting clang-tidy globally") set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_OPTIONS}) else() - message(${WARNING_MESSAGE} "clang-tidy requested but executable not found") + message(WARNING "clang-tidy requested but executable not found") endif() endmacro() @@ -109,6 +109,6 @@ macro(myproject_enable_include_what_you_use) if(INCLUDE_WHAT_YOU_USE) set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${INCLUDE_WHAT_YOU_USE}) else() - message(${WARNING_MESSAGE} "include-what-you-use requested but executable not found") + message(WARNING "include-what-you-use requested but executable not found") endif() endmacro() diff --git a/cmake/Tests.cmake b/cmake/Tests.cmake index e20c7d49..a7f9b6e1 100644 --- a/cmake/Tests.cmake +++ b/cmake/Tests.cmake @@ -1,6 +1,6 @@ function(myproject_enable_coverage project_name) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") - target_compile_options(${project_name} INTERFACE --coverage -O0 -g) + target_compile_options(${project_name} INTERFACE --coverage -g) target_link_libraries(${project_name} INTERFACE --coverage) endif() endfunction() diff --git a/cmake/VCEnvironment.cmake b/cmake/VCEnvironment.cmake index 2ed4d582..e4934b1a 100644 --- a/cmake/VCEnvironment.cmake +++ b/cmake/VCEnvironment.cmake @@ -1,6 +1,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/Utilities.cmake") -macro(detect_architecture) +macro(myproject_detect_architecture) # detect the architecture string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" CMAKE_SYSTEM_PROCESSOR_LOWER) if(CMAKE_SYSTEM_PROCESSOR_LOWER STREQUAL x86 OR CMAKE_SYSTEM_PROCESSOR_LOWER MATCHES "^i[3456]86$") @@ -25,7 +25,7 @@ macro(detect_architecture) endmacro() # Run vcvarsall.bat and set CMake environment variables -function(run_vcvarsall) +function(myproject_run_vcvarsall) # if MSVC but VSCMD_VER is not set, which means vcvarsall has not run if(MSVC AND "$ENV{VSCMD_VER}" STREQUAL "") @@ -43,7 +43,7 @@ function(run_vcvarsall) if(EXISTS ${VCVARSALL_FILE}) # detect the architecture - detect_architecture() + myproject_detect_architecture() # run vcvarsall and print the environment variables message(STATUS "Running `${VCVARSALL_FILE} ${VCVARSALL_ARCH}` to set up the MSVC environment") diff --git a/fuzz_test/CMakeLists.txt b/fuzz_test/CMakeLists.txt index 7a392f57..722acb62 100644 --- a/fuzz_test/CMakeLists.txt +++ b/fuzz_test/CMakeLists.txt @@ -13,6 +13,9 @@ target_link_libraries( -fsanitize=fuzzer) target_compile_options(fuzz_tester PRIVATE -fsanitize=fuzzer) + +myproject_configure_linker(fuzz_tester) + # Allow short runs during automated testing to see if something new breaks set(FUZZ_RUNTIME 10 diff --git a/src/ftxui_sample/CMakeLists.txt b/src/ftxui_sample/CMakeLists.txt index 5ba9b564..fb4b93ad 100644 --- a/src/ftxui_sample/CMakeLists.txt +++ b/src/ftxui_sample/CMakeLists.txt @@ -16,6 +16,9 @@ target_link_system_libraries( ftxui::dom ftxui::component) + +myproject_configure_linker(intro) + target_include_directories(intro PRIVATE "${CMAKE_BINARY_DIR}/configured_files/include") # Apply WASM-specific configuration diff --git a/src/sample_library/CMakeLists.txt b/src/sample_library/CMakeLists.txt index 211e6fac..708bb8b2 100644 --- a/src/sample_library/CMakeLists.txt +++ b/src/sample_library/CMakeLists.txt @@ -19,6 +19,8 @@ endif() target_compile_features(sample_library PUBLIC cxx_std_${CMAKE_CXX_STANDARD}) +myproject_configure_linker(sample_library) + set_target_properties( sample_library PROPERTIES VERSION ${PROJECT_VERSION} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 50f8e633..8679286f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.15...3.23) -project(CmakeConfigPackageTests LANGUAGES CXX) +project(CmakeConfigPackageTests + VERSION ${PROJECT_VERSION} + LANGUAGES CXX) # ---- Test as standalone project the exported config package ---- @@ -37,6 +39,8 @@ target_link_libraries( myproject::sample_library Catch2::Catch2WithMain) +myproject_configure_linker(tests) + if(WIN32 AND BUILD_SHARED_LIBS) add_custom_command( TARGET tests @@ -69,6 +73,8 @@ target_link_libraries( myproject::sample_library Catch2::Catch2WithMain) +myproject_configure_linker(constexpr_tests) + catch_discover_tests( constexpr_tests TEST_PREFIX @@ -93,6 +99,9 @@ target_link_libraries( Catch2::Catch2WithMain) target_compile_definitions(relaxed_constexpr_tests PRIVATE -DCATCH_CONFIG_RUNTIME_STATIC_REQUIRE) +myproject_configure_linker(relaxed_constexpr_tests) + + catch_discover_tests( relaxed_constexpr_tests TEST_PREFIX