Skip to content

Commit 6b2b0bc

Browse files
authored
Enable -O3 on RelWithDebInfo builds (#1587)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 217e7e3 commit 6b2b0bc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cmake/common/defaults.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ endif()
4141
# It is very useful for IDE integration, linting, etc
4242
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
4343

44+
# CMake typically defaults to -O2 for RelWithDebInfo, which can
45+
# result in slight differences when comparing to Release when
46+
# profiling or analysing the resulting assembly
47+
# See https://stackoverflow.com/a/59314670
48+
if(SOURCEMETA_COMPILER_LLVM OR SOURCEMETA_COMPILER_GCC)
49+
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g" CACHE STRING "Optimization level for RelWithDebInfo (C)" FORCE)
50+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g" CACHE STRING "Optimization level for RelWithDebInfo (C++)" FORCE)
51+
set(CMAKE_OBJC_FLAGS_RELWITHDEBINFO "-O3 -g" CACHE STRING "Optimization level for RelWithDebInfo (Objective-C)" FORCE)
52+
set(CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO "-O3 -g" CACHE STRING "Optimization level for RelWithDebInfo (Objective-C++)" FORCE)
53+
endif()
54+
4455
# Prevent DT_RPATH/DT_RUNPATH problem
4556
# This problem is not present on Apple platforms.
4657
# See https://www.youtube.com/watch?v=m0DwB4OvDXk

0 commit comments

Comments
 (0)