diff options
Diffstat (limited to 'test/API/CMake')
-rw-r--r-- | test/API/CMake/CheckAsan.cmake | 37 | ||||
-rw-r--r-- | test/API/CMake/CheckUbsan.cmake | 37 |
2 files changed, 74 insertions, 0 deletions
diff --git a/test/API/CMake/CheckAsan.cmake b/test/API/CMake/CheckAsan.cmake new file mode 100644 index 0000000..32f4b45 --- /dev/null +++ b/test/API/CMake/CheckAsan.cmake @@ -0,0 +1,37 @@ +set(ASAN_FLAG "-fsanitize=address") +set(ASAN_C_FLAGS "-O1 -g ${ASAN_FLAG} -fsanitize-address-use-after-scope -fno-omit-frame-pointer -fno-optimize-sibling-calls") +set(ASAN_CXX_FLAGS ${ASAN_C_FLAGS}) + +get_property(ASAN_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) +foreach(lang ${ASAN_LANGUAGES}) + set(ASAN_${lang}_LANG_ENABLED 1) +endforeach() + +if(ASAN_C_LANG_ENABLED) + include(CheckCCompilerFlag) + set(CMAKE_REQUIRED_LINK_OPTIONS ${ASAN_FLAG}) + check_c_compiler_flag(${ASAN_FLAG} ASAN_C_FLAG_SUPPORTED) + if(NOT ASAN_C_FLAG_SUPPORTED) + message(STATUS "Asan flags are not supported by the C compiler.") + else() + if(NOT CMAKE_C_FLAGS_ASAN) + set(CMAKE_C_FLAGS_ASAN ${ASAN_C_FLAGS} CACHE STRING "Flags used by the C compiler during ASAN builds." FORCE) + endif() + endif() + unset(CMAKE_REQUIRED_LINK_OPTIONS) +endif() + +if(ASAN_CXX_LANG_ENABLED) + include(CheckCXXCompilerFlag) + set(CMAKE_REQUIRED_LINK_OPTIONS ${ASAN_FLAG}) + check_cxx_compiler_flag(${ASAN_FLAG} ASAN_CXX_FLAG_SUPPORTED) + if(NOT ASAN_CXX_FLAG_SUPPORTED) + message(STATUS "Asan flags are not supported by the CXX compiler.") + else() + if(NOT CMAKE_CXX_FLAGS_ASAN) + set(CMAKE_CXX_FLAGS_ASAN ${ASAN_CXX_FLAGS} CACHE STRING "Flags used by the CXX compiler during ASAN builds." FORCE) + endif() + endif() + unset(CMAKE_REQUIRED_LINK_OPTIONS) +endif() + diff --git a/test/API/CMake/CheckUbsan.cmake b/test/API/CMake/CheckUbsan.cmake new file mode 100644 index 0000000..f2b9c2c --- /dev/null +++ b/test/API/CMake/CheckUbsan.cmake @@ -0,0 +1,37 @@ +set(UBSAN_FLAG "-fsanitize=undefined") +set(UBSAN_C_FLAGS "-O1 -g ${UBSAN_FLAG} -fno-omit-frame-pointer") +set(UBSAN_CXX_FLAGS ${UBSAN_C_FLAGS}) + +get_property(UBSAN_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES) +foreach(lang ${UBSAN_LANGUAGES}) + set(UBSAN_${lang}_LANG_ENABLED 1) +endforeach() + +if(UBSAN_C_LANG_ENABLED) + include(CheckCCompilerFlag) + set(CMAKE_REQUIRED_LINK_OPTIONS ${UBSAN_FLAG}) + check_c_compiler_flag(${UBSAN_FLAG} UBSAN_C_FLAG_SUPPORTED) + if(NOT UBSAN_C_FLAG_SUPPORTED) + message(STATUS "Ubsan flags are not supported by the C compiler.") + else() + if(NOT CMAKE_C_FLAGS_UBSAN) + set(CMAKE_C_FLAGS_UBSAN ${UBSAN_C_FLAGS} CACHE STRING "Flags used by the C compiler during UBSAN builds." FORCE) + endif() + endif() + unset(CMAKE_REQUIRED_LINK_OPTIONS) +endif() + +if(UBSAN_CXX_LANG_ENABLED) + include(CheckCXXCompilerFlag) + set(CMAKE_REQUIRED_LINK_OPTIONS ${UBSAN_FLAG}) + check_cxx_compiler_flag(${UBSAN_FLAG} UBSAN_CXX_FLAG_SUPPORTED) + if(NOT UBSAN_CXX_FLAG_SUPPORTED) + message(STATUS "Ubsan flags are not supported by the CXX compiler.") + else() + if(NOT CMAKE_CXX_FLAGS_UBSAN) + set(CMAKE_CXX_FLAGS_UBSAN ${UBSAN_CXX_FLAGS} CACHE STRING "Flags used by the CXX compiler during UBSAN builds." FORCE) + endif() + endif() + unset(CMAKE_REQUIRED_LINK_OPTIONS) +endif() + |