brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.8 KiB · 6167f5f Raw
118 lines · plain
1# OS X 10.11 El Capitan has just been released. One of the new features, System2# Integrity Protection, prevents modifying the base OS install, even with sudo.3# This prevents LLVM developers on OS X from being able to easily install new4# system compilers. The feature can be disabled, but to make it easier for5# developers to work without disabling SIP, this file can generate an Xcode6# toolchain. Xcode toolchains are a mostly-undocumented feature that allows7# multiple copies of low level tools to be installed to different locations, and8# users can easily switch between them.9 10# Setting an environment variable TOOLCHAINS to the toolchain's identifier will11# result in /usr/bin/<tool> or xcrun <tool> to find the tool in the toolchain.12 13# To make this work with Xcode 7.1 and later you can install the toolchain this14# file generates anywhere on your system and set EXTERNAL_TOOLCHAINS_DIR to the15# path specified by $CMAKE_INSTALL_PREFIX/Toolchains16 17# This file generates a custom install-xcode-toolchain target which constructs18# and installs a toolchain with the identifier in the pattern:19# org.llvm.${PACKAGE_VERSION}. This toolchain can then be used to override the20# system compiler by setting TOOLCHAINS=org.llvm.${PACKAGE_VERSION} in the21# in the environment.22 23# Example usage:24# cmake -G Ninja -DLLVM_CREATE_XCODE_TOOLCHAIN=On25#   -DCMAKE_INSTALL_PREFIX=$PWD/install26# ninja install-xcode-toolchain27# export EXTERNAL_TOOLCHAINS_DIR=$PWD/install/Toolchains28# export TOOLCHAINS=org.llvm.3.8.0svn29 30# `xcrun -find clang` should return the installed clang, and `clang --version`31# should show 3.8.0svn.32 33if(NOT APPLE)34  return()35endif()36 37option(LLVM_CREATE_XCODE_TOOLCHAIN "Create a target to install LLVM into an Xcode toolchain" Off)38 39if(NOT LLVM_CREATE_XCODE_TOOLCHAIN)40  return()41endif()42 43# XCODE_VERSION is set by CMake when using the Xcode generator, otherwise we need44# to detect it manually here.45if(NOT XCODE_VERSION)46  execute_process(47    COMMAND xcodebuild -version48    OUTPUT_VARIABLE xcodebuild_version49    OUTPUT_STRIP_TRAILING_WHITESPACE50    ERROR_FILE /dev/null51  )52  string(REGEX MATCH "Xcode ([0-9][0-9]?([.][0-9])+)" version_match ${xcodebuild_version})53  if(version_match)54    message(STATUS "Identified Xcode Version: ${CMAKE_MATCH_1}")55    set(XCODE_VERSION ${CMAKE_MATCH_1})56  else()57    # If detecting Xcode version failed, set a crazy high version so we default58    # to the newest.59    set(XCODE_VERSION 99)60    message(WARNING "Failed to detect the version of an installed copy of Xcode, falling back to highest supported version. Set XCODE_VERSION to override.")61  endif()62endif()63 64# Xcode 8 requires CompatibilityVersion 265set(COMPAT_VERSION 2)66if(XCODE_VERSION VERSION_LESS 8.0.0)67  # Xcode 7.3 (the first version supporting external toolchains) requires68  # CompatibilityVersion 169  set(COMPAT_VERSION 1)70endif()71 72execute_process(73  COMMAND xcrun -find otool74  OUTPUT_VARIABLE clang_path75  OUTPUT_STRIP_TRAILING_WHITESPACE76  ERROR_FILE /dev/null77)78string(REGEX MATCH "(.*/Toolchains)/.*" toolchains_match ${clang_path})79if(NOT toolchains_match)80  message(FATAL_ERROR "Could not identify toolchain dir")81endif()82set(toolchains_dir ${CMAKE_MATCH_1})83 84set(LLVMToolchainDir "${CMAKE_INSTALL_PREFIX}/Toolchains/LLVM${PACKAGE_VERSION}.xctoolchain/")85 86add_custom_command(OUTPUT ${LLVMToolchainDir}87                    COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVMToolchainDir})88 89add_custom_command(OUTPUT ${LLVMToolchainDir}/Info.plist90                  DEPENDS ${LLVMToolchainDir}91                  COMMAND ${CMAKE_COMMAND} -E remove ${LLVMToolchainDir}/Info.plist92                  COMMAND /usr/libexec/PlistBuddy -c "Add:CFBundleIdentifier string org.llvm.${PACKAGE_VERSION}" "${LLVMToolchainDir}/Info.plist"93                  COMMAND /usr/libexec/PlistBuddy -c "Add:CompatibilityVersion integer ${COMPAT_VERSION}" "${LLVMToolchainDir}/Info.plist"94                  )95 96add_custom_target(build-xcode-toolchain97                  COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target all)98add_llvm_install_targets(install-xcode-toolchain99                         DEPENDS ${LLVMToolchainDir}/Info.plist build-xcode-toolchain100                         PREFIX ${LLVMToolchainDir}/usr/)101 102if(LLVM_DISTRIBUTION_COMPONENTS)103  if(LLVM_ENABLE_IDE)104    message(FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS cannot be specified with multi-configuration generators (i.e. Xcode or Visual Studio)")105  endif()106 107  add_custom_target(install-distribution-toolchain108                  DEPENDS ${LLVMToolchainDir}/Info.plist distribution)109 110  foreach(target ${LLVM_DISTRIBUTION_COMPONENTS})111    add_llvm_install_targets(install-distribution-${target}112                             DEPENDS ${target}113                             COMPONENT ${target}114                             PREFIX ${LLVMToolchainDir}/usr/)115    add_dependencies(install-distribution-toolchain install-distribution-${target})116  endforeach()117endif()118