| .\" Man page generated from reStructuredText. |
| . |
| . |
| .nr rst2man-indent-level 0 |
| . |
| .de1 rstReportMargin |
| \\$1 \\n[an-margin] |
| level \\n[rst2man-indent-level] |
| level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] |
| - |
| \\n[rst2man-indent0] |
| \\n[rst2man-indent1] |
| \\n[rst2man-indent2] |
| .. |
| .de1 INDENT |
| .\" .rstReportMargin pre: |
| . RS \\$1 |
| . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] |
| . nr rst2man-indent-level +1 |
| .\" .rstReportMargin post: |
| .. |
| .de UNINDENT |
| . RE |
| .\" indent \\n[an-margin] |
| .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] |
| .nr rst2man-indent-level -1 |
| .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] |
| .in \\n[rst2man-indent\\n[rst2man-indent-level]]u |
| .. |
| .TH "CMAKE-TOOLCHAINS" "7" "Jan 23, 2025" "3.31.5" "CMake" |
| .SH NAME |
| cmake-toolchains \- CMake Toolchains Reference |
| .SH INTRODUCTION |
| .sp |
| CMake uses a toolchain of utilities to compile, link libraries and create |
| archives, and other tasks to drive the build. The toolchain utilities available |
| are determined by the languages enabled. In normal builds, CMake automatically |
| determines the toolchain for host builds based on system introspection and |
| defaults. In cross\-compiling scenarios, a toolchain file may be specified |
| with information about compiler and utility paths. |
| .sp |
| Added in version 3.19: One may use \X'tty: link |
|
|
| .SH LANGUAGES |
| .sp |
| Languages are enabled by the \X'tty: link |
| built\-in variables, such as |
| \X'tty: link |
| \X'tty: link |
| invoking the \X'tty: link |
| is in the top\-level CMakeLists file, one will be implicitly generated. By default |
| the enabled languages are \fBC\fP and \fBCXX\fP: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| project(C_Only C) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| A special value of \fBNONE\fP can also be used with the \X'tty: link |
| to enable no languages: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| project(MyProject NONE) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| The \X'tty: link |
| \X'tty: link |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| enable_language(CXX) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| When a language is enabled, CMake finds a compiler for that language, and |
| determines some information, such as the vendor and version of the compiler, |
| the target architecture and bitwidth, the location of corresponding utilities |
| etc. |
| .sp |
| The \X'tty: link |
| are currently enabled. |
| .SH VARIABLES AND PROPERTIES |
| .sp |
| Several variables relate to the language components of a toolchain which are |
| enabled: |
| .INDENT 0.0 |
| .TP |
| .B \X'tty: link |
| The full path to the compiler used for \fB<LANG>\fP |
| .TP |
| .B \X'tty: link |
| The compiler identifier used by CMake |
| .TP |
| .B \X'tty: link |
| The version of the compiler. |
| .TP |
| .B \X'tty: link |
| The variables and the configuration\-specific equivalents contain flags that |
| will be added to the compile command when compiling a file of a particular |
| language. |
| .UNINDENT |
| .sp |
| CMake needs a way to determine which compiler to use to invoke the linker. |
| This is determined by the \X'tty: link |
| \X'tty: link |
| the \fBLANGUAGE\fP of the dependent libraries. The choice CMake makes may be overridden |
| with the \X'tty: link |
| .SH TOOLCHAIN FEATURES |
| .sp |
| CMake provides the \X'tty: link |
| \X'tty: link |
| \X'tty: link |
| toolchain features. These APIs test the toolchain in some way and cache the |
| result so that the test does not have to be performed again the next time |
| CMake runs. |
| .sp |
| Some toolchain features have built\-in handling in CMake, and do not require |
| compile\-tests. For example, \X'tty: link |
| specifying that a target should be built as position\-independent code, if |
| the compiler supports that feature. The \X'tty: link |
| and \X'tty: link |
| hidden visibility, if supported by the compiler. |
| .SH CROSS COMPILING |
| .sp |
| If \X'tty: link |
| \X'tty: link |
| \X'tty: link |
| file will be loaded early to set values for the compilers. |
| The \X'tty: link |
| cross\-compiling. |
| .sp |
| Note that using the \X'tty: link |
| variables inside a toolchain file is typically undesirable. The toolchain |
| file is used in contexts where these variables have different values when used |
| in different places (e.g. as part of a call to \X'tty: link |
| cases, where there is a need to evaluate paths inside a toolchain file, the more |
| appropriate variable to use would be \X'tty: link |
| it always has an unambiguous, predictable value. |
| .SS Cross Compiling for Linux |
| .sp |
| A typical cross\-compiling toolchain for Linux has content such |
| as: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| set(CMAKE_SYSTEM_NAME Linux) |
| set(CMAKE_SYSTEM_PROCESSOR arm) |
|
|
| set(CMAKE_SYSROOT /home/devel/rasp\-pi\-rootfs) |
| set(CMAKE_STAGING_PREFIX /home/devel/stage) |
|
|
| set(tools /home/devel/gcc\-4.7\-linaro\-rpi\-gnueabihf) |
| set(CMAKE_C_COMPILER ${tools}/bin/arm\-linux\-gnueabihf\-gcc) |
| set(CMAKE_CXX_COMPILER ${tools}/bin/arm\-linux\-gnueabihf\-g++) |
|
|
| set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
| set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
| set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| Where: |
| .INDENT 0.0 |
| .TP |
| .B \X'tty: link |
| is the CMake\-identifier of the target platform to build for. |
| .TP |
| .B \X'tty: link |
| is the CMake\-identifier of the target architecture. |
| .TP |
| .B \X'tty: link |
| is optional, and may be specified if a sysroot is available. |
| .TP |
| .B \X'tty: link |
| is also optional. It may be used to specify a path on the host to install to. |
| The \X'tty: link |
| location, even when cross\-compiling. |
| .TP |
| .B \X'tty: link |
| variable may be set to full paths, or to names of compilers to search for |
| in standard locations. For toolchains that do not support linking binaries |
| without custom flags or scripts one may set the |
| \X'tty: link |
| tell CMake not to try to link executables during its checks. |
| .UNINDENT |
| .sp |
| CMake \fBfind_*\fP commands will look in the sysroot, and the \X'tty: link |
| entries by default in all cases, as well as looking in the host system root prefix. |
| Although this can be controlled on a case\-by\-case basis, when cross\-compiling, it |
| can be useful to exclude looking in either the host or the target for particular |
| artifacts. Generally, includes, libraries and packages should be found in the |
| target system prefixes, whereas executables which must be run as part of the build |
| should be found only on the host and not on the target. This is the purpose of |
| the \fBCMAKE_FIND_ROOT_PATH_MODE_*\fP variables. |
| .SS Cross Compiling for the Cray Linux Environment |
| .sp |
| Cross compiling for compute nodes in the Cray Linux Environment can be done |
| without needing a separate toolchain file. Specifying |
| \fB\-DCMAKE_SYSTEM_NAME=CrayLinuxEnvironment\fP on the CMake command line will |
| ensure that the appropriate build settings and search paths are configured. |
| The platform will pull its configuration from the current environment |
| variables and will configure a project to use the compiler wrappers from the |
| Cray Programming Environment\(aqs \fBPrgEnv\-*\fP modules if present and loaded. |
| .sp |
| The default configuration of the Cray Programming Environment is to only |
| support static libraries. This can be overridden and shared libraries |
| enabled by setting the \fBCRAYPE_LINK_TYPE\fP environment variable to |
| \fBdynamic\fP\&. |
| .sp |
| Running CMake without specifying \X'tty: link |
| run the configure step in host mode assuming a standard Linux environment. |
| If not overridden, the \fBPrgEnv\-*\fP compiler wrappers will end up getting used, |
| which if targeting the either the login node or compute node, is likely not the |
| desired behavior. The exception to this would be if you are building directly |
| on a NID instead of cross\-compiling from a login node. If trying to build |
| software for a login node, you will need to either first unload the |
| currently loaded \fBPrgEnv\-*\fP module or explicitly tell CMake to use the |
| system compilers in \fB/usr/bin\fP instead of the Cray wrappers. If instead |
| targeting a compute node is desired, just specify the |
| \X'tty: link |
| .SS Cross Compiling using Clang |
| .sp |
| Some compilers such as Clang are inherently cross compilers. |
| The \X'tty: link |
| value to those supported compilers when compiling: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| set(CMAKE_SYSTEM_NAME Linux) |
| set(CMAKE_SYSTEM_PROCESSOR arm) |
|
|
| set(triple arm\-linux\-gnueabihf) |
|
|
| set(CMAKE_C_COMPILER clang) |
| set(CMAKE_C_COMPILER_TARGET ${triple}) |
| set(CMAKE_CXX_COMPILER clang++) |
| set(CMAKE_CXX_COMPILER_TARGET ${triple}) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| Similarly, some compilers do not ship their own supplementary utilities |
| such as linkers, but provide a way to specify the location of the external |
| toolchain which will be used by the compiler driver. The |
| \X'tty: link |
| toolchain file to pass the path to the compiler driver. |
| .SS Cross Compiling for QNX |
| .sp |
| As the Clang compiler the QNX QCC compile is inherently a cross compiler. |
| And the \X'tty: link |
| value to those supported compilers when compiling: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| set(CMAKE_SYSTEM_NAME QNX) |
|
|
| set(arch gcc_ntoarmv7le) |
|
|
| set(CMAKE_C_COMPILER qcc) |
| set(CMAKE_C_COMPILER_TARGET ${arch}) |
| set(CMAKE_CXX_COMPILER QCC) |
| set(CMAKE_CXX_COMPILER_TARGET ${arch}) |
|
|
| set(CMAKE_SYSROOT $ENV{QNX_TARGET}) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .SS Cross Compiling for Windows CE |
| .sp |
| Cross compiling for Windows CE requires the corresponding SDK being |
| installed on your system. These SDKs are usually installed under |
| \fBC:/Program Files (x86)/Windows CE Tools/SDKs\fP\&. |
| .sp |
| A toolchain file to configure a Visual Studio generator for |
| Windows CE may look like this: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| set(CMAKE_SYSTEM_NAME WindowsCE) |
|
|
| set(CMAKE_SYSTEM_VERSION 8.0) |
| set(CMAKE_SYSTEM_PROCESSOR arm) |
|
|
| set(CMAKE_GENERATOR_TOOLSET CE800) |
| set(CMAKE_GENERATOR_PLATFORM SDK_AM335X_SK_WEC2013_V310) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| The \X'tty: link |
| Further \X'tty: link |
| Windows CE to use. Currently version 8.0 (Windows Embedded Compact 2013) is |
| supported out of the box. Other versions may require one to set |
| \X'tty: link |
| .SS Cross Compiling for Windows 10 Universal Applications |
| .sp |
| A toolchain file to configure \X'tty: link |
| Windows 10 Universal Application may look like this: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| set(CMAKE_SYSTEM_NAME WindowsStore) |
| set(CMAKE_SYSTEM_VERSION 10.0) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| A Windows 10 Universal Application targets both Windows Store and |
| Windows Phone. Specify the \X'tty: link |
| to be \fB10.0\fP or higher. |
| .sp |
| CMake selects a Windows SDK as described by documentation of the |
| \X'tty: link |
| .SS Cross Compiling for Windows Phone |
| .sp |
| A toolchain file to configure a Visual Studio generator for |
| Windows Phone may look like this: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| set(CMAKE_SYSTEM_NAME WindowsPhone) |
| set(CMAKE_SYSTEM_VERSION 8.1) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .SS Cross Compiling for Windows Store |
| .sp |
| A toolchain file to configure a Visual Studio generator for |
| Windows Store may look like this: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| set(CMAKE_SYSTEM_NAME WindowsStore) |
| set(CMAKE_SYSTEM_VERSION 8.1) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .SS Cross Compiling for ADSP SHARC/Blackfin |
| .sp |
| Cross\-compiling for ADSP SHARC or Blackfin can be configured |
| by setting the \X'tty: link |
| and the \X'tty: link |
| to the \(dqpart number\(dq, excluding the \fBADSP\-\fP prefix, |
| for example, \fB21594\fP, \fBSC589\fP, etc. |
| This value is case insensitive. |
| .sp |
| CMake will automatically search for CCES or VDSP++ installs |
| in their default install locations |
| and select the most recent version found. |
| CCES will be selected over VDSP++ if both are installed. |
| Custom install paths can be set via the \X'tty: link |
| or the \X'tty: link |
| .sp |
| The compiler (\fBcc21k\fP vs. \fBccblkfn\fP) is selected automatically |
| based on the \X'tty: link |
| .SS Cross Compiling for Android |
| .sp |
| A toolchain file may configure cross\-compiling for Android by setting the |
| \X'tty: link |
| is specific to the Android development environment to be used. |
| .sp |
| For \X'tty: link |
| Visual Studio Edition\fP or the \fI\%Visual Studio tools for Android\fP to be installed. See those sections |
| for further configuration details. |
| .sp |
| For \X'tty: link |
| CMake expects one of these environments: |
| .INDENT 0.0 |
| .IP \(bu 2 |
| \fI\%NDK\fP |
| .IP \(bu 2 |
| \fI\%Standalone Toolchain\fP |
| .UNINDENT |
| .sp |
| CMake uses the following steps to select one of the environments: |
| .INDENT 0.0 |
| .IP \(bu 2 |
| If the \X'tty: link |
| specified location will be used. |
| .IP \(bu 2 |
| Else, if the \X'tty: link |
| is set, the Standalone Toolchain at the specified location will be used. |
| .IP \(bu 2 |
| Else, if the \X'tty: link |
| of the form \fB<ndk>/platforms/android\-<api>/arch\-<arch>\fP, the \fB<ndk>\fP |
| part will be used as the value of \X'tty: link |
| NDK will be used. |
| .IP \(bu 2 |
| Else, if the \X'tty: link |
| form \fB<standalone\-toolchain>/sysroot\fP, the \fB<standalone\-toolchain>\fP part |
| will be used as the value of \X'tty: link |
| and the Standalone Toolchain will be used. |
| .IP \(bu 2 |
| Else, if a cmake variable \fBANDROID_NDK\fP is set it will be used |
| as the value of \X'tty: link |
| .IP \(bu 2 |
| Else, if a cmake variable \fBANDROID_STANDALONE_TOOLCHAIN\fP is set, it will be |
| used as the value of \X'tty: link |
| Standalone Toolchain will be used. |
| .IP \(bu 2 |
| Else, if an environment variable \fBANDROID_NDK_ROOT\fP or |
| \fBANDROID_NDK\fP is set, it will be used as the value of |
| \X'tty: link |
| .IP \(bu 2 |
| Else, if an environment variable \fBANDROID_STANDALONE_TOOLCHAIN\fP is |
| set then it will be used as the value of |
| \X'tty: link |
| Toolchain will be used. |
| .IP \(bu 2 |
| Else, an error diagnostic will be issued that neither the NDK or |
| Standalone Toolchain can be found. |
| .UNINDENT |
| .sp |
| Added in version 3.20: If an Android NDK is selected, its version number is reported |
| in the \X'tty: link |
|
|
| .SS Cross Compiling for Android with the NDK |
| .sp |
| A toolchain file may configure \X'tty: link |
| \X'tty: link |
| Android for cross\-compiling. |
| .sp |
| Configure use of an Android NDK with the following variables: |
| .INDENT 0.0 |
| .TP |
| .B \X'tty: link |
| Set to \fBAndroid\fP\&. Must be specified to enable cross compiling |
| for Android. |
| .TP |
| .B \X'tty: link |
| Set to the Android API level. If not specified, the value is |
| determined as follows: |
| .INDENT 7.0 |
| .IP \(bu 2 |
| If the \X'tty: link |
| is used as the API level. |
| .IP \(bu 2 |
| If the \X'tty: link |
| detected from the NDK directory structure containing the sysroot. |
| .IP \(bu 2 |
| Otherwise, the latest API level available in the NDK is used. |
| .UNINDENT |
| .TP |
| .B \X'tty: link |
| Set to the Android ABI (architecture). If not specified, this |
| variable will default to the first supported ABI in the list of |
| \fBarmeabi\fP, \fBarmeabi\-v7a\fP and \fBarm64\-v8a\fP\&. |
| The \X'tty: link |
| from \fBCMAKE_ANDROID_ARCH_ABI\fP automatically. |
| Also see the \X'tty: link |
| \X'tty: link |
| .TP |
| .B \X'tty: link |
| Set to the absolute path to the Android NDK root directory. |
| If not specified, a default for this variable will be chosen |
| as specified \fI\%above\fP\&. |
| .TP |
| .B \X'tty: link |
| Set to a true value to use the deprecated per\-api\-level headers |
| instead of the unified headers. If not specified, the default will |
| be false unless using a NDK that does not provide unified headers. |
| .TP |
| .B \X'tty: link |
| On NDK r19 or above, this variable must be unset or set to \fBclang\fP\&. |
| On NDK r18 or below, set this to the version of the NDK toolchain to |
| be selected as the compiler. If not specified, the default will be |
| the latest available GCC toolchain. |
| .TP |
| .B \X'tty: link |
| Set to specify which C++ standard library to use. If not specified, |
| a default will be selected as described in the variable documentation. |
| .UNINDENT |
| .sp |
| The following variables will be computed and provided automatically: |
| .INDENT 0.0 |
| .TP |
| .B \X'tty: link |
| The absolute path prefix to the binutils in the NDK toolchain. |
| .TP |
| .B \X'tty: link |
| The host platform suffix of the binutils in the NDK toolchain. |
| .UNINDENT |
| .sp |
| For example, a toolchain file might contain: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| set(CMAKE_SYSTEM_NAME Android) |
| set(CMAKE_SYSTEM_VERSION 21) |
| set(CMAKE_ANDROID_ARCH_ABI arm64\-v8a) |
| set(CMAKE_ANDROID_NDK /path/to/android\-ndk) |
| set(CMAKE_ANDROID_STL_TYPE gnustl_static) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| Alternatively one may specify the values without a toolchain file: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| $ cmake ../src \e |
| \-DCMAKE_SYSTEM_NAME=Android \e |
| \-DCMAKE_SYSTEM_VERSION=21 \e |
| \-DCMAKE_ANDROID_ARCH_ABI=arm64\-v8a \e |
| \-DCMAKE_ANDROID_NDK=/path/to/android\-ndk \e |
| \-DCMAKE_ANDROID_STL_TYPE=gnustl_static |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .SS Cross Compiling for Android with a Standalone Toolchain |
| .sp |
| A toolchain file may configure \X'tty: link |
| \X'tty: link |
| using a standalone toolchain. |
| .sp |
| Configure use of an Android standalone toolchain with the following variables: |
| .INDENT 0.0 |
| .TP |
| .B \X'tty: link |
| Set to \fBAndroid\fP\&. Must be specified to enable cross compiling |
| for Android. |
| .TP |
| .B \X'tty: link |
| Set to the absolute path to the standalone toolchain root directory. |
| A \fB${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot\fP directory |
| must exist. |
| If not specified, a default for this variable will be chosen |
| as specified \fI\%above\fP\&. |
| .TP |
| .B \X'tty: link |
| When the standalone toolchain targets ARM, optionally set this to \fBON\fP |
| to target 32\-bit ARM instead of 16\-bit Thumb. |
| See variable documentation for details. |
| .TP |
| .B \X'tty: link |
| When the standalone toolchain targets ARM v7, optionally set thisto \fBON\fP |
| to target ARM NEON devices. See variable documentation for details. |
| .UNINDENT |
| .sp |
| The following variables will be computed and provided automatically: |
| .INDENT 0.0 |
| .TP |
| .B \X'tty: link |
| The Android API level detected from the standalone toolchain. |
| .TP |
| .B \X'tty: link |
| The Android ABI detected from the standalone toolchain. |
| .TP |
| .B \X'tty: link |
| The absolute path prefix to the \fBbinutils\fP in the standalone toolchain. |
| .TP |
| .B \X'tty: link |
| The host platform suffix of the \fBbinutils\fP in the standalone toolchain. |
| .UNINDENT |
| .sp |
| For example, a toolchain file might contain: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| set(CMAKE_SYSTEM_NAME Android) |
| set(CMAKE_ANDROID_STANDALONE_TOOLCHAIN /path/to/android\-toolchain) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| Alternatively one may specify the values without a toolchain file: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| $ cmake ../src \e |
| \-DCMAKE_SYSTEM_NAME=Android \e |
| \-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=/path/to/android\-toolchain |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .SS Cross Compiling for Android with NVIDIA Nsight Tegra Visual Studio Edition |
| .sp |
| A toolchain file to configure one of the \X'tty: link |
| to build using NVIDIA Nsight Tegra targeting Android may look like this: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| set(CMAKE_SYSTEM_NAME Android) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| The \X'tty: link |
| the Nsight Tegra \(dqToolchain Version\(dq value. |
| .sp |
| See also target properties: |
| .INDENT 0.0 |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .IP \(bu 2 |
| \X'tty: link |
| .UNINDENT |
| .SS Cross Compiling for iOS, tvOS, visionOS, or watchOS |
| .sp |
| For cross\-compiling to iOS, tvOS, visionOS, or watchOS, the \X'tty: link |
| generator is recommended. The \X'tty: link |
| \X'tty: link |
| project to handle more areas like target CPU selection and code signing. |
| .sp |
| Any of the Apple device platforms can be targeted by setting the |
| \X'tty: link |
| By default, the latest Device SDK is chosen. As for all Apple platforms, |
| a different SDK (e.g. a simulator) can be selected by setting the |
| \X'tty: link |
| necessary (see \fI\%Switching Between Device and Simulator\fP below). |
| A list of available SDKs can be obtained by running \fBxcodebuild \-showsdks\fP\&. |
| .TS |
| center; |
| |l|l|l|l|l|. |
| _ |
| T{ |
| OS |
| T} T{ |
| CMAKE_SYSTEM_NAME |
| T} T{ |
| Device SDK (default) |
| T} T{ |
| Simulator SDK |
| T} T{ |
| Catalyst SDK |
| T} |
| _ |
| T{ |
| iOS |
| T} T{ |
| iOS |
| T} T{ |
| iphoneos |
| T} T{ |
| iphonesimulator |
| T} T{ |
| macosx |
| T} |
| _ |
| T{ |
| tvOS |
| T} T{ |
| tvOS |
| T} T{ |
| appletvos |
| T} T{ |
| appletvsimulator |
| T} T{ |
| N/A |
| T} |
| _ |
| T{ |
| visionOS |
| T} T{ |
| visionOS |
| T} T{ |
| xros |
| T} T{ |
| xrsimulator |
| T} T{ |
| N/A |
| T} |
| _ |
| T{ |
| watchOS |
| T} T{ |
| watchOS |
| T} T{ |
| watchos |
| T} T{ |
| watchsimulator |
| T} T{ |
| N/A |
| T} |
| _ |
| .TE |
| .sp |
| For example, to create a CMake configuration for iOS, the following |
| command is sufficient: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| cmake .. \-GXcode \-DCMAKE_SYSTEM_NAME=iOS |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| Variable \X'tty: link |
| for both device and simulator. Variable \X'tty: link |
| can be used to set an iOS/tvOS/visionOS/watchOS deployment target. |
| .sp |
| The next example installs five architectures in a universal binary for an iOS |
| library. It adds the relevant \fB\-miphoneos\-version\-min=9.3\fP or |
| \fB\-mios\-simulator\-version\-min=9.3\fP compiler flag where appropriate. |
| Note that the \X'tty: link |
| example is now deprecated, so this approach is no longer recommended. |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| $ cmake \-S. \-B_builds \-GXcode \e |
| \-DCMAKE_SYSTEM_NAME=iOS \e |
| \(dq\-DCMAKE_OSX_ARCHITECTURES=armv7;armv7s;arm64;i386;x86_64\(dq \e |
| \-DCMAKE_OSX_DEPLOYMENT_TARGET=9.3 \e |
| \-DCMAKE_INSTALL_PREFIX=\(gapwd\(ga/_install \e |
| \-DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO \e |
| \-DCMAKE_IOS_INSTALL_COMBINED=YES |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| Example: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| |
| cmake_minimum_required(VERSION 3.14) |
| project(foo) |
| add_library(foo foo.cpp) |
| install(TARGETS foo DESTINATION lib) |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| Install: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| $ cmake \-\-build _builds \-\-config Release \-\-target install |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| Check library: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| $ lipo \-info _install/lib/libfoo.a |
| Architectures in the fat file: _install/lib/libfoo.a are: i386 armv7 armv7s x86_64 arm64 |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| $ otool \-l _install/lib/libfoo.a | grep \-A2 LC_VERSION_MIN_IPHONEOS |
| cmd LC_VERSION_MIN_IPHONEOS |
| cmdsize 16 |
| version 9.3 |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .SS Code Signing |
| .sp |
| Some build artifacts for the embedded Apple platforms require mandatory |
| code signing. If the \X'tty: link |
| code signing is required or desired, the development team ID can be |
| specified via the \fBCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM\fP CMake variable. |
| This team ID will then be included in the generated Xcode project. |
| By default, CMake avoids the need for code signing during the internal |
| configuration phase (i.e compiler ID and feature detection). |
| .SS Switching Between Device and Simulator |
| .sp |
| When configuring for any of the embedded platforms, one can target either |
| real devices or the simulator. Both have their own separate SDK, but CMake |
| only supports specifying a single SDK for the configuration phase. This |
| means the developer must select one or the other at configuration time. |
| When using the \X'tty: link |
| because Xcode still allows you to build for either a device or a simulator, |
| even though configuration was only performed for one of the two. From |
| within the Xcode IDE, builds are performed for the selected \(dqdestination\(dq |
| platform. When building from the command line, the desired sdk can be |
| specified directly by passing a \fB\-sdk\fP option to the underlying build |
| tool (\fBxcodebuild\fP). For example: |
| .INDENT 0.0 |
| .INDENT 3.5 |
| .sp |
| .nf |
| .ft C |
| $ cmake \-\-build ... \-\- \-sdk iphonesimulator |
| .ft P |
| .fi |
| .UNINDENT |
| .UNINDENT |
| .sp |
| Please note that checks made during configuration were performed against |
| the configure\-time SDK and might not hold true for other SDKs. Commands |
| like \X'tty: link |
| details only for the configured SDK/platform, so they can be problematic |
| if wanting to switch between device and simulator builds. You can follow |
| the next rules to make device + simulator configuration work: |
| .INDENT 0.0 |
| .IP \(bu 2 |
| Use explicit \fB\-l\fP linker flag, |
| e.g. \fBtarget_link_libraries(foo PUBLIC \(dq\-lz\(dq)\fP |
| .IP \(bu 2 |
| Use explicit \fB\-framework\fP linker flag, |
| e.g. \fBtarget_link_libraries(foo PUBLIC \(dq\-framework CoreFoundation\(dq)\fP |
| .IP \(bu 2 |
| Use \X'tty: link |
| \X'tty: link |
| .UNINDENT |
| .SH COPYRIGHT |
| 2000-2024 Kitware, Inc. and Contributors |
| .\" Generated by docutils manpage writer. |
| . |
|
|