From c75ec240869f9a8fc7a27bfaa0d78c9fc0bce55b Mon Sep 17 00:00:00 2001 From: ewarchul Date: Sat, 13 Jul 2024 13:55:33 +0200 Subject: [PATCH] Tweak CMake --- .env | 4 ++-- .gitignore | 1 + CMakeLists.txt | 10 ++++++++-- Justfile | 2 +- cmake/{config.cmake => ProjectConfig.cmake} | 7 +++++-- test/CMakeLists.txt | 2 ++ 6 files changed, 19 insertions(+), 7 deletions(-) rename cmake/{config.cmake => ProjectConfig.cmake} (70%) diff --git a/.env b/.env index 0a95abf..7e0713e 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ -CXX="clang++-18" -CC="clang-18" +CXX="g++-14" +CC="gcc-14" diff --git a/.gitignore b/.gitignore index 8ee1e50..13f77eb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ build-*/* .cache/* legacy/* include/cecxx/benchmark/defaults.hpp +data/* diff --git a/CMakeLists.txt b/CMakeLists.txt index dba0d90..170fc78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ project(cecxx set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(Package) -include(config) +include(ProjectConfig) include(GNUInstallDirs) include(CMakePackageConfigHelpers) @@ -51,6 +51,8 @@ target_sources(cecxx PUBLIC FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_D target_compile_options(cecxx PRIVATE ${COMPILE_FLAGS}) target_compile_features(cecxx PRIVATE cxx_std_20) +message(STATUS "The cecxx library is going to be compiled with the following additional flags: ${COMPILE_FLAGS}") + configure_file(defaults.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/cecxx/benchmark/defaults.hpp) generate_export_header(cecxx) @@ -74,5 +76,9 @@ if (WITH_BENCHMARKS) endif() if (WITH_TESTS) - add_subdirectory(test) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_subdirectory(test) + else() + message(WARNING "To build tests, use clang compiler. Current CXX compiler: ${CMAKE_CXX_COMPILER}") + endif() endif(WITH_TESTS) diff --git a/Justfile b/Justfile index 4548e96..b0350ac 100644 --- a/Justfile +++ b/Justfile @@ -17,7 +17,7 @@ ncores := `nproc` init_build: clean mkdir -p {{build_dir}} - cd {{build_dir}} && CC={{c_compiler}} CXX={{cxx_compiler}} cmake -DFUZZTEST_FUZZING_MODE=on -DWITH_TESTS=on -DWITH_EXAMPLES=on .. + cd {{build_dir}} && CC={{c_compiler}} CXX={{cxx_compiler}} cmake -DWITH_TESTS=on -DWITH_EXAMPLES=on .. ln -fs {{build_dir}}/compile_commands.json compile_commands.json build: diff --git a/cmake/config.cmake b/cmake/ProjectConfig.cmake similarity index 70% rename from cmake/config.cmake rename to cmake/ProjectConfig.cmake index 9f659b1..e3f2e02 100644 --- a/cmake/config.cmake +++ b/cmake/ProjectConfig.cmake @@ -5,10 +5,13 @@ option(WITH_BENCHMARKS "Build benchmarks" OFF) set(BENCHMARK_DATA_STORAGE "${CMAKE_INSTALL_PREFIX}/share/cecxx") if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") - set(COMPILE_FLAGS -Wall -Wpedantic -Wextra -Wconversion -Wimplicit-fallthrough -Wundef) + set(COMPILE_FLAGS -Wall -Wpedantic -Wextra -Wconversion -Wimplicit-fallthrough -Wundef -Werror) + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14.0) + set(COMPILE_FLAGS ${COMPILE_FLAGS} -Wnrvo) + endif() endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(COMPILE_FLAGS -Wall -Wextra -pedantic -Wconversion -Wundef - -Wdeprecated -Wshadow) + -Wdeprecated -Wshadow -Werror) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e0932d1..d764ba8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,5 @@ +set(FUZZTEST_FUZZING_MODE ON) + include(FetchContent) FetchContent_Declare( fuzztest