diff --git a/config/sanitizer/sanitizers.cmake b/config/sanitizer/sanitizers.cmake index 72f101f4c25..91768240fb2 100644 --- a/config/sanitizer/sanitizers.cmake +++ b/config/sanitizer/sanitizers.cmake @@ -43,11 +43,17 @@ function(test_san_flags return_var flags) set(FLAGS_BACKUP ${CMAKE_REQUIRED_FLAGS}) set(CMAKE_REQUIRED_FLAGS "${flags}") check_c_source_compiles("int main() { return 0; }" ${return_var}) + if(CMAKE_CXX_COMPILER_LOADED) + check_cxx_source_compiles("int main() { return 0; }" ${return_var}) + endif() set(CMAKE_REQUIRED_FLAGS "${FLAGS_BACKUP}") set(CMAKE_REQUIRED_QUIET "${QUIET_BACKUP}") endfunction() message(STATUS "USE_SANITIZER=${USE_SANITIZER}, CMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}") +if(CMAKE_CXX_COMPILER_LOADED) + message(STATUS "... CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}") +endif() if(USE_SANITIZER) if(CMAKE_C_COMPILER_ID MATCHES "IntelLLVM" OR CMAKE_C_COMPILER_ID MATCHES "[Cc]lang") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -79,9 +85,15 @@ if(USE_SANITIZER) if(AFL) append_quoteless(AFL_USE_ASAN=1 CMAKE_C_COMPILER_LAUNCHER) + if (CMAKE_CXX_COMPILER_LOADED) + append_quoteless(AFL_USE_ASAN=1 CMAKE_CXX_COMPILER_LAUNCHER) + endif () endif() else() message(FATAL_ERROR "Address sanitizer not available for ${CMAKE_C_COMPILER}") + if (CMAKE_CXX_COMPILER_LOADED) + message(FATAL_ERROR "Address sanitizer not available for ${CMAKE_CXX_COMPILER}") + endif () endif() endif() @@ -104,9 +116,15 @@ if(USE_SANITIZER) if(AFL) append_quoteless(AFL_USE_MSAN=1 CMAKE_C_COMPILER_LAUNCHER) + if (CMAKE_CXX_COMPILER_LOADED) + append_quoteless(AFL_USE_MSAN=1 CMAKE_CXX_COMPILER_LAUNCHER) + endif () endif() else() message(FATAL_ERROR "Memory [With Origins] sanitizer not available for ${CMAKE_C_COMPILER}") + if (CMAKE_CXX_COMPILER_LOADED) + message(FATAL_ERROR "Memory [With Origins] sanitizer not available for ${CMAKE_CXX_COMPILER}") + endif () endif() endif() @@ -123,9 +141,15 @@ if(USE_SANITIZER) if(AFL) append_quoteless(AFL_USE_UBSAN=1 CMAKE_C_COMPILER_LAUNCHER) + if (CMAKE_CXX_COMPILER_LOADED) + append_quoteless(AFL_USE_UBSAN=1 CMAKE_CXX_COMPILER_LAUNCHER) + endif () endif() else() message(FATAL_ERROR "Undefined Behaviour sanitizer not available for ${CMAKE_C_COMPILER}") + if (CMAKE_CXX_COMPILER_LOADED) + message(FATAL_ERROR "Undefined Behaviour sanitizer not available for ${CMAKE_CXX_COMPILER}") + endif () endif() endif() @@ -139,9 +163,15 @@ if(USE_SANITIZER) if(AFL) append_quoteless(AFL_USE_TSAN=1 CMAKE_C_COMPILER_LAUNCHER) + if (CMAKE_CXX_COMPILER_LOADED) + append_quoteless(AFL_USE_TSAN=1 CMAKE_CXX_COMPILER_LAUNCHER) + endif () endif() else() message(FATAL_ERROR "Thread sanitizer not available for ${CMAKE_C_COMPILER}") + if (CMAKE_CXX_COMPILER_LOADED) + message(FATAL_ERROR "Thread sanitizer not available for ${CMAKE_CXX_COMPILER}") + endif () endif() endif() @@ -155,9 +185,15 @@ if(USE_SANITIZER) if(AFL) append_quoteless(AFL_USE_LSAN=1 CMAKE_C_COMPILER_LAUNCHER) + if (CMAKE_CXX_COMPILER_LOADED) + append_quoteless(AFL_USE_LSAN=1 CMAKE_CXX_COMPILER_LAUNCHER) + endif () endif() else() message(FATAL_ERROR "Thread sanitizer not available for ${CMAKE_C_COMPILER}") + if (CMAKE_CXX_COMPILER_LOADED) + message(FATAL_ERROR "Thread sanitizer not available for ${CMAKE_CXX_COMPILER}") + endif () endif() endif() @@ -171,9 +207,15 @@ if(USE_SANITIZER) if(AFL) append_quoteless(AFL_USE_CFISAN=1 CMAKE_C_COMPILER_LAUNCHER) + if (CMAKE_CXX_COMPILER_LOADED) + append_quoteless(AFL_USE_CFISAN=1 CMAKE_CXX_COMPILER_LAUNCHER) + endif () endif() else() message(FATAL_ERROR "Control Flow Integrity(CFI) sanitizer not available for ${CMAKE_C_COMPILER}") + if (CMAKE_CXX_COMPILER_LOADED) + message(FATAL_ERROR "Control Flow Integrity(CFI) sanitizer not available for ${CMAKE_CXX_COMPILER}") + endif () endif() endif() @@ -198,6 +240,9 @@ if(USE_SANITIZER) if(AFL) append_quoteless(AFL_USE_ASAN=1 CMAKE_C_COMPILER_LAUNCHER) + if (CMAKE_CXX_COMPILER_LOADED) + append_quoteless(AFL_USE_ASAN=1 CMAKE_CXX_COMPILER_LAUNCHER) + endif () endif() else() message(FATAL_ERROR "This sanitizer not yet supported in the MSVC environment: ${USE_SANITIZER}") diff --git a/config/toolchain/clang.cmake b/config/toolchain/clang.cmake index 2d35641a14c..2a856077f11 100644 --- a/config/toolchain/clang.cmake +++ b/config/toolchain/clang.cmake @@ -9,6 +9,7 @@ if(WIN32) else() set (CMAKE_C_COMPILER clang) set (CMAKE_CXX_COMPILER clang++) + #set (CMAKE_Fortran_COMPILER flang-new) endif() set (CMAKE_EXPORT_COMPILE_COMMANDS ON)