[CMake] Support for generating Xcode 8 compatible toolchains

Xcode 8 requires toolchain compatibility version 2. This allows us to select the correct compatibility version based on the installed version of Xcode.

llvm-svn: 279152
This commit is contained in:
Chris Bieneman 2016-08-18 21:32:48 +00:00
parent 6a78dccd95
commit ab28de8c4f

View File

@ -40,6 +40,35 @@ if(NOT LLVM_CREATE_XCODE_TOOLCHAIN)
return()
endif()
# XCODE_VERSION is set by CMake when using the Xcode generator, otherwise we need
# to detect it manually here.
if(NOT XCODE_VERSION)
execute_process(
COMMAND xcodebuild -version
OUTPUT_VARIABLE xcodebuild_version
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_FILE /dev/null
)
string(REGEX MATCH "Xcode ([0-9][.][0-9][.][0-9])" version_match ${xcodebuild_version})
if(version_match)
message(STATUS "Identified Xcode Version: ${CMAKE_MATCH_1}")
set(XCODE_VERSION ${CMAKE_MATCH_1})
else()
# If detecting Xcode version failed, set a crazy high version so we default
# to the newest.
set(XCODE_VERSION 99)
message(WARNING "Failed to detect the version of an installed copy of Xcode, falling back to highest supported version. Set XCODE_VERSION to override.")
endif()
endif()
# Xcode 8 requires CompatibilityVersion 2
set(COMPAT_VERSION 2)
if(XCODE_VERSION VERSION_LESS 8.0.0)
# Xcode 7.3 (the first version supporting external toolchains) requires
# CompatibilityVersion 1
set(COMPAT_VERSION 1)
endif()
execute_process(
COMMAND xcrun -find otool
OUTPUT_VARIABLE clang_path
@ -61,7 +90,7 @@ add_custom_command(OUTPUT ${LLVMToolchainDir}/Info.plist
DEPENDS ${LLVMToolchainDir}
COMMAND ${CMAKE_COMMAND} -E remove ${LLVMToolchainDir}/Info.plist
COMMAND /usr/libexec/PlistBuddy -c "Add:CFBundleIdentifier string org.llvm.${PACKAGE_VERSION}" "${LLVMToolchainDir}/Info.plist"
COMMAND /usr/libexec/PlistBuddy -c "Add:CompatibilityVersion integer 1" "${LLVMToolchainDir}/Info.plist"
COMMAND /usr/libexec/PlistBuddy -c "Add:CompatibilityVersion integer ${COMPAT_VERSION}" "${LLVMToolchainDir}/Info.plist"
)
add_custom_target(install-xcode-toolchain