2015-10-16 04:09:01 +08:00
# 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.
# Example usage:
# cmake -G Ninja -DLLVM_CREATE_XCODE_TOOLCHAIN=On
# -DCMAKE_INSTALL_PREFIX=$PWD/install
# ninja install-xcode-toolchain
# export EXTERNAL_TOOLCHAINS_DIR=$PWD/install/Toolchains
# export TOOLCHAINS=org.llvm.3.8.0svn
# `xcrun -find clang` should return the installed clang, and `clang --version`
# should show 3.8.0svn.
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 ( )
2016-08-19 05:32:48 +08:00
# 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 (
C O M M A N D x c o d e b u i l d - v e r s i o n
O U T P U T _ V A R I A B L E x c o d e b u i l d _ v e r s i o n
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
E R R O R _ F I L E / d e v / n u l l
)
2018-06-28 08:39:09 +08:00
string ( REGEX MATCH "Xcode ([0-9][0-9]?([.][0-9])+)" version_match ${ xcodebuild_version } )
2016-08-19 05:32:48 +08:00
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 ( )
2015-10-16 04:09:01 +08:00
execute_process (
C O M M A N D x c r u n - f i n d o t o o l
O U T P U T _ V A R I A B L E c l a n g _ p a t h
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
E R R O R _ F I L E / d e v / n u l l
)
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 ( LLVMToolchainDir "${CMAKE_INSTALL_PREFIX}/Toolchains/LLVM${PACKAGE_VERSION}.xctoolchain/" )
add_custom_command ( OUTPUT ${ LLVMToolchainDir }
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y $ { L L V M T o o l c h a i n D i r } )
2016-07-26 08:47:52 +08:00
add_custom_command ( OUTPUT ${ LLVMToolchainDir } /Info.plist
2015-10-16 04:09:01 +08:00
D E P E N D S $ { L L V M T o o l c h a i n D i r }
2016-07-26 08:47:52 +08:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e $ { L L V M T o o l c h a i n D i r } / I n f o . p l i s t
C O M M A N D / u s r / l i b e x e c / P l i s t B u d d y - c " A d d : C F B u n d l e I d e n t i f i e r s t r i n g o r g . l l v m . $ { P A C K A G E _ V E R S I O N } " " $ { L L V M T o o l c h a i n D i r } / I n f o . p l i s t "
2016-08-19 05:32:48 +08:00
C O M M A N D / u s r / l i b e x e c / P l i s t B u d d y - c " A d d : C o m p a t i b i l i t y V e r s i o n i n t e g e r $ { C O M P A T _ V E R S I O N } " " $ { L L V M T o o l c h a i n D i r } / I n f o . p l i s t "
2016-07-26 08:47:52 +08:00
)
2015-10-16 04:09:01 +08:00
2017-12-01 05:48:26 +08:00
add_custom_target ( build-xcode-toolchain
C O M M A N D " $ { C M A K E _ C O M M A N D } " - - b u i l d $ { C M A K E _ B I N A R Y _ D I R } - - t a r g e t a l l )
add_llvm_install_targets ( install-xcode-toolchain
D E P E N D S $ { L L V M T o o l c h a i n D i r } / I n f o . p l i s t b u i l d - x c o d e - t o o l c h a i n
P R E F I X $ { L L V M T o o l c h a i n D i r } / u s r / )
2016-04-30 06:19:35 +08:00
if ( LLVM_DISTRIBUTION_COMPONENTS )
2018-08-30 17:32:09 +08:00
if ( CMAKE_CONFIGURATION_TYPES )
2016-04-30 06:19:35 +08:00
message ( FATAL_ERROR "LLVM_DISTRIBUTION_COMPONENTS cannot be specified with multi-configuration generators (i.e. Xcode or Visual Studio)" )
endif ( )
add_custom_target ( install-distribution-toolchain
2016-07-26 08:47:52 +08:00
D E P E N D S $ { L L V M T o o l c h a i n D i r } / I n f o . p l i s t d i s t r i b u t i o n )
2016-04-30 06:19:35 +08:00
foreach ( target ${ LLVM_DISTRIBUTION_COMPONENTS } )
2017-12-01 05:48:26 +08:00
add_llvm_install_targets ( install-distribution- ${ target }
D E P E N D S $ { t a r g e t }
C O M P O N E N T $ { t a r g e t }
P R E F I X $ { L L V M T o o l c h a i n D i r } / u s r / )
2016-04-30 06:19:35 +08:00
add_dependencies ( install-distribution-toolchain install-distribution- ${ target } )
endforeach ( )
endif ( )