From dbb9f38e8d2a6ceb9bfdd3bc4909f1390d77088c Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 27 Sep 2023 16:06:18 -0400 Subject: [PATCH] xo-cmake: + xo_toplevel_compile_options() --- cmake/xo_cxx.cmake | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/cmake/xo_cxx.cmake b/cmake/xo_cxx.cmake index 160a1833..dac88151 100644 --- a/cmake/xo_cxx.cmake +++ b/cmake/xo_cxx.cmake @@ -1,6 +1,32 @@ -set(XO_STANDARD_COMPILE_OPTIONS -Werror -Wall -Wextra) -set(XO_COMPILE_OPTIONS ${XO_STANDARD_COMPILE_OPTIONS}) +macro(xo_toplevel_compile_options) + # ---------------------------------------------------------------- + # variable + # XO_ADDRESS_SANITIZE + # determines whether to enable address sanitizer for the XO project + # (see toplevel CMakeLists.txt) + # ---------------------------------------------------------------- + if(XO_ADDRESS_SANITIZE) + add_compile_options(-fsanitize=address) + add_link_options(-fsanitize=address) + endif() + + set(XO_STANDARD_COMPILE_OPTIONS -Werror -Wall -Wextra) + # XO_ADDRESS_SANITIZE_COMPILE_OPTIONS: use when XO_ADDRESS_SANITIZE=ON + # + # address sanitizer build complains about _FORTIFY_SOURCE redefines + # In file included from :460: + # :1:9: error: '_FORTIFY_SOURCE' macro redefined [-Werror,-Wmacro-redefined] + # #define _FORTIFY_SOURCE 2 + # + set(XO_ADDRESS_SANITIZE_COMPILE_OPTIONS -Werror -Wall -Wextra -Wno-macro-redefined) + + if(XO_ADDRESS_SANITIZE) + set(XO_COMPILE_OPTIONS ${XO_ADDRESS_SANITIZE_COMPILE_OPTIONS}) + else() + set(XO_COMPILE_OPTIONS ${XO_STANDARD_COMPILE_OPTIONS}) + endif() +endif() # ---------------------------------------------------------------- # use this in subdirs that compile c++ code @@ -38,6 +64,9 @@ endmacro() # ---------------------------------------------------------------- # +# Require: +# needs to be preceded by call to xo_toplevel_compile_options() +# macro(xo_compile_options target) target_copmile_options(${target} PRIVATE ${XO_COMPILE_OPTIONS}) endmacro()