From ec2bd92859329d672a2d04031545c1c4be58e990 Mon Sep 17 00:00:00 2001 From: Duta-Sebastian Date: Tue, 14 Jan 2025 00:04:50 +0200 Subject: [PATCH] =?UTF-8?q?Ad=C4=83ugat=20op=C8=9Biune=20run=5Fsanitizers?= =?UTF-8?q?=20in=20CompilerFlags.cmake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 3 ++- cmake/CompilerFlags.cmake | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 72081b8d..9b67ef67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,8 @@ add_executable(${MAIN_EXECUTABLE_NAME} ) # NOTE: Add all defined targets (e.g. executables, libraries, etc. ) -set_compiler_flags(TARGET_NAMES ${MAIN_EXECUTABLE_NAME}) +# NOTE: RUN_SANITIZERS is optional, if it's not present it will default to true +set_compiler_flags(RUN_SANITIZERS TRUE TARGET_NAMES ${MAIN_EXECUTABLE_NAME}) # set_compiler_flags(TARGET_NAMES ${MAIN_EXECUTABLE_NAME} ${FOO} ${BAR}) # where ${FOO} and ${BAR} represent additional executables or libraries # you want to compile with the set compiler flags diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index 3a9d3379..a4f084a5 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -4,7 +4,12 @@ include(cmake/CustomStdlibAndSanitizers.cmake) function(set_compiler_flags) set(multiValueArgs TARGET_NAMES) - cmake_parse_arguments(PARSE_ARGV 0 ARG "" "" "${multiValueArgs}") + set(oneValueArgs RUN_SANITIZERS) + cmake_parse_arguments(PARSE_ARGV 0 ARG "" "${oneValueArgs}" "${multiValueArgs}") + + if(NOT DEFINED ARG_RUN_SANITIZERS) + set(ARG_RUN_SANITIZERS TRUE) + endif() # iterate over all specified targets foreach (TARGET_NAME IN LISTS ARG_TARGET_NAMES) @@ -30,6 +35,9 @@ function(set_compiler_flags) ############################################################################### # sanitizers - set_custom_stdlib_and_sanitizers(${TARGET_NAME} true) + if("${ARG_RUN_SANITIZERS}" STREQUAL "TRUE") + set_custom_stdlib_and_sanitizers(${TARGET_NAME} true) + endif () + endforeach () endfunction() \ No newline at end of file