diff --git a/CMakeLists.txt b/CMakeLists.txt index dad564236..ea8dfc6a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,39 @@ FetchContent_Declare( FIND_PACKAGE_ARGS ) +# ############################################################################## +# Initial compilation flags for build types we care about. Setting these in the +# cache before project() prevents CMake's per-compiler defaults from overwriting +# them; using DEFINED CACHE{} respects any value the user has already placed in +# the cache (e.g. via -D on the command line). +if(NOT DEFINED CACHE{CMAKE_CXX_FLAGS_DEBUG}) + set( + CMAKE_CXX_FLAGS_DEBUG + "-Og -g" + CACHE STRING + "Flags used by the CXX compiler during DEBUG builds." + ) +endif() + +if(NOT DEFINED CACHE{CMAKE_CXX_FLAGS_RELEASE}) + set( + CMAKE_CXX_FLAGS_RELEASE + "-O3 -g0 -DNDEBUG" + CACHE STRING + "Flags used by the CXX compiler during RELEASE builds." + ) +endif() + +if(NOT DEFINED CACHE{CMAKE_CXX_FLAGS_RELWITHDEBINFO}) + set( + CMAKE_CXX_FLAGS_RELWITHDEBINFO + "-O3 -fno-omit-frame-pointer -g -DNDEBUG" + CACHE STRING + "Flags used by the CXX compiler during RELWITHDEBINFO builds." + ) +endif() +# ############################################################################## + # Make cetmodules available FetchContent_MakeAvailable(cetmodules) find_package(cetmodules 4.01.01 REQUIRED) @@ -49,8 +82,8 @@ project(phlex VERSION 0.1.0 LANGUAGES CXX) cet_cmake_env() # ############################################################################## -# Set CI/test timeouts to a conservative value to avoid long stalls in CI. -# Use cache variables so generated CTest/Dart files pick this up when configured. +# Set CI/test timeouts to a conservative value to avoid long stalls in CI. Use +# cache variables so generated CTest/Dart files pick this up when configured. set(DART_TESTING_TIMEOUT 90 CACHE STRING "Timeout (s) for Dart/CTest runs") set(CTEST_TEST_TIMEOUT 90 CACHE STRING "Per-test timeout (s) for CTest")