aboutsummaryrefslogtreecommitdiff
path: root/cmake/modules/HandleLLVMOptions.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/modules/HandleLLVMOptions.cmake')
-rw-r--r--cmake/modules/HandleLLVMOptions.cmake45
1 files changed, 42 insertions, 3 deletions
diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
index 528320b94e..4e59a3e3d9 100644
--- a/cmake/modules/HandleLLVMOptions.cmake
+++ b/cmake/modules/HandleLLVMOptions.cmake
@@ -60,9 +60,9 @@ else(WIN32)
endif(WIN32)
function(add_flag_or_print_warning flag)
- check_c_compiler_flag(${flag} C_SUPPORTS_${flag})
- check_cxx_compiler_flag(${flag} CXX_SUPPORTS_${flag})
- if (C_SUPPORTS_${flag} AND CXX_SUPPORTS_${flag})
+ check_c_compiler_flag(${flag} C_SUPPORTS_FLAG)
+ check_cxx_compiler_flag(${flag} CXX_SUPPORTS_FLAG)
+ if (C_SUPPORTS_FLAG AND CXX_SUPPORTS_FLAG)
message(STATUS "Building with ${flag}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
@@ -85,6 +85,13 @@ function(append_if condition value)
endif()
endfunction()
+macro(add_flag_if_supported flag)
+ check_c_compiler_flag(${flag} C_SUPPORTS_FLAG)
+ append_if(C_SUPPORTS_FLAG "${flag}" CMAKE_C_FLAGS)
+ check_cxx_compiler_flag(${flag} CXX_SUPPORTS_FLAG)
+ append_if(CXX_SUPPORTS_FLAG "${flag}" CMAKE_CXX_FLAGS)
+endmacro()
+
if( LLVM_ENABLE_PIC )
if( XCODE )
# Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
@@ -223,6 +230,38 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
endif (LLVM_ENABLE_WERROR)
endif( MSVC )
+macro(append_common_sanitizer_flags)
+ # Append -fno-omit-frame-pointer and turn on debug info to get better
+ # stack traces.
+ add_flag_if_supported("-fno-omit-frame-pointer")
+ if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
+ NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
+ add_flag_if_supported("-gline-tables-only")
+ endif()
+endmacro()
+
+# Turn on sanitizers if necessary.
+if(LLVM_USE_SANITIZER)
+ if (LLVM_ON_UNIX)
+ if (LLVM_USE_SANITIZER STREQUAL "Address")
+ append_common_sanitizer_flags()
+ add_flag_or_print_warning("-fsanitize=address")
+ elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
+ append_common_sanitizer_flags()
+ add_flag_or_print_warning("-fsanitize=memory")
+ # -pie is required for MSan.
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
+ if(LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins")
+ add_flag_or_print_warning("-fsanitize-memory-track-origins")
+ endif()
+ else()
+ message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
+ endif()
+ else()
+ message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
+ endif()
+endif()
+
add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
add_llvm_definitions( -D__STDC_FORMAT_MACROS )
add_llvm_definitions( -D__STDC_LIMIT_MACROS )