From b1f1f319d7c00a5a1306ca356bfde22e2f270bc0 Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Wed, 6 Nov 2024 15:24:34 +0900 Subject: [PATCH] CMake: Respect any optimization level specified in the CXXFLAGS value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Meta/CMake/lagom_compile_options.cmake | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Meta/CMake/lagom_compile_options.cmake b/Meta/CMake/lagom_compile_options.cmake index 7fec47ac843..64ddf53a379 100644 --- a/Meta/CMake/lagom_compile_options.cmake +++ b/Meta/CMake/lagom_compile_options.cmake @@ -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()