]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Use add_link_options in cmake sanitizer detection.
authorNathan Moinvaziri <nathan@nathanm.com>
Wed, 26 Jan 2022 01:49:45 +0000 (17:49 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sat, 29 Jan 2022 15:44:21 +0000 (16:44 +0100)
cmake/detect-sanitizer.cmake

index b0a0236e83293092f0762f85b628e4b8b667a3fb..93b437454de92e09ffee25780362e4037dd4a224 100644 (file)
@@ -14,7 +14,7 @@ macro(check_sanitizer_support known_checks supported_checks)
             set(compile_checks "${available_checks},${check}")
         endif()
 
-        set(CMAKE_REQUIRED_FLAGS "-fsanitize=${compile_checks}")
+        set(CMAKE_REQUIRED_FLAGS -fsanitize=${compile_checks})
 
         check_c_source_compiles("int main() { return 0; }" HAS_SANITIZER_${check}
             FAIL_REGEX "not supported|unrecognized command|unknown option")
@@ -40,6 +40,7 @@ macro(add_address_sanitizer)
     if(NOT ${supported_checks} STREQUAL "")
         message(STATUS "Address sanitizer is enabled: ${supported_checks}")
         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${supported_checks}")
+        add_link_options(-fsanitize=${supported_checks})
     else()
         message(STATUS "Address sanitizer is not supported")
     endif()
@@ -53,6 +54,7 @@ macro(add_address_sanitizer)
         if(NOT ${supported_checks} STREQUAL "")
             message(STATUS "Leak sanitizer is enabled: ${supported_checks}")
             set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${supported_checks}")
+            add_link_options(-fsanitize=${supported_checks})
         else()
             message(STATUS "Leak sanitizer is not supported")
         endif()
@@ -64,6 +66,7 @@ macro(add_memory_sanitizer)
     if(NOT ${supported_checks} STREQUAL "")
         message(STATUS "Memory sanitizer is enabled: ${supported_checks}")
         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${supported_checks}")
+        add_link_options(-fsanitize=${supported_checks})
     else()
         message(STATUS "Memory sanitizer is not supported")
     endif()
@@ -74,6 +77,7 @@ macro(add_thread_sanitizer)
     if(NOT ${supported_checks} STREQUAL "")
         message(STATUS "Thread sanitizer is enabled: ${supported_checks}")
         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${supported_checks}")
+        add_link_options(-fsanitize=${supported_checks})
     else()
         message(STATUS "Thread sanitizer is not supported")
     endif()
@@ -121,6 +125,7 @@ macro(add_undefined_sanitizer)
     if(NOT ${supported_checks} STREQUAL "")
         message(STATUS "Undefined behavior sanitizer is enabled: ${supported_checks}")
         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=${supported_checks}")
+        add_link_options(-fsanitize=${supported_checks})
 
         # Group sanitizer flag -fsanitize=undefined will automatically add alignment, even if
         # it is not in our sanitize flag list, so we need to explicitly disable alignment sanitizing.