if( NOT MSVC )
add_definitions( -D_DEBUG )
endif()
- # On Release builds cmake automatically defines NDEBUG, so we
+ # On non-Debug builds cmake automatically defines NDEBUG, so we
# explicitly undefine it:
- if( uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
+ if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
add_definitions( -UNDEBUG )
+ # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
+ string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
+ CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
endif()
else()
if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
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)
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
if( MSVC )
include(ChooseMSVCCRT)
- if( MSVC11 )
+ if( MSVC10 )
+ # MSVC 10 will complain about headers in the STL not being exported, but
+ # will not complain in MSVC 11.
+ add_llvm_definitions(
+ -wd4275 # Suppress 'An exported class was derived from a class that was not exported.'
+ )
+ elseif( MSVC11 )
add_llvm_definitions(-D_VARIADIC_MAX=10)
endif()
-
+
# Add definitions that make MSVC much less annoying.
add_llvm_definitions(
# For some reason MS wants to deprecate a bunch of standard functions...
-D_SCL_SECURE_NO_WARNINGS
# Disabled warnings.
- -wd4065 # Suppress 'switch statement contains 'default' but no 'case' labels'
-wd4146 # Suppress 'unary minus operator applied to unsigned type, result still unsigned'
-wd4180 # Suppress 'qualifier applied to function type has no meaning; ignored'
- -wd4181 # Suppress 'qualifier applied to reference type; ignored'
- -wd4224 # Suppress 'nonstandard extension used : formal parameter 'identifier' was previously defined as a type'
-wd4244 # Suppress ''argument' : conversion from 'type1' to 'type2', possible loss of data'
-wd4267 # Suppress ''var' : conversion from 'size_t' to 'type', possible loss of data'
- -wd4275 # Suppress 'An exported class was derived from a class that was not exported.'
- -wd4291 # Suppress ''declaration' : no matching operator delete found; memory will not be freed if initialization throws an exception'
-wd4345 # Suppress 'behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized'
-wd4351 # Suppress 'new behavior: elements of array 'array' will be default initialized'
-wd4355 # Suppress ''this' : used in base member initializer list'
-wd4503 # Suppress ''identifier' : decorated name length exceeded, name was truncated'
- -wd4551 # Suppress 'function call missing argument list'
-wd4624 # Suppress ''derived class' : destructor could not be generated because a base class destructor is inaccessible'
- -wd4715 # Suppress ''function' : not all control paths return a value'
- -wd4722 # Suppress ''function' : destructor never returns, potential memory leak'
-wd4800 # Suppress ''type' : forcing value to bool 'true' or 'false' (performance warning)'
-
+
# Promoted warnings.
-w14062 # Promote 'enumerator in switch of enum is not handled' to level 1 warning.
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")
+ 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()
+
+# Turn on -gsplit-dwarf if requested
+if(LLVM_USE_SPLIT_DWARF)
+ add_flag_if_supported("-gsplit-dwarf")
+endif()
+
add_llvm_definitions( -D__STDC_CONSTANT_MACROS )
add_llvm_definitions( -D__STDC_FORMAT_MACROS )
add_llvm_definitions( -D__STDC_LIMIT_MACROS )
+
+# clang doesn't print colored diagnostics when invoked from Ninja
+if (UNIX AND
+ CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
+ CMAKE_GENERATOR STREQUAL "Ninja")
+ append("-fcolor-diagnostics" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+endif()