From bfe518b8022c5b7c6c3f2b78bf7230d018b7e186 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Wed, 2 Aug 2023 15:19:57 +0200 Subject: [PATCH 01/11] Prevent initialize git submodules aminya/project_options has an example as submodule this is not needed while build --- .cmake-format | 19 ++++++++++++++++++- CMakeLists.txt | 16 ++++++++++++---- GNUmakefile | 2 +- cmake/options.cmake | 22 ++++++++++++++++------ requirements.txt | 7 +++++-- 5 files changed, 52 insertions(+), 14 deletions(-) diff --git a/.cmake-format b/.cmake-format index b61459e..254d567 100644 --- a/.cmake-format +++ b/.cmake-format @@ -19,6 +19,7 @@ parse: GITHUB_REPOSITORY: 1 GITLAB_REPOSITORY: 1 GIT_REPOSITORY: 1 + GIT_MODULES: 1 SVN_REPOSITORY: 1 SVN_REVISION: 1 SOURCE_DIR: 1 @@ -56,11 +57,15 @@ parse: spelling: packageProject kwargs: NAME: 1 - VERSION: 1 INCLUDE_DIR: 1 INCLUDE_DESTINATION: 1 + INCLUDE_HEADER_PATTERN: 1 BINARY_DIR: 1 COMPATIBILITY: 1 + DISABLE_VERSION_SUFFIX: 1 + EXPORT_HEADER: 1 + NAMESPACE: 1 + VERSION: 1 VERSION_HEADER: 1 DEPENDENCIES: + cpmusepackagelock: @@ -72,3 +77,15 @@ parse: cpmgetpackageversion: pargs: 2 spelling: CPMGetPackageVersion + project_options: + pargs: + nargs: '*' + flags: [ENABLE_CACHE] + kwargs: + PREFIX: 1 + dynamic_project_options: + pargs: + nargs: '*' + flags: [ENABLE_CACHE] + kwargs: + PREFIX: 1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ce36de..6e7c5ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,12 +68,14 @@ include(DynamicProjectOptions) # sets `project_warnings` uncomment the options to enable them: # cmake-format: off dynamic_project_options( + PREFIX ${PROJECT_NAME} + ENABLE_CACHE # MSVC_WARNINGS "/permissive-" # Override the defaults for the MSVC warnings # CLANG_WARNINGS "-Wall;-Wextra" # Override the defaults for the CLANG warnings # GCC_WARNINGS "-Wextra" # Override the defaults for the GCC warnings ) # cmake-format: on -target_compile_features(project_options INTERFACE cxx_std_${CMAKE_CXX_STANDARD}) +target_compile_features(${PROJECT_NAME}_project_options INTERFACE cxx_std_${CMAKE_CXX_STANDARD}) # ---- Add source files ---- @@ -111,7 +113,10 @@ target_include_directories( ) if(CMAKE_SKIP_INSTALL_RULES OR CMAKE_BUILD_TYPE STREQUAL "Debug") - target_link_libraries(${PROJECT_NAME} PUBLIC $) + target_link_libraries( + ${PROJECT_NAME} PUBLIC $ + $ + ) return() endif() @@ -126,11 +131,14 @@ install(FILES test.cfg DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}) packageProject( NAME ${PROJECT_NAME} - VERSION ${PROJECT_VERSION} NAMESPACE ${PROJECT_NAME} + VERSION ${PROJECT_VERSION} + NAMESPACE ${PROJECT_NAME} BINARY_DIR ${PROJECT_BINARY_DIR} INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include INCLUDE_DESTINATION include/${PROJECT_NAME} - VERSION_HEADER ${VERSION_HEADER_LOCATION} DISABLE_VERSION_SUFFIX YES + VERSION_HEADER ${VERSION_HEADER_LOCATION} + EXPORT_HEADER ${PROJECT_NAME}/export.h + DISABLE_VERSION_SUFFIX YES COMPATIBILITY SameMajorVersion # TODO: DEPENDENCIES "fmt 10.0.0" ) diff --git a/GNUmakefile b/GNUmakefile index dea5f57..267c3ea 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -29,7 +29,7 @@ check: setup run-clang-tidy -extra-arg=-Wno-unknown-warning-option -p $(BUILD_DIR)/all source */source setup: - cd all && cmake --preset default --log-level=TRACE --trace-expand --trace-source=CPM.cmake + cd all && cmake --preset default --log-level=TRACE #XXX --trace-expand --trace-source=CPM.cmake #XXX perl -i.bak -p -e 's#-W[-\w]+(=\d)?\b##g;' \ #XXX -e 's#-I(${CPM_SOURCE_CACHE})#-isystem $$1#g;' $(BUILD_DIR)/all/compile_commands.json diff --git a/cmake/options.cmake b/cmake/options.cmake index 8163c3c..5b2af69 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -27,13 +27,23 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) -CPMAddPackage("gh:aminya/project_options@0.36.2") -list(APPEND CMAKE_MODULE_PATH ${project_options_SOURCE_DIR}/src) -include(StaticAnalyzers) # for target_disable_clang_tidy() and enable_clang_tidy() +cmake_policy(SET CMP0097 NEW) +CPMAddPackage( + NAME project_options + GIT_TAG v0.36.2 + GITHUB_REPOSITORY aminya/project_options + # XXX GIT_MODULES "examples/cpp_vcpkg_project" + GIT_MODULES "" + # NOTE(CK): should be empty to NOT initializes submodules! See policy CMP0097. +) +if(project_options_SOURCE_DIR) + list(APPEND CMAKE_MODULE_PATH ${project_options_SOURCE_DIR}/src) + include(StaticAnalyzers) # for target_disable_clang_tidy() and enable_clang_tidy() -if(OPT_ENABLE_CLANG_TIDY) - set(ProjectOptions_ENABLE_PCH OFF) - enable_clang_tidy("") + if(OPT_ENABLE_CLANG_TIDY) + set(ProjectOptions_ENABLE_PCH OFF) + enable_clang_tidy("") + endif() endif() # Disable clang-tidy for target diff --git a/requirements.txt b/requirements.txt index b961add..cd67d8d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,13 +6,16 @@ PyYAML>=5.4.1,<6.0 asyncio==3.4.3 -builddriver==0.9.0 +black>=22.12 +builddriver>=0.9.0 bumpversion>=0.6.0 cmake-format>=0.6.13 -cmake>=3.25 +cmake>=3.27 gcovr>=5.2 ninja>=1.11 +pylint>=2.17 pytest-asyncio==0.19.0 pytest==7.1.3 tftpy>=0.8.2 wheel>=0.37.1 +yamllint>=1.26 From 2421ee48c1c9b6d6f4471d7c65f1ca23049cf0cf Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Thu, 3 Aug 2023 13:18:32 +0200 Subject: [PATCH 02/11] Change cmake workflow presets a bit To reduce the buildtime, install doctest while test installed version at test subdirectory. --- CMakeLists.txt | 5 +---- all/CMakeLists.txt | 2 ++ cmake/options.cmake | 5 ++--- test/CMakeLists.txt | 8 +++++--- test/CMakePresets.json | 9 +++++++++ 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e7c5ea..0c1b495 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,10 +31,7 @@ include(GNUInstallDirs) # ---- local Options ---- -if(NOT PROJECT_IS_TOP_LEVEL) - message(WARNING "set(CMAKE_SKIP_INSTALL_RULES YES)") - option(CMAKE_SKIP_INSTALL_RULES "Whether to disable generation of installation rules" YES) -endif() +option(CMAKE_SKIP_INSTALL_RULES "Whether to disable generation of installation rules" NO) # --- Import project options ---- diff --git a/all/CMakeLists.txt b/all/CMakeLists.txt index bf888e4..a807462 100644 --- a/all/CMakeLists.txt +++ b/all/CMakeLists.txt @@ -7,6 +7,8 @@ project(BuildAll LANGUAGES CXX) # ---- local Options ---- +option(CMAKE_SKIP_INSTALL_RULES "Whether to disable generation of installation rules" YES) + # Note: by default ENABLE_DEVELOPER_MODE is True. This means that all analysis (sanitizers, static # analysis) is enabled and all warnings are treated as errors. if you want to switch this behavior, # change TRUE to FALSE diff --git a/cmake/options.cmake b/cmake/options.cmake index 5b2af69..ae4f8cc 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -32,9 +32,8 @@ CPMAddPackage( NAME project_options GIT_TAG v0.36.2 GITHUB_REPOSITORY aminya/project_options - # XXX GIT_MODULES "examples/cpp_vcpkg_project" - GIT_MODULES "" - # NOTE(CK): should be empty to NOT initializes submodules! See policy CMP0097. + # XXX GIT_SUBMODULES "examples/cpp_vcpkg_project" # See policy CMP0097. + GIT_SUBMODULES "" ) if(project_options_SOURCE_DIR) list(APPEND CMAKE_MODULE_PATH ${project_options_SOURCE_DIR}/src) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e045a92..fe3adc6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,7 +8,7 @@ project(GreeterTests LANGUAGES CXX) # ---- local Options ---- -option(TEST_INSTALLED_VERSION "Test the version found by find_package" OFF) +option(TEST_INSTALLED_VERSION "Test the version found by find_package" ${PROJECT_IS_TOP_LEVEL}) # --- Import project options ---- @@ -18,17 +18,19 @@ include(../cmake/options.cmake) CPMAddPackage("gh:TheLartians/Format.cmake@1.7.3") -# XXX CPMAddPackage("gh:doctest/doctest@2.4.9") +# NOTE: EXCLUDE_FROM_ALL must be OFF or doctest target will NOT be installed! CK CPMAddPackage( GITHUB_REPOSITORY "doctest/doctest" VERSION "2.4.11" + EXCLUDE_FROM_ALL OFF SYSTEM YES # used in case of cmake v3.25 + OPTIONS "DOCTEST_NO_INSTALL NO" ) if(TARGET doctest) target_disable_clang_tidy(doctest) endif() -if(TEST_INSTALLED_VERSION) # TODO(CK): or if(PROJECT_IS_TOP_LEVEL) +if(TEST_INSTALLED_VERSION) find_package(greeter 1.1 REQUIRED) message(TRACE "Found at ${Greeter_DIR}") else() diff --git a/test/CMakePresets.json b/test/CMakePresets.json index bebecae..8d96266 100644 --- a/test/CMakePresets.json +++ b/test/CMakePresets.json @@ -53,6 +53,11 @@ { "name": "default", "configurePreset": "default" + }, + { + "name": "install", + "configurePreset": "default", + "targets": ["install"] } ], "testPresets": [ @@ -87,6 +92,10 @@ { "type": "test", "name": "default" + }, + { + "type": "build", + "name": "install" } ] } From 31d6633d3a7eb2546cec0e062bb1b887e2941ece Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Thu, 3 Aug 2023 14:23:39 +0200 Subject: [PATCH 03/11] Prevent cmake warnings --- GNUmakefile | 4 ++-- all/CMakeLists.txt | 3 +++ all/CMakePresets.json | 3 +-- standalone/CMakeLists.txt | 15 ++++++++------- test/CMakeLists.txt | 3 ++- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 267c3ea..f0112d8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -18,7 +18,7 @@ BUILD_DIR:=$(shell realpath $(CURDIR)/build) .PHONY: setup all test gcov install lib_install test_install standalone documentation clean distclean check format all: install - cd all && cmake --preset default --debug-find-pkg=greeter + #XXX cd all && cmake --preset default --debug-find-pkg=greeter cd all && cmake --workflow --preset default test: setup @@ -29,7 +29,7 @@ check: setup run-clang-tidy -extra-arg=-Wno-unknown-warning-option -p $(BUILD_DIR)/all source */source setup: - cd all && cmake --preset default --log-level=TRACE #XXX --trace-expand --trace-source=CPM.cmake + cd all && cmake --preset default #XXX --log-level=TRACE --trace-expand --trace-source=CPM.cmake #XXX perl -i.bak -p -e 's#-W[-\w]+(=\d)?\b##g;' \ #XXX -e 's#-I(${CPM_SOURCE_CACHE})#-isystem $$1#g;' $(BUILD_DIR)/all/compile_commands.json diff --git a/all/CMakeLists.txt b/all/CMakeLists.txt index a807462..c955e0f 100644 --- a/all/CMakeLists.txt +++ b/all/CMakeLists.txt @@ -8,6 +8,9 @@ project(BuildAll LANGUAGES CXX) # ---- local Options ---- option(CMAKE_SKIP_INSTALL_RULES "Whether to disable generation of installation rules" YES) +if(CMAKE_SKIP_INSTALL_RULES) + message(WARNING "CMAKE_SKIP_INSTALL_RULES=YES") +endif() # Note: by default ENABLE_DEVELOPER_MODE is True. This means that all analysis (sanitizers, static # analysis) is enabled and all warnings are treated as errors. if you want to switch this behavior, diff --git a/all/CMakePresets.json b/all/CMakePresets.json index 193263e..08eb937 100644 --- a/all/CMakePresets.json +++ b/all/CMakePresets.json @@ -24,8 +24,7 @@ "CPM_USE_LOCAL_PACKAGES": "YES", "OPTION_ENABLE_UNITY": "NO", "OPTION_ENABLE_CLANG_TIDY": "YES", - "BUILD_SHARED_LIBS": "YES", - "ENABLE_TEST_COVERAGE": "YES" + "BUILD_SHARED_LIBS": "YES" }, "environment": { "CPM_USE_LOCAL_PACKAGES": "YES", diff --git a/standalone/CMakeLists.txt b/standalone/CMakeLists.txt index 9724243..13d315c 100644 --- a/standalone/CMakeLists.txt +++ b/standalone/CMakeLists.txt @@ -3,12 +3,9 @@ cmake_minimum_required(VERSION 3.21...3.31) project(GreeterStandalone LANGUAGES CXX) if(PROJECT_IS_TOP_LEVEL AND CMAKE_BUILD_TYPE STREQUAL "Release") - set(CMAKE_SKIP_INSTALL_RULES - NO - CACHE BOOL "Forced generation of installation rules" FORCE - ) -else() - message(WARNING "set(CMAKE_SKIP_INSTALL_RULES YES)") + option(CXXOPTS_ENABLE_INSTALL "install cxxopts" YES) +elseif(CMAKE_SKIP_INSTALL_RULES) + option(CXXOPTS_ENABLE_INSTALL "Install cxxopts" NO) endif() # --- Import project options ---- @@ -23,7 +20,7 @@ CPMAddPackage( VERSION 3.1.1 EXCLUDE_FROM_ALL NO SYSTEM YES # used in case of cmake v3.25 - OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES" + OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" ) if(TARGET cxxopts) target_disable_clang_tidy(cxxopts) @@ -57,6 +54,10 @@ add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME} --help) add_test(NAME ${PROJECT_NAME}-de COMMAND ${PROJECT_NAME} --lang=de) add_test(NAME ${PROJECT_NAME}-err COMMAND ${PROJECT_NAME} --lang=err) +if(CMAKE_SKIP_INSTALL_RULES) + return() +endif() + # --- Install it --- install(TARGETS ${PROJECT_NAME} RUNTIME) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fe3adc6..ea406fc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,6 +9,7 @@ project(GreeterTests LANGUAGES CXX) # ---- local Options ---- option(TEST_INSTALLED_VERSION "Test the version found by find_package" ${PROJECT_IS_TOP_LEVEL}) +option(CMAKE_SKIP_INSTALL_RULES "Whether to disable generation of installation rules" NO) # --- Import project options ---- @@ -24,7 +25,7 @@ CPMAddPackage( VERSION "2.4.11" EXCLUDE_FROM_ALL OFF SYSTEM YES # used in case of cmake v3.25 - OPTIONS "DOCTEST_NO_INSTALL NO" + OPTIONS "DOCTEST_NO_INSTALL ${CMAKE_SKIP_INSTALL_RULES}" ) if(TARGET doctest) target_disable_clang_tidy(doctest) From 6dfd9cc5429f26b27c1426228d17b1600845ec77 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Thu, 3 Aug 2023 15:34:16 +0200 Subject: [PATCH 04/11] Use workaround for GIT_SUBMODULES --- .cmake-format | 2 +- GNUmakefile | 2 +- cmake/options.cmake | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.cmake-format b/.cmake-format index 254d567..99a1a63 100644 --- a/.cmake-format +++ b/.cmake-format @@ -19,7 +19,7 @@ parse: GITHUB_REPOSITORY: 1 GITLAB_REPOSITORY: 1 GIT_REPOSITORY: 1 - GIT_MODULES: 1 + GIT_SUBMODULES: 1 SVN_REPOSITORY: 1 SVN_REVISION: 1 SOURCE_DIR: 1 diff --git a/GNUmakefile b/GNUmakefile index f0112d8..d56bdb0 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -29,7 +29,7 @@ check: setup run-clang-tidy -extra-arg=-Wno-unknown-warning-option -p $(BUILD_DIR)/all source */source setup: - cd all && cmake --preset default #XXX --log-level=TRACE --trace-expand --trace-source=CPM.cmake + cd all && cmake --preset default #XXX --log-level=TRACE --trace-expand --trace-source=CPM_0.38.2.cmake #XXX perl -i.bak -p -e 's#-W[-\w]+(=\d)?\b##g;' \ #XXX -e 's#-I(${CPM_SOURCE_CACHE})#-isystem $$1#g;' $(BUILD_DIR)/all/compile_commands.json diff --git a/cmake/options.cmake b/cmake/options.cmake index ae4f8cc..6adab6e 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -27,13 +27,15 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) +# NOTE(CK): Set GIT_SUBMODULES to empty string to NOT initializes submodules! cmake_policy(SET CMP0097 NEW) CPMAddPackage( NAME project_options GIT_TAG v0.36.2 GITHUB_REPOSITORY aminya/project_options - # XXX GIT_SUBMODULES "examples/cpp_vcpkg_project" # See policy CMP0097. - GIT_SUBMODULES "" + # FIXME: GIT_SUBMODULES "" + GIT_SUBMODULES "docs" + # NOTE(CK): Workaround existing dir to prevent load of submodule ) if(project_options_SOURCE_DIR) list(APPEND CMAKE_MODULE_PATH ${project_options_SOURCE_DIR}/src) From 66db29317efdb7795a7e0e96c515b5d23de9e4ca Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Thu, 3 Aug 2023 15:47:46 +0200 Subject: [PATCH 05/11] Fix CI build again --- test/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ea406fc..46c7fdf 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,7 +8,7 @@ project(GreeterTests LANGUAGES CXX) # ---- local Options ---- -option(TEST_INSTALLED_VERSION "Test the version found by find_package" ${PROJECT_IS_TOP_LEVEL}) +option(TEST_INSTALLED_VERSION "Test the version found by find_package" NO) option(CMAKE_SKIP_INSTALL_RULES "Whether to disable generation of installation rules" NO) # --- Import project options ---- @@ -31,7 +31,7 @@ if(TARGET doctest) target_disable_clang_tidy(doctest) endif() -if(TEST_INSTALLED_VERSION) +if(TEST_INSTALLED_VERSION) # TODO(CK): this breaks CI build! if(PROJECT_IS_TOP_LEVEL) find_package(greeter 1.1 REQUIRED) message(TRACE "Found at ${Greeter_DIR}") else() From 82c8507f3d730bab9ff5baab13b86092ef896e11 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Sun, 13 Aug 2023 19:47:01 +0200 Subject: [PATCH 06/11] Update cmake/options.cmake Co-authored-by: papperlapapp --- cmake/options.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/options.cmake b/cmake/options.cmake index 6adab6e..543c47f 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -27,7 +27,7 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) -# NOTE(CK): Set GIT_SUBMODULES to empty string to NOT initializes submodules! +# NOTE(CK): Set GIT_SUBMODULES to empty string to NOT initialize submodules! cmake_policy(SET CMP0097 NEW) CPMAddPackage( NAME project_options From ae7c934f9ea302e344037baabbd1b846e7d4bc30 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 4 Oct 2023 06:31:47 +0200 Subject: [PATCH 07/11] Set CMAKE_DEPFILE_FLAGS_CXX --- CMakeDefaultPresets.json | 7 +++++-- CMakeLists.txt | 4 ++-- cmake/options.cmake | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CMakeDefaultPresets.json b/CMakeDefaultPresets.json index f284035..e1e7200 100644 --- a/CMakeDefaultPresets.json +++ b/CMakeDefaultPresets.json @@ -1,8 +1,8 @@ { - "version": 6, + "version": 7, "cmakeMinimumRequired": { "major": 3, - "minor": 25, + "minor": 27, "patch": 0 }, "configurePresets": [ @@ -30,6 +30,9 @@ "warnings": { "deprecated": true, "uninitialized": false + }, + "trace": { + "mode": "off" } } ], diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c1b495..8410015 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,8 +105,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE $ - $ + ${PROJECT_NAME} PUBLIC $ + $ ) if(CMAKE_SKIP_INSTALL_RULES OR CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/cmake/options.cmake b/cmake/options.cmake index 543c47f..0257d75 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -9,6 +9,7 @@ endif() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_DEBUG_POSTFIX D) +set(CMAKE_DEPFILE_FLAGS_CXX "-MMD") option(OPTION_ENABLE_UNITY "Enable Unity builds of project" ON) option(OPTION_ENABLE_CLANG_TIDY "Enable clang-tdiy as prebuild step" OFF) From 8c3b2ee3ff533785f3acedc0772d0650696c428b Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Wed, 4 Oct 2023 15:11:59 +0200 Subject: [PATCH 08/11] Fix CMAKE_DEPFILE_FLAGS_CXX setup --- cmake/options.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/options.cmake b/cmake/options.cmake index 0257d75..1e56d47 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -9,7 +9,9 @@ endif() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_DEBUG_POSTFIX D) -set(CMAKE_DEPFILE_FLAGS_CXX "-MMD") +if(UNIX AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + set(CMAKE_DEPFILE_FLAGS_CXX "-MMD -MT -MF ") +endif() option(OPTION_ENABLE_UNITY "Enable Unity builds of project" ON) option(OPTION_ENABLE_CLANG_TIDY "Enable clang-tdiy as prebuild step" OFF) From 454f88738825f1af80fe72c58c48246389cb8d77 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 2 Feb 2024 13:14:05 +0100 Subject: [PATCH 09/11] make format --- .clang-format | 2 +- .envrc | 2 +- CMakePresets.json | 92 ++++++++--------- GNUmakefile | 2 + all/CMakePresets.json | 194 +++++++++++++++++----------------- include/greeter/greeter.h | 38 +++---- source/greeter.cpp | 22 ++-- standalone/CMakePresets.json | 195 ++++++++++++++++++----------------- standalone/source/main.cpp | 56 +++++----- test/CMakePresets.json | 191 +++++++++++++++++----------------- test/source/greeter.cpp | 12 +-- 11 files changed, 415 insertions(+), 391 deletions(-) diff --git a/.clang-format b/.clang-format index d6b24fe..92687f3 100644 --- a/.clang-format +++ b/.clang-format @@ -10,7 +10,7 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: 'true' IncludeBlocks: Regroup IndentPPDirectives: AfterHash - IndentWidth: '2' + IndentWidth: '4' NamespaceIndentation: All BreakBeforeBinaryOperators: All BreakBeforeTernaryOperators: 'true' diff --git a/.envrc b/.envrc index d0cccd3..8b6d75a 100644 --- a/.envrc +++ b/.envrc @@ -8,7 +8,7 @@ export CMAKE_EXPORT_COMPILE_COMMANDS=YES export CTEST_OUTPUT_ON_FAILURE=YES export CPM_USE_LOCAL_PACKAGES=YES -export CPM_SOURCE_CACHE=${PWD}/.cache/CPM +export CPM_SOURCE_CACHE=${HOME}/.cache/CPM export LD_LIBRARY_PATH=${CMAKE_PREFIX_PATH}/lib export BUILD_DIR=${PWD}/build diff --git a/CMakePresets.json b/CMakePresets.json index e09c3de..065f0ea 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,54 +1,54 @@ { - "version": 6, - "cmakeMinimumRequired": { - "major": 3, - "minor": 25, - "patch": 0 - }, - "include": [ - "CMakeDefaultPresets.json" - ], - "configurePresets": [ - { - "name": "ninja-multi", - "inherits": "default", - "displayName": "Ninja Multi-Config", - "description": "Default build using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config" + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 }, - { - "name": "windows-only", - "inherits": "default", - "displayName": "Windows-only configuration", - "description": "This build is only available on Windows", - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - } - ], - "workflowPresets": [ - { - "name": "default", - "steps": [ + "include": [ + "CMakeDefaultPresets.json" + ], + "configurePresets": [ { - "type": "configure", - "name": "default" + "name": "ninja-multi", + "inherits": "default", + "displayName": "Ninja Multi-Config", + "description": "Default build using Ninja Multi-Config generator", + "generator": "Ninja Multi-Config" }, { - "type": "build", - "name": "default" - }, - { - "type": "build", - "name": "install" - }, + "name": "windows-only", + "inherits": "default", + "displayName": "Windows-only configuration", + "description": "This build is only available on Windows", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "workflowPresets": [ { - "type": "package", - "name": "default" + "name": "default", + "steps": [ + { + "type": "configure", + "name": "default" + }, + { + "type": "build", + "name": "default" + }, + { + "type": "build", + "name": "install" + }, + { + "type": "package", + "name": "default" + } + ] } - ] - } - ] + ] } diff --git a/GNUmakefile b/GNUmakefile index d56bdb0..9761655 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -64,5 +64,7 @@ distclean: #XXX clean format: setup cmake --build $(BUILD_DIR)/all --target $@ + clang-format -i *.json */*.json + git-clang-format . ################################ diff --git a/all/CMakePresets.json b/all/CMakePresets.json index 08eb937..1490dcc 100644 --- a/all/CMakePresets.json +++ b/all/CMakePresets.json @@ -1,104 +1,112 @@ { - "version": 6, - "cmakeMinimumRequired": { - "major": 3, - "minor": 25, - "patch": 0 - }, - "configurePresets": [ - { - "name": "default", - "displayName": "Default develop all Config", - "description": "Default build using Ninja generator", - "generator": "Ninja", - "binaryDir": "${sourceParentDir}/build/all", - "installDir": "${sourceParentDir}/stagedir", - "cacheVariables": { - "CMAKE_PREFIX_PATH": { - "type": "path", - "value": "${sourceParentDir}/stagedir" - }, - "CMAKE_CXX_STANDARD": "20", - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_DEBUG_POSTFIX": "D", - "CPM_USE_LOCAL_PACKAGES": "YES", - "OPTION_ENABLE_UNITY": "NO", - "OPTION_ENABLE_CLANG_TIDY": "YES", - "BUILD_SHARED_LIBS": "YES" - }, - "environment": { - "CPM_USE_LOCAL_PACKAGES": "YES", - "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" - } - }, - { - "name": "ninja-multi", - "inherits": "default", - "displayName": "Ninja Multi-Config", - "description": "Default build using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config" - }, - { - "name": "windows-only", - "inherits": "default", - "displayName": "Windows-only configuration", - "description": "This build is only available on Windows", - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - } - ], - "buildPresets": [ - { - "name": "default", - "configurePreset": "default" + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 }, - { - "name": "format", - "configurePreset": "default", - "targets": ["fix-clang-format", "fix-cmake-format"] - } - ], - "testPresets": [ - { - "name": "default", - "configurePreset": "default", - "output": {"outputOnFailure": true}, - "execution": {"noTestsAction": "error", "stopOnFailure": true} - } - ], - "packagePresets": [ - { - "name": "default", - "configurePreset": "default", - "generators": [ - "TGZ" - ] - } - ], - "workflowPresets": [ - { - "name": "default", - "steps": [ + "configurePresets": [ { - "type": "configure", - "name": "default" + "name": "default", + "displayName": "Default develop all Config", + "description": "Default build using Ninja generator", + "generator": "Ninja", + "binaryDir": "${sourceParentDir}/build/all", + "installDir": "${sourceParentDir}/stagedir", + "cacheVariables": { + "CMAKE_PREFIX_PATH": { + "type": "path", + "value": "${sourceParentDir}/stagedir" + }, + "CMAKE_CXX_STANDARD": "20", + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_DEBUG_POSTFIX": "D", + "CPM_USE_LOCAL_PACKAGES": "YES", + "OPTION_ENABLE_UNITY": "NO", + "OPTION_ENABLE_CLANG_TIDY": "YES", + "BUILD_SHARED_LIBS": "YES" + }, + "environment": { + "CPM_USE_LOCAL_PACKAGES": "YES", + "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" + } }, { - "type": "build", - "name": "default" + "name": "ninja-multi", + "inherits": "default", + "displayName": "Ninja Multi-Config", + "description": "Default build using Ninja Multi-Config generator", + "generator": "Ninja Multi-Config" }, { - "type": "build", - "name": "format" + "name": "windows-only", + "inherits": "default", + "displayName": "Windows-only configuration", + "description": "This build is only available on Windows", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" }, { - "type": "test", - "name": "default" + "name": "format", + "configurePreset": "default", + "targets": [ + "fix-clang-format", + "fix-cmake-format" + ] + } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + } + ], + "packagePresets": [ + { + "name": "default", + "configurePreset": "default", + "generators": [ + "TGZ" + ] + } + ], + "workflowPresets": [ + { + "name": "default", + "steps": [ + { + "type": "configure", + "name": "default" + }, + { + "type": "build", + "name": "default" + }, + { + "type": "build", + "name": "format" + }, + { + "type": "test", + "name": "default" + } + ] } - ] - } - ] + ] } diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 77dfe3b..5f61c6a 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -4,28 +4,28 @@ namespace greeter { - /** Language codes to be used with the Greeter class */ - enum class LanguageCode { EN, DE, ES, FR }; + /** Language codes to be used with the Greeter class */ + enum class LanguageCode { EN, DE, ES, FR }; - /** - * @brief A class for saying hello in multiple languages - */ - class Greeter { - std::string name; - - public: /** - * @brief Creates a new greeter - * @param name the name to greet + * @brief A class for saying hello in multiple languages */ - Greeter(std::string name); + class Greeter { + std::string name; - /** - * @brief Creates a localized string containing the greeting - * @param lang the language to greet in - * @return a string containing the greeting - */ - std::string greet(LanguageCode lang = LanguageCode::EN) const; - }; + public: + /** + * @brief Creates a new greeter + * @param name the name to greet + */ + Greeter(std::string name); + + /** + * @brief Creates a localized string containing the greeting + * @param lang the language to greet in + * @return a string containing the greeting + */ + std::string greet(LanguageCode lang = LanguageCode::EN) const; + }; } // namespace greeter diff --git a/source/greeter.cpp b/source/greeter.cpp index a2a418e..baed3c8 100644 --- a/source/greeter.cpp +++ b/source/greeter.cpp @@ -7,15 +7,15 @@ using greeter::Greeter; Greeter::Greeter(std::string _name) : name(std::move(_name)) {} std::string Greeter::greet(LanguageCode lang) const { - switch (lang) { - default: - case LanguageCode::EN: - return fmt::format("Hello, {}!", name); - case LanguageCode::DE: - return fmt::format("Hallo {}!", name); - case LanguageCode::ES: - return fmt::format("¡Hola {}!", name); - case LanguageCode::FR: - return fmt::format("Bonjour {}!", name); - } + switch (lang) { + default: + case LanguageCode::EN: + return fmt::format("Hello, {}!", name); + case LanguageCode::DE: + return fmt::format("Hallo {}!", name); + case LanguageCode::ES: + return fmt::format("¡Hola {}!", name); + case LanguageCode::FR: + return fmt::format("Bonjour {}!", name); + } } diff --git a/standalone/CMakePresets.json b/standalone/CMakePresets.json index d104bde..335497f 100644 --- a/standalone/CMakePresets.json +++ b/standalone/CMakePresets.json @@ -1,106 +1,113 @@ { - "version": 6, - "cmakeMinimumRequired": { - "major": 3, - "minor": 25, - "patch": 0 - }, - "configurePresets": [ - { - "name": "default", - "displayName": "Default standalone Config", - "description": "Default build using Ninja generator", - "generator": "Ninja", - "binaryDir": "${sourceParentDir}/build/standalone", - "installDir": "${sourceParentDir}/stagedir", - "cacheVariables": { - "CMAKE_PREFIX_PATH": { - "type": "path", - "value": "${sourceParentDir}/stagedir" - }, - "CMAKE_CXX_STANDARD": "20", - "CMAKE_BUILD_TYPE": "Release", - "CMAKE_DEBUG_POSTFIX": "D", - "CPM_USE_LOCAL_PACKAGES": "YES", - "BUILD_SHARED_LIBS": "YES" - }, - "environment": { - "CPM_USE_LOCAL_PACKAGES": "YES", - "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" - } - }, - { - "name": "ninja-multi", - "inherits": "default", - "displayName": "Ninja Multi-Config", - "description": "Default build using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config" - }, - { - "name": "windows-only", - "inherits": "default", - "displayName": "Windows-only configuration", - "description": "This build is only available on Windows", - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - } - ], - "buildPresets": [ - { - "name": "default", - "configurePreset": "default" + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 }, - { - "name": "install", - "configurePreset": "default", - "targets": ["install"] - } - ], - "testPresets": [ - { - "name": "default", - "configurePreset": "default", - "output": {"outputOnFailure": true}, - "execution": {"noTestsAction": "error", "stopOnFailure": true} - } - ], - "packagePresets": [ - { - "name": "default", - "configurePreset": "default", - "generators": [ - "TGZ" - ] - } - ], - "workflowPresets": [ - { - "name": "default", - "steps": [ + "configurePresets": [ { - "type": "configure", - "name": "default" + "name": "default", + "displayName": "Default standalone Config", + "description": "Default build using Ninja generator", + "generator": "Ninja", + "binaryDir": "${sourceParentDir}/build/standalone", + "installDir": "${sourceParentDir}/stagedir", + "cacheVariables": { + "CMAKE_PREFIX_PATH": { + "type": "path", + "value": "${sourceParentDir}/stagedir" + }, + "CMAKE_CXX_STANDARD": "20", + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_DEBUG_POSTFIX": "D", + "CPM_USE_LOCAL_PACKAGES": "YES", + "BUILD_SHARED_LIBS": "YES" + }, + "environment": { + "CPM_USE_LOCAL_PACKAGES": "YES", + "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" + } }, { - "type": "build", - "name": "default" + "name": "ninja-multi", + "inherits": "default", + "displayName": "Ninja Multi-Config", + "description": "Default build using Ninja Multi-Config generator", + "generator": "Ninja Multi-Config" }, { - "type": "test", - "name": "default" - }, + "name": "windows-only", + "inherits": "default", + "displayName": "Windows-only configuration", + "description": "This build is only available on Windows", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "buildPresets": [ { - "type": "build", - "name": "install" + "name": "default", + "configurePreset": "default" }, { - "type": "package", - "name": "default" + "name": "install", + "configurePreset": "default", + "targets": [ + "install" + ] + } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + } + ], + "packagePresets": [ + { + "name": "default", + "configurePreset": "default", + "generators": [ + "TGZ" + ] + } + ], + "workflowPresets": [ + { + "name": "default", + "steps": [ + { + "type": "configure", + "name": "default" + }, + { + "type": "build", + "name": "default" + }, + { + "type": "test", + "name": "default" + }, + { + "type": "build", + "name": "install" + }, + { + "type": "package", + "name": "default" + } + ] } - ] - } - ] + ] } diff --git a/standalone/source/main.cpp b/standalone/source/main.cpp index 0c5ef8e..206f465 100644 --- a/standalone/source/main.cpp +++ b/standalone/source/main.cpp @@ -7,47 +7,47 @@ #include auto main(int argc, char** argv) -> int { - const std::unordered_map languages{ - {"en", greeter::LanguageCode::EN}, - {"de", greeter::LanguageCode::DE}, - {"es", greeter::LanguageCode::ES}, - {"fr", greeter::LanguageCode::FR}, - }; + const std::unordered_map languages{ + {"en", greeter::LanguageCode::EN}, + {"de", greeter::LanguageCode::DE}, + {"es", greeter::LanguageCode::ES}, + {"fr", greeter::LanguageCode::FR}, + }; - cxxopts::Options options(*argv, "A program to welcome the world!"); + cxxopts::Options options(*argv, "A program to welcome the world!"); - std::string language; - std::string name; + std::string language; + std::string name; - // clang-format off + // clang-format off options.add_options() ("h,help", "Show help") // ("v,version", "Print the current version number") ("n,name", "Name to greet", cxxopts::value(name)->default_value("World")) ("l,lang", "Language code to use", cxxopts::value(language)->default_value("en")) ; - // clang-format on + // clang-format on - auto result = options.parse(argc, argv); + auto result = options.parse(argc, argv); - if (result["help"].as()) { - std::cout << options.help() << std::endl; - return 0; - } + if (result["help"].as()) { + std::cout << options.help() << std::endl; + return 0; + } - // if (result["version"].as()) { - // std::cout << "Greeter, version " << GREETER_VERSION << std::endl; - // return 0; - // } + // if (result["version"].as()) { + // std::cout << "Greeter, version " << GREETER_VERSION << std::endl; + // return 0; + // } - auto langIt = languages.find(language); - if (langIt == languages.end()) { - std::cerr << "unknown language code: " << language << std::endl; - return 0; - } + auto langIt = languages.find(language); + if (langIt == languages.end()) { + std::cerr << "unknown language code: " << language << std::endl; + return 0; + } - greeter::Greeter greeter(name); - std::cout << greeter.greet(langIt->second) << std::endl; + greeter::Greeter greeter(name); + std::cout << greeter.greet(langIt->second) << std::endl; - return 0; + return 0; } diff --git a/test/CMakePresets.json b/test/CMakePresets.json index 8d96266..3b34adb 100644 --- a/test/CMakePresets.json +++ b/test/CMakePresets.json @@ -1,103 +1,110 @@ { - "version": 6, - "cmakeMinimumRequired": { - "major": 3, - "minor": 25, - "patch": 0 - }, - "configurePresets": [ - { - "name": "default", - "displayName": "Default develop test Config", - "description": "Default build using Ninja generator", - "generator": "Ninja", - "binaryDir": "${sourceParentDir}/build/test", - "installDir": "${sourceParentDir}/stagedir", - "cacheVariables": { - "CMAKE_PREFIX_PATH": { - "type": "path", - "value": "${sourceParentDir}/stagedir" - }, - "CMAKE_CXX_STANDARD": "20", - "CMAKE_BUILD_TYPE": "Release", - "CMAKE_DEBUG_POSTFIX": "D", - "CPM_USE_LOCAL_PACKAGES": "NO", - "BUILD_SHARED_LIBS": "YES", - "TEST_INSTALLED_VERSION": "YES" - }, - "environment": { - "CPM_USE_LOCAL_PACKAGES": "YES", - "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" - } - }, - { - "name": "ninja-multi", - "inherits": "default", - "displayName": "Ninja Multi-Config", - "description": "Default build using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config" - }, - { - "name": "windows-only", - "inherits": "default", - "displayName": "Windows-only configuration", - "description": "This build is only available on Windows", - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - } - ], - "buildPresets": [ - { - "name": "default", - "configurePreset": "default" + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 }, - { - "name": "install", - "configurePreset": "default", - "targets": ["install"] - } - ], - "testPresets": [ - { - "name": "default", - "configurePreset": "default", - "output": {"outputOnFailure": true}, - "execution": {"noTestsAction": "error", "stopOnFailure": true} - } - ], - "packagePresets": [ - { - "name": "default", - "configurePreset": "default", - "generators": [ - "TGZ" - ] - } - ], - "workflowPresets": [ - { - "name": "default", - "steps": [ + "configurePresets": [ { - "type": "configure", - "name": "default" + "name": "default", + "displayName": "Default develop test Config", + "description": "Default build using Ninja generator", + "generator": "Ninja", + "binaryDir": "${sourceParentDir}/build/test", + "installDir": "${sourceParentDir}/stagedir", + "cacheVariables": { + "CMAKE_PREFIX_PATH": { + "type": "path", + "value": "${sourceParentDir}/stagedir" + }, + "CMAKE_CXX_STANDARD": "20", + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_DEBUG_POSTFIX": "D", + "CPM_USE_LOCAL_PACKAGES": "NO", + "BUILD_SHARED_LIBS": "YES", + "TEST_INSTALLED_VERSION": "YES" + }, + "environment": { + "CPM_USE_LOCAL_PACKAGES": "YES", + "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" + } }, { - "type": "build", - "name": "default" + "name": "ninja-multi", + "inherits": "default", + "displayName": "Ninja Multi-Config", + "description": "Default build using Ninja Multi-Config generator", + "generator": "Ninja Multi-Config" }, { - "type": "test", - "name": "default" + "name": "windows-only", + "inherits": "default", + "displayName": "Windows-only configuration", + "description": "This build is only available on Windows", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" }, { - "type": "build", - "name": "install" + "name": "install", + "configurePreset": "default", + "targets": [ + "install" + ] + } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + } + ], + "packagePresets": [ + { + "name": "default", + "configurePreset": "default", + "generators": [ + "TGZ" + ] + } + ], + "workflowPresets": [ + { + "name": "default", + "steps": [ + { + "type": "configure", + "name": "default" + }, + { + "type": "build", + "name": "default" + }, + { + "type": "test", + "name": "default" + }, + { + "type": "build", + "name": "install" + } + ] } - ] - } - ] + ] } diff --git a/test/source/greeter.cpp b/test/source/greeter.cpp index a6ca649..a0400e5 100644 --- a/test/source/greeter.cpp +++ b/test/source/greeter.cpp @@ -5,14 +5,14 @@ #include TEST_CASE("Greeter") { - using namespace greeter; + using namespace greeter; - Greeter greeter("Tests"); + Greeter greeter("Tests"); - CHECK(greeter.greet(LanguageCode::EN) == "Hello, Tests!"); - CHECK(greeter.greet(LanguageCode::DE) == "Hallo Tests!"); - CHECK(greeter.greet(LanguageCode::ES) == "¡Hola Tests!"); - CHECK(greeter.greet(LanguageCode::FR) == "Bonjour Tests!"); + CHECK(greeter.greet(LanguageCode::EN) == "Hello, Tests!"); + CHECK(greeter.greet(LanguageCode::DE) == "Hallo Tests!"); + CHECK(greeter.greet(LanguageCode::ES) == "¡Hola Tests!"); + CHECK(greeter.greet(LanguageCode::FR) == "Bonjour Tests!"); } // TEST_CASE("Greeter version") { From d1cfe97505d5d5c887f280a8367a909dc7a4657c Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 13 Dec 2024 08:09:38 +0100 Subject: [PATCH 10/11] Apply changes requested in review --- include/greeter/greeter.h | 2 +- source/greeter.cpp | 2 +- standalone/source/main.cpp | 12 ++++++------ test/source/greeter.cpp | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 5f61c6a..783ac39 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -18,7 +18,7 @@ namespace greeter { * @brief Creates a new greeter * @param name the name to greet */ - Greeter(std::string name); + explicit Greeter(std::string name); /** * @brief Creates a localized string containing the greeting diff --git a/source/greeter.cpp b/source/greeter.cpp index baed3c8..74216e2 100644 --- a/source/greeter.cpp +++ b/source/greeter.cpp @@ -6,7 +6,7 @@ using greeter::Greeter; Greeter::Greeter(std::string _name) : name(std::move(_name)) {} -std::string Greeter::greet(LanguageCode lang) const { +[[nodiscard]] std::string Greeter::greet(LanguageCode lang) const { switch (lang) { default: case LanguageCode::EN: diff --git a/standalone/source/main.cpp b/standalone/source/main.cpp index 206f465..d0606a4 100644 --- a/standalone/source/main.cpp +++ b/standalone/source/main.cpp @@ -20,12 +20,12 @@ auto main(int argc, char** argv) -> int { std::string name; // clang-format off - options.add_options() - ("h,help", "Show help") - // ("v,version", "Print the current version number") - ("n,name", "Name to greet", cxxopts::value(name)->default_value("World")) - ("l,lang", "Language code to use", cxxopts::value(language)->default_value("en")) - ; + options.add_options() + ("h,help", "Show help") + // ("v,version", "Print the current version number") + ("n,name", "Name to greet", cxxopts::value(name)->default_value("World")) + ("l,lang", "Language code to use", cxxopts::value(language)->default_value("en")) + ; // clang-format on auto result = options.parse(argc, argv); diff --git a/test/source/greeter.cpp b/test/source/greeter.cpp index a0400e5..656c894 100644 --- a/test/source/greeter.cpp +++ b/test/source/greeter.cpp @@ -5,7 +5,8 @@ #include TEST_CASE("Greeter") { - using namespace greeter; + using greeter::Greeter; + using greeter::LanguageCode; Greeter greeter("Tests"); From 839b4a908a9a464307ab3c0e39b96bb2f5c23d19 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 13 Dec 2024 10:45:28 +0100 Subject: [PATCH 11/11] Fix most clang-tidy warnings --- .clang-format | 5 +- CMakeDefaultPresets.json | 21 +++- CMakeLists.txt | 2 +- CMakePresets.json | 92 ++++++++-------- GNUmakefile | 9 +- README.md | 6 +- all/CMakePresets.json | 202 +++++++++++++++++------------------ include/greeter/greeter.h | 5 +- standalone/CMakeLists.txt | 4 +- standalone/CMakePresets.json | 202 +++++++++++++++++------------------ standalone/source/main.cpp | 11 +- test/CMakeLists.txt | 2 +- test/CMakePresets.json | 198 +++++++++++++++++----------------- test/source/greeter.cpp | 2 +- 14 files changed, 392 insertions(+), 369 deletions(-) diff --git a/.clang-format b/.clang-format index 92687f3..6334d6b 100644 --- a/.clang-format +++ b/.clang-format @@ -1,6 +1,9 @@ --- - # clang-format v12.0.0 + # clang-format v12.0.0 or newer BasedOnStyle: Google + IndentWidth: '2' +--- + Language: Cpp AccessModifierOffset: '-2' AlignTrailingComments: 'true' AllowAllParametersOfDeclarationOnNextLine: 'false' diff --git a/CMakeDefaultPresets.json b/CMakeDefaultPresets.json index e1e7200..173e2e9 100644 --- a/CMakeDefaultPresets.json +++ b/CMakeDefaultPresets.json @@ -21,7 +21,8 @@ "CMAKE_CXX_STANDARD": "20", "CMAKE_BUILD_TYPE": "Release", "CMAKE_DEBUG_POSTFIX": "D", - "BUILD_SHARED_LIBS": "NO" + "OPTION_ENABLE_UNITY": true, + "BUILD_SHARED_LIBS": false }, "environment": { "CPM_USE_LOCAL_PACKAGES": "YES", @@ -44,20 +45,30 @@ { "name": "install", "configurePreset": "default", - "targets": ["install"] + "targets": [ + "install" + ] }, { "name": "format", "configurePreset": "default", - "targets": ["fix-clang-format", "fix-cmake-format"] + "targets": [ + "fix-clang-format", + "fix-cmake-format" + ] } ], "testPresets": [ { "name": "default", "configurePreset": "default", - "output": {"outputOnFailure": true}, - "execution": {"noTestsAction": "error", "stopOnFailure": true} + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } } ], "packagePresets": [ diff --git a/CMakeLists.txt b/CMakeLists.txt index 8410015..4a2bdb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES UNITY_BUILD ${OPTION_ENABLE_UNI # being a cross-platform target, we enforce standards conformance on MSVC target_compile_options(${PROJECT_NAME} PRIVATE "$<$:/permissive->") -target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) # mimimum requierd for package user +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) # minimum required for package user # Link dependencies target_link_libraries(${PROJECT_NAME} PRIVATE $) diff --git a/CMakePresets.json b/CMakePresets.json index 065f0ea..e09c3de 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,54 +1,54 @@ { - "version": 6, - "cmakeMinimumRequired": { - "major": 3, - "minor": 25, - "patch": 0 + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 + }, + "include": [ + "CMakeDefaultPresets.json" + ], + "configurePresets": [ + { + "name": "ninja-multi", + "inherits": "default", + "displayName": "Ninja Multi-Config", + "description": "Default build using Ninja Multi-Config generator", + "generator": "Ninja Multi-Config" }, - "include": [ - "CMakeDefaultPresets.json" - ], - "configurePresets": [ + { + "name": "windows-only", + "inherits": "default", + "displayName": "Windows-only configuration", + "description": "This build is only available on Windows", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "workflowPresets": [ + { + "name": "default", + "steps": [ { - "name": "ninja-multi", - "inherits": "default", - "displayName": "Ninja Multi-Config", - "description": "Default build using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config" + "type": "configure", + "name": "default" }, { - "name": "windows-only", - "inherits": "default", - "displayName": "Windows-only configuration", - "description": "This build is only available on Windows", - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - } - ], - "workflowPresets": [ + "type": "build", + "name": "default" + }, + { + "type": "build", + "name": "install" + }, { - "name": "default", - "steps": [ - { - "type": "configure", - "name": "default" - }, - { - "type": "build", - "name": "default" - }, - { - "type": "build", - "name": "install" - }, - { - "type": "package", - "name": "default" - } - ] + "type": "package", + "name": "default" } - ] + ] + } + ] } diff --git a/GNUmakefile b/GNUmakefile index 9761655..5ee7252 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -16,7 +16,7 @@ STAGE_DIR:=$(shell realpath $(CURDIR)/stagedir) BUILD_DIR:=$(shell realpath $(CURDIR)/build) #################################### -.PHONY: setup all test gcov install lib_install test_install standalone documentation clean distclean check format +.PHONY: setup all test gcov install lib_install test_install standalone documentation clean distclean check fixme format all: install #XXX cd all && cmake --preset default --debug-find-pkg=greeter cd all && cmake --workflow --preset default @@ -28,6 +28,13 @@ test: setup check: setup run-clang-tidy -extra-arg=-Wno-unknown-warning-option -p $(BUILD_DIR)/all source */source +# TODO(CK): Why doesn't this check/fix all files? +fixme: + rm -rf $(STAGE_DIR) + cd all && cmake --preset default --fresh + run-clang-tidy -extra-arg=-Wno-unknown-warning-option -p $(BUILD_DIR)/all \ + -checks='-*,performance-avoid-endl,modernize-use-nodiscard,misc-const-correctness' $(CURDIR) + setup: cd all && cmake --preset default #XXX --log-level=TRACE --trace-expand --trace-source=CPM_0.38.2.cmake #XXX perl -i.bak -p -e 's#-W[-\w]+(=\d)?\b##g;' \ diff --git a/README.md b/README.md index 7beab95..fb4d092 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This project is the result of learnings from many previous projects and should h ## Features - [How to Use CMake Without the Agonizing Pain](https://alexreinking.com/blog/how-to-use-cmake-without-the-agonizing-pain-part-1.html) Note the Resources sections! -- [Modern CMake practices](https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/) Noteable if you want to use project without CMake config package exports +- [Modern CMake practices](https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/) Notable if you want to use project without CMake config package exports - Suited for single header libraries and projects of any scale - Clean separation of library and executable code - Integrated test suite @@ -178,7 +178,7 @@ make standalone ./build/standalone/greeter --help ``` -### Build and test the installed Release version of the libray +### Build and test the installed Release version of the library see [test/CMakeLists.txt](test/CMakeLists.txt) and [test/CMakePresets.json](test/CMakePresets.json) @@ -308,7 +308,7 @@ Simply remove the standalone / documentation directory and according github work > Can I build the standalone and tests at the same time? / How can I tell my IDE about all subprojects? To keep the project modular, all subprojects derived from the library have been separated into their own CMake modules. -This approach makes it trivial for third-party projects to re-use the projects library code. +This approach makes it trivial for third-party projects to reuse the projects library code. To allow IDEs to see the full scope of the project, the project includes the `all` directory that will create a single build for all subprojects. Use this as the main directory for best IDE support. diff --git a/all/CMakePresets.json b/all/CMakePresets.json index 1490dcc..ec1ad59 100644 --- a/all/CMakePresets.json +++ b/all/CMakePresets.json @@ -1,112 +1,112 @@ { - "version": 6, - "cmakeMinimumRequired": { - "major": 3, - "minor": 25, - "patch": 0 + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "displayName": "Default develop all Config", + "description": "Default build using Ninja generator", + "generator": "Ninja", + "binaryDir": "${sourceParentDir}/build/all", + "installDir": "${sourceParentDir}/stagedir", + "cacheVariables": { + "CMAKE_PREFIX_PATH": { + "type": "path", + "value": "${sourceParentDir}/stagedir" + }, + "CMAKE_CXX_STANDARD": "20", + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_DEBUG_POSTFIX": "D", + "CPM_USE_LOCAL_PACKAGES": true, + "OPTION_ENABLE_UNITY": false, + "OPTION_ENABLE_CLANG_TIDY": true, + "BUILD_SHARED_LIBS": true + }, + "environment": { + "CPM_USE_LOCAL_PACKAGES": "YES", + "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" + } + }, + { + "name": "ninja-multi", + "inherits": "default", + "displayName": "Ninja Multi-Config", + "description": "Default build using Ninja Multi-Config generator", + "generator": "Ninja Multi-Config" + }, + { + "name": "windows-only", + "inherits": "default", + "displayName": "Windows-only configuration", + "description": "This build is only available on Windows", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" }, - "configurePresets": [ + { + "name": "format", + "configurePreset": "default", + "targets": [ + "fix-clang-format", + "fix-cmake-format" + ] + } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + } + ], + "packagePresets": [ + { + "name": "default", + "configurePreset": "default", + "generators": [ + "TGZ" + ] + } + ], + "workflowPresets": [ + { + "name": "default", + "steps": [ { - "name": "default", - "displayName": "Default develop all Config", - "description": "Default build using Ninja generator", - "generator": "Ninja", - "binaryDir": "${sourceParentDir}/build/all", - "installDir": "${sourceParentDir}/stagedir", - "cacheVariables": { - "CMAKE_PREFIX_PATH": { - "type": "path", - "value": "${sourceParentDir}/stagedir" - }, - "CMAKE_CXX_STANDARD": "20", - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_DEBUG_POSTFIX": "D", - "CPM_USE_LOCAL_PACKAGES": "YES", - "OPTION_ENABLE_UNITY": "NO", - "OPTION_ENABLE_CLANG_TIDY": "YES", - "BUILD_SHARED_LIBS": "YES" - }, - "environment": { - "CPM_USE_LOCAL_PACKAGES": "YES", - "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" - } + "type": "configure", + "name": "default" }, { - "name": "ninja-multi", - "inherits": "default", - "displayName": "Ninja Multi-Config", - "description": "Default build using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config" + "type": "build", + "name": "default" }, { - "name": "windows-only", - "inherits": "default", - "displayName": "Windows-only configuration", - "description": "This build is only available on Windows", - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - } - ], - "buildPresets": [ - { - "name": "default", - "configurePreset": "default" + "type": "build", + "name": "format" }, { - "name": "format", - "configurePreset": "default", - "targets": [ - "fix-clang-format", - "fix-cmake-format" - ] - } - ], - "testPresets": [ - { - "name": "default", - "configurePreset": "default", - "output": { - "outputOnFailure": true - }, - "execution": { - "noTestsAction": "error", - "stopOnFailure": true - } - } - ], - "packagePresets": [ - { - "name": "default", - "configurePreset": "default", - "generators": [ - "TGZ" - ] - } - ], - "workflowPresets": [ - { - "name": "default", - "steps": [ - { - "type": "configure", - "name": "default" - }, - { - "type": "build", - "name": "default" - }, - { - "type": "build", - "name": "format" - }, - { - "type": "test", - "name": "default" - } - ] + "type": "test", + "name": "default" } - ] + ] + } + ] } diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 783ac39..fc347c1 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -1,11 +1,12 @@ #pragma once +#include #include namespace greeter { /** Language codes to be used with the Greeter class */ - enum class LanguageCode { EN, DE, ES, FR }; + enum class LanguageCode : std::uint8_t { EN, DE, ES, FR }; /** * @brief A class for saying hello in multiple languages @@ -25,7 +26,7 @@ namespace greeter { * @param lang the language to greet in * @return a string containing the greeting */ - std::string greet(LanguageCode lang = LanguageCode::EN) const; + [[nodiscard]] std::string greet(LanguageCode lang = LanguageCode::EN) const; }; } // namespace greeter diff --git a/standalone/CMakeLists.txt b/standalone/CMakeLists.txt index 13d315c..0ee3358 100644 --- a/standalone/CMakeLists.txt +++ b/standalone/CMakeLists.txt @@ -17,7 +17,7 @@ include(../cmake/options.cmake) # NOTE: EXCLUDE_FROM_ALL has to be OFF or cxxopts target may NOT be installed! CK CPMAddPackage( GITHUB_REPOSITORY jarro2783/cxxopts - VERSION 3.1.1 + VERSION 3.2.1 EXCLUDE_FROM_ALL NO SYSTEM YES # used in case of cmake v3.25 OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" @@ -34,7 +34,7 @@ CPMAddPackage( # ---- Add source files ---- -# XXX file(GLOB _sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp) +# DO NO USE! file(GLOB _sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp) set(_sources source/main.cpp) # ---- Create standalone executable ---- diff --git a/standalone/CMakePresets.json b/standalone/CMakePresets.json index 335497f..363da71 100644 --- a/standalone/CMakePresets.json +++ b/standalone/CMakePresets.json @@ -1,113 +1,113 @@ { - "version": 6, - "cmakeMinimumRequired": { - "major": 3, - "minor": 25, - "patch": 0 + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "displayName": "Default standalone Config", + "description": "Default build using Ninja generator", + "generator": "Ninja", + "binaryDir": "${sourceParentDir}/build/standalone", + "installDir": "${sourceParentDir}/stagedir", + "cacheVariables": { + "CMAKE_PREFIX_PATH": { + "type": "path", + "value": "${sourceParentDir}/stagedir" + }, + "CMAKE_CXX_STANDARD": "20", + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_DEBUG_POSTFIX": "D", + "CPM_USE_LOCAL_PACKAGES": true, + "BUILD_SHARED_LIBS": true + }, + "environment": { + "CPM_USE_LOCAL_PACKAGES": "YES", + "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" + } + }, + { + "name": "ninja-multi", + "inherits": "default", + "displayName": "Ninja Multi-Config", + "description": "Default build using Ninja Multi-Config generator", + "generator": "Ninja Multi-Config" + }, + { + "name": "windows-only", + "inherits": "default", + "displayName": "Windows-only configuration", + "description": "This build is only available on Windows", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" }, - "configurePresets": [ + { + "name": "install", + "configurePreset": "default", + "targets": [ + "install" + ] + } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + } + ], + "packagePresets": [ + { + "name": "default", + "configurePreset": "default", + "generators": [ + "TGZ" + ] + } + ], + "workflowPresets": [ + { + "name": "default", + "steps": [ { - "name": "default", - "displayName": "Default standalone Config", - "description": "Default build using Ninja generator", - "generator": "Ninja", - "binaryDir": "${sourceParentDir}/build/standalone", - "installDir": "${sourceParentDir}/stagedir", - "cacheVariables": { - "CMAKE_PREFIX_PATH": { - "type": "path", - "value": "${sourceParentDir}/stagedir" - }, - "CMAKE_CXX_STANDARD": "20", - "CMAKE_BUILD_TYPE": "Release", - "CMAKE_DEBUG_POSTFIX": "D", - "CPM_USE_LOCAL_PACKAGES": "YES", - "BUILD_SHARED_LIBS": "YES" - }, - "environment": { - "CPM_USE_LOCAL_PACKAGES": "YES", - "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" - } + "type": "configure", + "name": "default" }, { - "name": "ninja-multi", - "inherits": "default", - "displayName": "Ninja Multi-Config", - "description": "Default build using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config" + "type": "build", + "name": "default" }, { - "name": "windows-only", - "inherits": "default", - "displayName": "Windows-only configuration", - "description": "This build is only available on Windows", - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - } - ], - "buildPresets": [ - { - "name": "default", - "configurePreset": "default" + "type": "test", + "name": "default" }, { - "name": "install", - "configurePreset": "default", - "targets": [ - "install" - ] - } - ], - "testPresets": [ - { - "name": "default", - "configurePreset": "default", - "output": { - "outputOnFailure": true - }, - "execution": { - "noTestsAction": "error", - "stopOnFailure": true - } - } - ], - "packagePresets": [ - { - "name": "default", - "configurePreset": "default", - "generators": [ - "TGZ" - ] - } - ], - "workflowPresets": [ + "type": "build", + "name": "install" + }, { - "name": "default", - "steps": [ - { - "type": "configure", - "name": "default" - }, - { - "type": "build", - "name": "default" - }, - { - "type": "test", - "name": "default" - }, - { - "type": "build", - "name": "install" - }, - { - "type": "package", - "name": "default" - } - ] + "type": "package", + "name": "default" } - ] + ] + } + ] } diff --git a/standalone/source/main.cpp b/standalone/source/main.cpp index d0606a4..04a76ad 100644 --- a/standalone/source/main.cpp +++ b/standalone/source/main.cpp @@ -6,6 +6,7 @@ #include #include +// TODO(CK): [bugprone-exception-escape] auto main(int argc, char** argv) -> int { const std::unordered_map languages{ {"en", greeter::LanguageCode::EN}, @@ -31,23 +32,23 @@ auto main(int argc, char** argv) -> int { auto result = options.parse(argc, argv); if (result["help"].as()) { - std::cout << options.help() << std::endl; + std::cout << options.help() << '\n'; return 0; } // if (result["version"].as()) { - // std::cout << "Greeter, version " << GREETER_VERSION << std::endl; + // std::cout << "Greeter, version " << GREETER_VERSION << '\n'; // return 0; // } auto langIt = languages.find(language); if (langIt == languages.end()) { - std::cerr << "unknown language code: " << language << std::endl; + std::cerr << "unknown language code: " << language << '\n'; return 0; } - greeter::Greeter greeter(name); - std::cout << greeter.greet(langIt->second) << std::endl; + const greeter::Greeter greeter(name); + std::cout << greeter.greet(langIt->second) << '\n'; return 0; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 46c7fdf..b34650f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -44,7 +44,7 @@ endif() # ---- Create binary ---- -# XXX file(GLOB _sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp) +# DO NOT USE! file(GLOB _sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp) set(_sources source/main.cpp source/greeter.cpp) add_executable(${PROJECT_NAME} ${_sources}) diff --git a/test/CMakePresets.json b/test/CMakePresets.json index 3b34adb..db85523 100644 --- a/test/CMakePresets.json +++ b/test/CMakePresets.json @@ -1,110 +1,110 @@ { - "version": 6, - "cmakeMinimumRequired": { - "major": 3, - "minor": 25, - "patch": 0 + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "displayName": "Default develop test Config", + "description": "Default build using Ninja generator", + "generator": "Ninja", + "binaryDir": "${sourceParentDir}/build/test", + "installDir": "${sourceParentDir}/stagedir", + "cacheVariables": { + "CMAKE_PREFIX_PATH": { + "type": "path", + "value": "${sourceParentDir}/stagedir" + }, + "CMAKE_CXX_STANDARD": "20", + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_DEBUG_POSTFIX": "D", + "CPM_USE_LOCAL_PACKAGES": false, + "BUILD_SHARED_LIBS": true, + "TEST_INSTALLED_VERSION": true + }, + "environment": { + "CPM_USE_LOCAL_PACKAGES": "YES", + "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" + } + }, + { + "name": "ninja-multi", + "inherits": "default", + "displayName": "Ninja Multi-Config", + "description": "Default build using Ninja Multi-Config generator", + "generator": "Ninja Multi-Config" + }, + { + "name": "windows-only", + "inherits": "default", + "displayName": "Windows-only configuration", + "description": "This build is only available on Windows", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" }, - "configurePresets": [ + { + "name": "install", + "configurePreset": "default", + "targets": [ + "install" + ] + } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + } + ], + "packagePresets": [ + { + "name": "default", + "configurePreset": "default", + "generators": [ + "TGZ" + ] + } + ], + "workflowPresets": [ + { + "name": "default", + "steps": [ { - "name": "default", - "displayName": "Default develop test Config", - "description": "Default build using Ninja generator", - "generator": "Ninja", - "binaryDir": "${sourceParentDir}/build/test", - "installDir": "${sourceParentDir}/stagedir", - "cacheVariables": { - "CMAKE_PREFIX_PATH": { - "type": "path", - "value": "${sourceParentDir}/stagedir" - }, - "CMAKE_CXX_STANDARD": "20", - "CMAKE_BUILD_TYPE": "Release", - "CMAKE_DEBUG_POSTFIX": "D", - "CPM_USE_LOCAL_PACKAGES": "NO", - "BUILD_SHARED_LIBS": "YES", - "TEST_INSTALLED_VERSION": "YES" - }, - "environment": { - "CPM_USE_LOCAL_PACKAGES": "YES", - "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" - } + "type": "configure", + "name": "default" }, { - "name": "ninja-multi", - "inherits": "default", - "displayName": "Ninja Multi-Config", - "description": "Default build using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config" + "type": "build", + "name": "default" }, { - "name": "windows-only", - "inherits": "default", - "displayName": "Windows-only configuration", - "description": "This build is only available on Windows", - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - } - ], - "buildPresets": [ - { - "name": "default", - "configurePreset": "default" + "type": "test", + "name": "default" }, { - "name": "install", - "configurePreset": "default", - "targets": [ - "install" - ] - } - ], - "testPresets": [ - { - "name": "default", - "configurePreset": "default", - "output": { - "outputOnFailure": true - }, - "execution": { - "noTestsAction": "error", - "stopOnFailure": true - } - } - ], - "packagePresets": [ - { - "name": "default", - "configurePreset": "default", - "generators": [ - "TGZ" - ] - } - ], - "workflowPresets": [ - { - "name": "default", - "steps": [ - { - "type": "configure", - "name": "default" - }, - { - "type": "build", - "name": "default" - }, - { - "type": "test", - "name": "default" - }, - { - "type": "build", - "name": "install" - } - ] + "type": "build", + "name": "install" } - ] + ] + } + ] } diff --git a/test/source/greeter.cpp b/test/source/greeter.cpp index 656c894..284005f 100644 --- a/test/source/greeter.cpp +++ b/test/source/greeter.cpp @@ -8,7 +8,7 @@ TEST_CASE("Greeter") { using greeter::Greeter; using greeter::LanguageCode; - Greeter greeter("Tests"); + const Greeter greeter("Tests"); CHECK(greeter.greet(LanguageCode::EN) == "Hello, Tests!"); CHECK(greeter.greet(LanguageCode::DE) == "Hallo Tests!");