File: Sanitizers.cmake

package info (click to toggle)
mongo-c-driver 1.23.1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 41,364 kB
  • sloc: ansic: 176,588; javascript: 7,954; python: 4,498; sh: 136; makefile: 32; xml: 10; cpp: 2
file content (35 lines) | stat: -rw-r--r-- 1,140 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
include (CheckCSourceCompiles)
include (CMakePushCheckState)

## Directly control the options passed to -fsanitize
set (MONGO_SANITIZE "" CACHE STRING "Semicolon/comma-separated list of sanitizers to apply when building")

# Replace commas with semicolons for the genex
string(REPLACE ";" "," _sanitize "${MONGO_SANITIZE}")

if (_sanitize)
    string (MAKE_C_IDENTIFIER "HAVE_SANITIZE_${_sanitize}" ident)
    string (TOUPPER "${ident}" varname)
    set (flag "-fsanitize=${_sanitize}")

    cmake_push_check_state ()
        set (CMAKE_REQUIRED_FLAGS "${flag}")
        set (CMAKE_REQUIRED_LIBRARIES "${flag}")
        check_c_source_compiles ([[
            #include <stdio.h>

            int main (void) {
                puts ("Hello, world!");
                return 0;
            }
        ]] "${varname}")
    cmake_pop_check_state ()

    if (NOT "${${varname}}")
        message (SEND_ERROR "Requested sanitizer option '${flag}' is not supported by the compiler+linker")
    else ()
        message (STATUS "Building with ${flag}")
        add_compile_options ("${flag}")
        link_libraries ("${flag}")
    endif ()
endif ()