]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Change WITH_SANITIZER to be a multi-option parameter (for ccmake etc).
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Sun, 13 Jun 2021 13:11:23 +0000 (15:11 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 18 Jun 2021 07:16:10 +0000 (09:16 +0200)
Add support for selcting Thread sanitizer.

CMakeLists.txt
cmake/detect-sanitizer.cmake

index 9fcef690425401ab44d2696e1d6db1c6f581ded6..fd696449cc299990575ca4595ef832d0c903fb70 100644 (file)
@@ -79,7 +79,6 @@ add_option(WITH_GZFILEOP "Compile with support for gzFile related functions" ON)
 add_option(ZLIB_COMPAT "Compile with zlib compatible API" OFF)
 add_option(ZLIB_ENABLE_TESTS "Build test binaries" ON)
 add_option(ZLIB_DUAL_LINK "Dual link tests against system zlib" OFF)
-add_option(WITH_SANITIZER "Build with sanitizer (Memory, Address, Undefined)" OFF)
 add_option(WITH_FUZZERS "Build test/fuzz" OFF)
 add_option(WITH_OPTIM "Build with optimisation" ON)
 add_option(WITH_NEW_STRATEGIES "Use new strategies" ON)
@@ -91,6 +90,10 @@ add_option(WITH_INFLATE_STRICT "Build with strict inflate distance checking" OFF
 add_option(WITH_INFLATE_ALLOW_INVALID_DIST "Build with zero fill for inflate invalid distances" OFF)
 add_option(WITH_UNALIGNED "Support unaligned reads on platforms that support it" ON)
 
+# Add multi-choice option
+set(WITH_SANITIZER AUTO CACHE STRING "Enable sanitizer support")
+set_property(CACHE WITH_SANITIZER PROPERTY STRINGS "Memory" "Address" "Undefined" "Thread")
+
 if(BASEARCH_ARM_FOUND)
     add_option(WITH_ACLE "Build with ACLE" ON)
     add_option(WITH_NEON "Build with NEON intrinsics" ON)
@@ -322,6 +325,8 @@ if(WITH_SANITIZER STREQUAL "Address")
     add_address_sanitizer()
 elseif(WITH_SANITIZER STREQUAL "Memory")
     add_memory_sanitizer()
+elseif(WITH_SANITIZER STREQUAL "Thread")
+    add_thread_sanitizer()
 elseif(WITH_SANITIZER STREQUAL "Undefined")
     add_undefined_sanitizer()
 endif()
index 172a8d558390768ab6a002a2be5f93f26ad5a2fa..b0a0236e83293092f0762f85b628e4b8b667a3fb 100644 (file)
@@ -69,6 +69,16 @@ macro(add_memory_sanitizer)
     endif()
 endmacro()
 
+macro(add_thread_sanitizer)
+    check_sanitizer_support("thread" supported_checks)
+    if(NOT ${supported_checks} STREQUAL "")
+        message(STATUS "Thread sanitizer is enabled: ${supported_checks}")
+        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${supported_checks}")
+    else()
+        message(STATUS "Thread sanitizer is not supported")
+    endif()
+endmacro()
+
 macro(add_undefined_sanitizer)
     set(known_checks
         array-bounds
@@ -120,4 +130,4 @@ macro(add_undefined_sanitizer)
     else()
         message(STATUS "UNdefined behavior sanitizer is not supported")
     endif()
-endmacro()
\ No newline at end of file
+endmacro()