Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -270,27 +270,16 @@ append_list_if(COMPILER_RT_HAS_WD4722_FLAG /wd4722 SANITIZER_COMMON_CFLAGS) append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS) if(APPLE) - macro(find_darwin_sdk_dir var sdk_name) - # Let's first try the internal SDK, otherwise use the public SDK. - execute_process( - COMMAND xcodebuild -version -sdk ${sdk_name}.internal Path - OUTPUT_VARIABLE ${var} - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_FILE /dev/null - ) - if(${var} STREQUAL "") - execute_process( - COMMAND xcodebuild -version -sdk ${sdk_name} Path - OUTPUT_VARIABLE ${var} - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_FILE /dev/null - ) - endif() - endmacro() + include(CompilerRTDarwinUtils) + + option(COMPILER_RT_ENABLE_IOS "Enable building for iOS - Experimental" Off) find_darwin_sdk_dir(OSX_SDK_DIR macosx) find_darwin_sdk_dir(IOSSIM_SDK_DIR iphonesimulator) + find_darwin_sdk_dir(IOS_SDK_DIR iphoneos) + # Note: In order to target x86_64h on OS X the minimum deployment target must + # be 10.8 or higher. set(SANITIZER_COMMON_SUPPORTED_OS osx) string(REGEX MATCH "-mmacosx-version-min=([.0-9]+)" MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}") @@ -300,32 +289,78 @@ set(SANITIZER_MIN_OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET}) else() set(SANITIZER_MIN_OSX_VERSION 10.9) - if(IOSSIM_SDK_DIR) - list(APPEND SANITIZER_COMMON_SUPPORTED_OS iossim) - endif() endif() if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7") message(FATAL_ERROR "Too old OS X version: ${SANITIZER_MIN_OSX_VERSION}") endif() - set(CMAKE_OSX_DEPLOYMENT_TARGET "") # We evaluate target OS X version above. - set(DARWIN_osx_CFLAGS -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION} - -stdlib=libc++) - set(DARWIN_iossim_CFLAGS + set(CMAKE_OSX_DEPLOYMENT_TARGET "") # We're setting the flag manually for each target OS + + set(DARWIN_COMMON_CFLAGS -stdlib=libc++) + set(DARWIN_COMMON_LINKFLAGS -stdlib=libc++ - -mios-simulator-version-min=7.0 -isysroot ${IOSSIM_SDK_DIR}) - set(DARWIN_osx_LINKFLAGS -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION} - -stdlib=libc++ -lc++ -lc++abi) - set(DARWIN_iossim_LINKFLAGS - -stdlib=libc++ -lc++ -lc++abi - -Wl,-ios_simulator_version_min,7.0.0 - -mios-simulator-version-min=7.0 - -isysroot ${IOSSIM_SDK_DIR}) + -lc++ + -lc++abi) + + set(DARWIN_osx_CFLAGS + ${DARWIN_COMMON_CFLAGS} + -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION}) + set(DARWIN_osx_LINKFLAGS + ${DARWIN_COMMON_LINKFLAGS} + -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION}) if(OSX_SDK_DIR) list(APPEND DARWIN_osx_CFLAGS -isysroot ${OSX_SDK_DIR}) list(APPEND DARWIN_osx_LINKFLAGS -isysroot ${OSX_SDK_DIR}) endif() + + # Figure out which arches to use for each OS + darwin_get_toolchain_supported_archs(toolchain_arches) + message(STATUS "Toolchain supported arches: ${toolchain_arches}") + + if(NOT MACOSX_VERSION_MIN_FLAG) + darwin_test_archs(osx + SANITIZER_COMMON_DARWIN_osx_ARCHES + ${toolchain_arches}) + message(STATUS "OSX supported arches: ${SANITIZER_COMMON_DARWIN_osx_ARCHES}") + + if(IOSSIM_SDK_DIR) + set(DARWIN_iossim_CFLAGS + ${DARWIN_COMMON_CFLAGS} + -mios-simulator-version-min=7.0 + -isysroot ${IOSSIM_SDK_DIR}) + set(DARWIN_iossim_LINKFLAGS + ${DARWIN_COMMON_LINKFLAGS} + -Wl,-ios_simulator_version_min,7.0.0 + -mios-simulator-version-min=7.0 + -isysroot ${IOSSIM_SDK_DIR}) + + list(APPEND SANITIZER_COMMON_SUPPORTED_OS iossim) + darwin_test_archs(iossim + SANITIZER_COMMON_DARWIN_iossim_ARCHES + ${toolchain_arches}) + message(STATUS "iOS Simulator supported arches: ${SANITIZER_COMMON_DARWIN_iossim_ARCHES}") + endif() + + if(IOS_SDK_DIR AND COMPILER_RT_ENABLE_IOS) + set(DARWIN_ios_CFLAGS + ${DARWIN_COMMON_CFLAGS} + -miphoneos-version-min=7.0 + -isysroot ${IOS_SDK_DIR}) + set(DARWIN_ios_LINKFLAGS + ${DARWIN_COMMON_LINKFLAGS} + -Wl,-ios_version_min,7.0.0 + -miphoneos-version-min=7.0 + -isysroot ${IOS_SDK_DIR}) + + list(APPEND SANITIZER_COMMON_SUPPORTED_OS ios) + darwin_test_archs(ios + SANITIZER_COMMON_DARWIN_ios_ARCHES + ${toolchain_arches}) + message(STATUS "iOS supported arches: ${SANITIZER_COMMON_DARWIN_ios_ARCHES}") + endif() + endif() + endif() if(APPLE AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9")