diff --git a/CMakeLists.txt b/CMakeLists.txt index de2a028..f74d415 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,5 @@ -cmake_minimum_required(VERSION 3.17) +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 @@ -13,6 +9,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 @@ -22,16 +21,9 @@ 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) +target_compile_features(mppi INTERFACE cxx_std_26) -# only combile tests in debug mode -if(CMAKE_BUILD_TYPE STREQUAL "Debug") +if(BUILD_TESTING) add_subdirectory(tests) endif() 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++)