Specify default opt/debug options for different CMAKE_BUILD_TYPEs#409
Specify default opt/debug options for different CMAKE_BUILD_TYPEs#409greenc-FNAL wants to merge 2 commits intomainfrom
CMAKE_BUILD_TYPEs#409Conversation
greenc-FNAL
commented
Mar 11, 2026
- May be overridden from CMake command line, environment, etc.
|
@phlexbot cmake-fix |
|
Automatic cmake-format fixes pushed (commit ff40cdd). |
There was a problem hiding this comment.
Pull request overview
Adds explicit default C++ compiler flags for common CMake build types at the top level, aiming to standardize optimization/debug settings across builds.
Changes:
- Introduce cached defaults for
CMAKE_CXX_FLAGS_DEBUG,CMAKE_CXX_FLAGS_RELEASE, andCMAKE_CXX_FLAGS_RELWITHDEBINFO.
| if(NOT CMAKE_CXX_FLAGS_DEBUG) | ||
| set(CMAKE_CXX_FLAGS_DEBUG "-Og -g" CACHE STRING "" FORCE) | ||
| endif() | ||
|
|
||
| if(NOT CMAKE_CXX_FLAGS_RELEASE) | ||
| set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g0 -DNDEBUG" CACHE STRING "" FORCE) | ||
| endif() | ||
|
|
||
| if(NOT CMAKE_CXX_FLAGS_RELWITHDEBINFO) | ||
| set( | ||
| CMAKE_CXX_FLAGS_RELWITHDEBINFO | ||
| "-O3 -fno-omit-frame-pointer -g -DNDEBUG" | ||
| CACHE STRING | ||
| "" | ||
| FORCE | ||
| ) |
There was a problem hiding this comment.
These set(CMAKE_CXX_FLAGS_<CONFIG> ... CACHE ... FORCE) calls run before project()/cet_cmake_env(), so the variables are typically still unset and will be force-initialized here. That overrides the toolchain/compiler defaults CMake (and cetmodules) would normally populate, and can break or unexpectedly change flags for non-GNU/Clang toolchains. Prefer setting CMAKE_CXX_FLAGS_<CONFIG>_INIT before project(), or move this after project() and append per-config flags via add_compile_options($<$<CONFIG:...>:...>)/target options, and avoid FORCE unless you intend to override user-provided cache values.
| if(NOT CMAKE_CXX_FLAGS_DEBUG) | |
| set(CMAKE_CXX_FLAGS_DEBUG "-Og -g" CACHE STRING "" FORCE) | |
| endif() | |
| if(NOT CMAKE_CXX_FLAGS_RELEASE) | |
| set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g0 -DNDEBUG" CACHE STRING "" FORCE) | |
| endif() | |
| if(NOT CMAKE_CXX_FLAGS_RELWITHDEBINFO) | |
| set( | |
| CMAKE_CXX_FLAGS_RELWITHDEBINFO | |
| "-O3 -fno-omit-frame-pointer -g -DNDEBUG" | |
| CACHE STRING | |
| "" | |
| FORCE | |
| ) | |
| if(NOT DEFINED CMAKE_CXX_FLAGS_DEBUG_INIT) | |
| set(CMAKE_CXX_FLAGS_DEBUG_INIT "-Og -g") | |
| endif() | |
| if(NOT DEFINED CMAKE_CXX_FLAGS_RELEASE_INIT) | |
| set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -g0 -DNDEBUG") | |
| endif() | |
| if(NOT DEFINED CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT) | |
| set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O3 -fno-omit-frame-pointer -g -DNDEBUG") |
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #409 +/- ##
==========================================
- Coverage 84.05% 84.02% -0.04%
==========================================
Files 127 127
Lines 3306 3306
Branches 562 562
==========================================
- Hits 2779 2778 -1
Misses 329 329
- Partials 198 199 +1
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
ff40cdd to
24926bc
Compare
|
Review the full CodeQL report for details. |
- May be overridden from CMake command line, environment, etc.
24926bc to
13407aa
Compare