From 8784ed836a91e1fdabdb4f386c47e3ba042629f6 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 19 May 2024 21:26:59 -0400 Subject: [PATCH 1/3] 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 3de0e9e..fee69d1 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) From 1925c144b0c510f2a0d1bd5b4df29490323886ed Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 19 May 2024 21:32:50 -0400 Subject: [PATCH 2/3] xo-cmake: + xo_toplevel_config2() --- cmake/xo_macros/xo_cxx.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmake/xo_macros/xo_cxx.cmake b/cmake/xo_macros/xo_cxx.cmake index fee69d1..1bfc4f2 100644 --- a/cmake/xo_macros/xo_cxx.cmake +++ b/cmake/xo_macros/xo_cxx.cmake @@ -122,6 +122,18 @@ macro(xo_toplevel_asan_config2) endif() endmacro() +# support for +# cmake -DCMAKE_BUILD_TYPE=release +# cmake -DCMAKE_BUILD_TYPE=debug +# cmake -DCMAKE_BUILD_TYPE+asan +# cmake -DCMAKE_BUILD_TYPE=coverage +# +macro(xo_toplevel_config2) + xo_toplevel_release_config2() + xo_toplevel_debug_config2() + xo_toplevel_asan_config2() + xo_toplevel_coverage_config2() +endmacro() # coverage build: # 0. From 1df767b7c4a20ea10208d4c715accfa2c22e7ba1 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 19 May 2024 21:37:26 -0400 Subject: [PATCH 3/3] xo-cmake: + xo_cxx_toplevel_options3() --- cmake/xo_macros/xo_cxx.cmake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmake/xo_macros/xo_cxx.cmake b/cmake/xo_macros/xo_cxx.cmake index 1bfc4f2..8f75beb 100644 --- a/cmake/xo_macros/xo_cxx.cmake +++ b/cmake/xo_macros/xo_cxx.cmake @@ -20,6 +20,7 @@ macro(xo_cxx_toplevel_options) add_custom_target(all_libraries) endmacro() +# deprecated -- prefer xo_cxx_toplevel_options3() macro(xo_cxx_toplevel_options2) enable_language(CXX) xo_toplevel_compile_options() @@ -28,6 +29,15 @@ macro(xo_cxx_toplevel_options2) add_custom_target(all_utest_executables) endmacro() +macro(xo_cxx_toplevel_options3) + enable_language(CXX) + xo_toplevel_compile_options() + enable_testing() + add_custom_target(all_libraries) + add_custom_target(all_utest_executables) + xo_toplevel_config2() +endmacro() + macro(xo_toplevel_testing_options) enable_testing() add_code_coverage()