Compare commits

...

2 commits

Author SHA1 Message Date
sideshowbarker
60fd075da4
Merge b1f1f319d7 into f638f84185 2024-11-21 02:41:45 +09:00
sideshowbarker
b1f1f319d7
CMake: Respect any optimization level specified in the CXXFLAGS value
This change makes the build respect any valid optimization level
specified with the -O flag in the CXXFLAGS environment variable.

Otherwise, without this change, the build ignores any optimization level
specified with the -O flag in the CXXFLAGS environment variable — which
prevents use of -O0 to build without any optimizations. And one effect
of not being able to disable optimizations is that trying to check
certain frame variables in lldb can result in an error of this form:

> error: Couldn't look up symbols: __ZN2AK6Detail10StringBaseD2Ev
> Hint: The expression tried to call a function that is not present in
> the target, perhaps because it was optimized out by the compiler.
2024-11-06 15:43:39 +09:00

View file

@ -29,9 +29,17 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (NOT MSVC)
add_cxx_compile_options(-ggdb3)
endif()
add_cxx_compile_options(-Og)
if ("$ENV{CXXFLAGS}" MATCHES "(^| )(-O(fast|.?))( |$)")
add_cxx_compile_options(${CMAKE_MATCH_0})
else ()
add_cxx_compile_options(-Og)
endif()
else()
add_cxx_compile_options(-O2)
if ("$ENV{CXXFLAGS}" MATCHES "(^| )(-O(fast|.?))( |$)")
add_cxx_compile_options(${CMAKE_MATCH_0})
else ()
add_cxx_compile_options(-O2)
endif()
if (NOT MSVC)
add_cxx_compile_options(-g1)
endif()