Skip to content

Specify default opt/debug options for different CMAKE_BUILD_TYPEs#409

Open
greenc-FNAL wants to merge 2 commits intomainfrom
maintenance/specify-opt-debug-flags
Open

Specify default opt/debug options for different CMAKE_BUILD_TYPEs#409
greenc-FNAL wants to merge 2 commits intomainfrom
maintenance/specify-opt-debug-flags

Conversation

@greenc-FNAL
Copy link
Contributor

  • May be overridden from CMake command line, environment, etc.

- May be overridden from CMake command line, environment, etc.
@greenc-FNAL
Copy link
Contributor Author

@phlexbot cmake-fix

@github-actions
Copy link
Contributor

Automatic cmake-format fixes pushed (commit ff40cdd).
⚠️ Note: Some issues may require manual review and fixing.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and CMAKE_CXX_FLAGS_RELWITHDEBINFO.

Comment on lines +44 to +59
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
)
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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")

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##             main     #409      +/-   ##
==========================================
+ Coverage   83.71%   83.83%   +0.12%     
==========================================
  Files         126      126              
  Lines        3291     3291              
  Branches      583      583              
==========================================
+ Hits         2755     2759       +4     
+ Misses        325      324       -1     
+ Partials      211      208       -3     
Flag Coverage Δ
unittests 83.83% <ø> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9890393...ff40cdd. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants