[llvm] r279152 - [CMake] Support for generating Xcode 8 compatible toolchains

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 18 14:32:48 PDT 2016


Author: cbieneman
Date: Thu Aug 18 16:32:48 2016
New Revision: 279152

URL: http://llvm.org/viewvc/llvm-project?rev=279152&view=rev
Log:
[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.

Modified:
    llvm/trunk/tools/xcode-toolchain/CMakeLists.txt

Modified: llvm/trunk/tools/xcode-toolchain/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/xcode-toolchain/CMakeLists.txt?rev=279152&r1=279151&r2=279152&view=diff
==============================================================================
--- llvm/trunk/tools/xcode-toolchain/CMakeLists.txt (original)
+++ llvm/trunk/tools/xcode-toolchain/CMakeLists.txt Thu Aug 18 16:32:48 2016
@@ -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 ${LLVMToolchai
                   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




More information about the llvm-commits mailing list