[PATCH] D13605: [CMake] [Darwin] Add support for generating Xcode-compatible toolchains that xcodebuild and xcrun can search

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 14:00:15 PDT 2015


beanz created this revision.
beanz added a reviewer: Bigcheese.
beanz added a subscriber: llvm-commits.

Sometimes you want to install a custom compiler and use it like the system compiler without overriding the system compiler. This patch lets you create xctoolchains that the darwin command line tools can use.

To use this patch set LLVM_CREATE_XCODE_TOOLCHAIN=On in your CMake invocation and build the `install-code-toolchain` target.

After installation you can set the envar EXTERNAL_TOOLCHAINS_DIR to your installed Toolchains directory, and the TOOLCHAINS envar to the toolchain identifier (ex org.llvm.3.8.0svn). This will then cause /usr/bin/clang to call your newly installed clang.

http://reviews.llvm.org/D13605

Files:
  tools/xcode-toolchain/CMakeLists.txt

Index: tools/xcode-toolchain/CMakeLists.txt
===================================================================
--- /dev/null
+++ tools/xcode-toolchain/CMakeLists.txt
@@ -0,0 +1,62 @@
+# OS X 10.11 El Capitan has just been released. One of the new features, System
+# Integrity Protection, prevents modifying the base OS install, even with sudo.
+# This prevents LLVM developers on OS X from being able to easily install new
+# system compilers. The feature can be disabled, but to make it easier for
+# developers to work without disabling SIP, this file can generate an Xcode
+# toolchain. Xcode toolchains are a mostly-undocumented feature that allows
+# multiple copies of low level tools to be installed to different locations, and
+# users can easily switch between them.
+
+# Setting an environment variable TOOLCHAINS to the toolchain's identifier will
+# result in /usr/bin/<tool> or xcrun <tool> to find the tool in the toolchain.
+
+# To make this work with Xcode 7.1 and later you can install the toolchain this
+# file generates anywhere on your system and set EXTERNAL_TOOLCHAINS_DIR to the
+# path specified by $CMAKE_INSTALL_PREFIX/Toolchains
+
+# This file generates a custom install-xcode-toolchain target which constructs
+# and installs a toolchain with the identifier in the pattern:
+# org.llvm.${PACKAGE_VERSION}. This toolchain can then be used to override the
+# system compiler by setting TOOLCHAINS=org.llvm.${PACKAGE_VERSION} in the
+# in the environment.
+
+if(NOT APPLE)
+  return()
+endif()
+
+option(LLVM_CREATE_XCODE_TOOLCHAIN "Create a target to install LLVM into an Xcode toolchain" Off)
+
+if(NOT LLVM_CREATE_XCODE_TOOLCHAIN)
+  return()
+endif()
+
+execute_process(
+  COMMAND xcodebuild -find clang
+  OUTPUT_VARIABLE clang_path
+  OUTPUT_STRIP_TRAILING_WHITESPACE
+  ERROR_FILE /dev/null
+)
+string(REGEX MATCH "(.*Toolchains).*" toolchains_match ${clang_path})
+if(NOT toolchains_match)
+  message(FATAL_ERROR "Could not identify toolchain dir")
+endif()
+set(toolchains_dir ${CMAKE_MATCH_1})
+
+set(XcodeDefaultInfo "${toolchains_dir}/XcodeDefault.xctoolchain/ToolchainInfo.plist")
+set(LLVMToolchainDir "${CMAKE_INSTALL_PREFIX}/Toolchains/LLVM${PACKAGE_VERSION}.xctoolchain/")
+
+add_custom_command(OUTPUT ${LLVMToolchainDir}
+                    COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVMToolchainDir})
+
+add_custom_command(OUTPUT ${LLVMToolchainDir}/ToolchainInfo.plist
+                  DEPENDS ${LLVMToolchainDir}
+                  COMMAND ${CMAKE_COMMAND} -E copy "${XcodeDefaultInfo}" "${LLVMToolchainDir}/ToolchainInfo.plist"
+                  COMMAND /usr/libexec/PlistBuddy -c "Set:Identifier org.llvm.${PACKAGE_VERSION}" "${LLVMToolchainDir}/ToolchainInfo.plist")
+
+add_custom_target(install-xcode-toolchain
+                  DEPENDS ${LLVMToolchainDir}/ToolchainInfo.plist
+                  COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target all
+                  COMMAND "${CMAKE_COMMAND}"
+                          -DCMAKE_INSTALL_PREFIX=${LLVMToolchainDir}/usr/
+                          -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
+                  ${cmake_3_2_USES_TERMINAL})


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13605.36988.patch
Type: text/x-patch
Size: 3166 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151009/c0284a4b/attachment.bin>


More information about the llvm-commits mailing list