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.
This commit is contained in:
sideshowbarker 2024-11-06 15:24:34 +09:00
parent 42b31820a6
commit b1f1f319d7
No known key found for this signature in database

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()