From 8784ed836a91e1fdabdb4f386c47e3ba042629f6 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 19 May 2024 21:26:59 -0400 Subject: [PATCH] xo-cmake: + xo_toplevel_release_config() --- cmake/xo_macros/xo_cxx.cmake | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cmake/xo_macros/xo_cxx.cmake b/cmake/xo_macros/xo_cxx.cmake index 3de0e9e2..fee69d14 100644 --- a/cmake/xo_macros/xo_cxx.cmake +++ b/cmake/xo_macros/xo_cxx.cmake @@ -35,6 +35,35 @@ macro(xo_toplevel_testing_options) add_custom_target(all_utest_executables) endmacro() +# release build (cmake -DCMAKE_BUILD_TYPE=release path/to/source) +# +macro(xo_toplevel_release_config2) + if ("${CMAKE_BUILD_TYPE}" STREQUAL "release") + # clear out hardwired default + # we want to override project-level defaults, + # but need to prevent interference from hardwired defaults + # (the problem with non-empty hardwired defaults is that we can't tell if they've + # been set on the command line) + # + set(CMAKE_CXX_FLAGS_RELEASE "") + + # CMAKE_CXX_FLAGS_RELEASE is built-in to cmake and has non-empty default + # -> we cannot tell whether it was set on the command line + # -> use PROJECT_CXX_FLAGS_RELEASE instead + # + # built-in default value is -march=native -O3 -DNDEBUG + # + if (NOT DEFINED PROJECT_CXX_FLAGS_RELEASE) + set(PROJECT_CXX_FLAGS_RELEASE ${PROJECT_CXX_FLAGS} -march=native -O3 -DNDEBUG + CACHE STRING "release c++ compiler flags") + endif() + + message(STATUS "PROJECT_CXX_FLAGS_RELEASE: release c++ flags are [${PROJECT_CXX_FLAGS_RELEASE}]") + + add_compile_options("$<$:${PROJECT_CXX_FLAGS_RELEASE}>") + endif() +endmacro() + # debug build (cmake -DCMAKE_BUILD_TYPE=debug path/to/source) # macro(xo_toplevel_debug_config2)