From 9686ddc70aa8416c59ed90e1cae0ac0703a9cfa5 Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 15 Jan 2026 11:46:06 +0100 Subject: [PATCH 1/5] Use newer cmake version that should be available when using C++23 Signed-off-by: Christoph Niethammer --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de2a028..0cf4510 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.17) +cmake_minimum_required(VERSION 3.27) set(CMAKE_C_COMPILER "clang") set(CMAKE_CXX_COMPILER "clang++") From 7985850215193361f2eb59754cba6cdc5ea416c5 Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 15 Jan 2026 11:47:32 +0100 Subject: [PATCH 2/5] Make tests available for all build types and use CTest Signed-off-by: Christoph Niethammer --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cf4510..866718c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,9 @@ find_package(MPI REQUIRED) include(GNUInstallDirs) include(CMakePackageConfigHelpers) +if(PROJECT_IS_TOP_LEVEL) + include(CTest) +endif() add_library(mppi INTERFACE) target_include_directories(mppi @@ -30,8 +33,7 @@ set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) endif(NOT CMAKE_BUILD_TYPE) -# only combile tests in debug mode -if(CMAKE_BUILD_TYPE STREQUAL "Debug") +if(BUILD_TESTING) add_subdirectory(tests) endif() From 5dbff4d423a8c4857b50168c9194f92e542a4978 Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 15 Jan 2026 11:48:05 +0100 Subject: [PATCH 3/5] Do not enforece a specific build type in CMakeLists.txt Signed-off-by: Christoph Niethammer --- CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 866718c..90d6230 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,12 +26,6 @@ target_include_directories(mppi add_library(mppi::mppi ALIAS mppi) target_link_libraries(mppi INTERFACE MPI::MPI_CXX) target_compile_features(mppi INTERFACE cxx_std_23) - -# set Release as the default build type if it is not yet set. -if(NOT CMAKE_BUILD_TYPE) -set(CMAKE_BUILD_TYPE "Release" CACHE STRING - "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) -endif(NOT CMAKE_BUILD_TYPE) if(BUILD_TESTING) add_subdirectory(tests) From 93e0f6c60c4011c5126aab7b436a2174ac3b69ac Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 15 Jan 2026 15:07:38 +0100 Subject: [PATCH 4/5] Bump C++ version up to 26 for reflections Signed-off-by: Christoph Niethammer --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90d6230..782547c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ target_include_directories(mppi add_library(mppi::mppi ALIAS mppi) target_link_libraries(mppi INTERFACE MPI::MPI_CXX) -target_compile_features(mppi INTERFACE cxx_std_23) +target_compile_features(mppi INTERFACE cxx_std_26) if(BUILD_TESTING) add_subdirectory(tests) From cbc30b91f15fc5dce6437ebffa4db3c2accd5a20 Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 15 Jan 2026 15:12:51 +0100 Subject: [PATCH 5/5] Use CMake presets and toolchains instead of hard coding CMAKE variables Signed-off-by: Christoph Niethammer --- CMakeLists.txt | 4 -- CMakePresets.json | 46 +++++++++++++++++++++++ README.md | 7 ++-- cmake/toolchains/clang-p2996-libcxx.cmake | 5 +++ 4 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 CMakePresets.json create mode 100644 cmake/toolchains/clang-p2996-libcxx.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 782547c..f74d415 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,5 @@ cmake_minimum_required(VERSION 3.27) -set(CMAKE_C_COMPILER "clang") -set(CMAKE_CXX_COMPILER "clang++") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -freflection -fno-access-contexts -std=c++26") -# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++") project(mppi VERSION 0.10.2 diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..71bec7a --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,46 @@ +{ + "version": 5, + "cmakeMinimumRequired": { + "major": 3, + "minor": 27, + "patch": 0 + }, + "configurePresets": [ + { + "name": "clang_reflection", + "hidden": true, + "cacheVariables": { + "CMAKE_CXX_STANDARD": "26", + "CMAKE_CXX_STANDARD_REQUIRED": "ON", + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/clang-p2996-libcxx.cmake" + } + }, + { + "name": "release", + "displayName": "Release", + "inherits": "clang_reflection", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "debug", + "displayName": "Debug", + "inherits": "clang_reflection", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + } + ], + + "buildPresets": [ + { + "name": "release", + "configurePreset": "release" + }, + { + "name": "debug", + "configurePreset": "debug" + } + ] +} diff --git a/README.md b/README.md index dc85579..18ec2f9 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,9 @@ Additionally, for the tests: To build, test and install the MPPI library execute ```shell -mkdir build && cd build -cmake -DCMAKE_INSTALL_PREFIX=/my/install/prefix .. -make [-j N] -make install +cmake --preset release -B build -S . -DCMAKE_INSTALL_PREFIX=/my/install/prefix .. +cmake --build build +cmake --install build ``` ## Notes diff --git a/cmake/toolchains/clang-p2996-libcxx.cmake b/cmake/toolchains/clang-p2996-libcxx.cmake new file mode 100644 index 0000000..2eddef7 --- /dev/null +++ b/cmake/toolchains/clang-p2996-libcxx.cmake @@ -0,0 +1,5 @@ +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) + +add_compile_options(-stdlib=libc++ -freflection) +add_link_options(-stdlib=libc++)