Skip to content

Enable -O3 on RelWithDebInfo builds #1587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cmake/common/defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ endif()
# It is very useful for IDE integration, linting, etc
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# CMake typically defaults to -O2 for RelWithDebInfo, which can
# result in slight differences when comparing to Release when
# profiling or analysing the resulting assembly
# See https://stackoverflow.com/a/59314670
if(SOURCEMETA_COMPILER_LLVM OR SOURCEMETA_COMPILER_GCC)
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g" CACHE STRING "Optimization level for RelWithDebInfo (C)" FORCE)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g" CACHE STRING "Optimization level for RelWithDebInfo (C++)" FORCE)
set(CMAKE_OBJC_FLAGS_RELWITHDEBINFO "-O3 -g" CACHE STRING "Optimization level for RelWithDebInfo (Objective-C)" FORCE)
set(CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO "-O3 -g" CACHE STRING "Optimization level for RelWithDebInfo (Objective-C++)" FORCE)
endif()

# Prevent DT_RPATH/DT_RUNPATH problem
# This problem is not present on Apple platforms.
# See https://www.youtube.com/watch?v=m0DwB4OvDXk
Expand Down