[CMake] set -mmacosx-version-min to 10.7 if compiler-rt is built with -stdlib=libc++
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@174699 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bd4295e..90062cd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -101,6 +101,10 @@
set(COMPILER_RT_CAN_EXECUTE_TESTS FALSE)
endif()
+# Check if compiler-rt is built with libc++.
+find_flag_in_string("${CMAKE_CXX_FLAGS}" "-stdlib=libc++"
+ COMPILER_RT_USES_LIBCXX)
+
function(filter_available_targets out_var)
set(archs)
foreach(arch ${ARGN})
@@ -140,8 +144,16 @@
if(SUPPORTS_NO_C99_EXTENSIONS_FLAG)
list(APPEND SANITIZER_COMMON_CFLAGS -Wno-c99-extensions)
endif()
+
+# Setup min Mac OS X version.
if(APPLE)
- list(APPEND SANITIZER_COMMON_CFLAGS -mmacosx-version-min=10.5)
+ if(COMPILER_RT_USES_LIBCXX)
+ set(SANITIZER_MIN_OSX_VERSION 10.7)
+ else()
+ set(SANITIZER_MIN_OSX_VERSION 10.5)
+ endif()
+ list(APPEND SANITIZER_COMMON_CFLAGS
+ -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
endif()
# Architectures supported by Sanitizer runtimes. Specific sanitizers may
diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake
index 50f0680..f9760f4 100644
--- a/cmake/Modules/CompilerRTUtils.cmake
+++ b/cmake/Modules/CompilerRTUtils.cmake
@@ -15,3 +15,14 @@
set_property(TARGET ${target} PROPERTY LINK_FLAGS "${argstring}")
endfunction()
+# Check if a given flag is present in a space-separated flag_string.
+# Store the result in out_var.
+function(find_flag_in_string flag_string flag out_var)
+ string(REPLACE " " ";" flag_list ${flag_string})
+ list(FIND flag_list ${flag} flag_pos)
+ if(NOT flag_pos EQUAL -1)
+ set(${out_var} TRUE PARENT_SCOPE)
+ else()
+ set(${out_var} FALSE PARENT_SCOPE)
+ endif()
+endfunction()