CMAKE-TOOLCHAINS(7) CMake CMAKE-TOOLCHAINS(7)
NAME
cmake-toolchains - CMake Toolchains Reference
INTRODUCTION
CMake uses a toolchain of utilities to compile, link libraries and cre-
ate archives, and other tasks to drive the build. The toolchain utili-
ties 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 scenar-
ios, a toolchain file may be specified with information about compiler
and utility paths.
LANGUAGES
Languages are enabled by the project() command. Language-specific
built-in variables, such as CMAKE_CXX_COMPILER, CMAKE_CXX_COMPILER_ID
etc are set by invoking the project() command. If no project command
is in the top-level CMakeLists file, one will be implicitly generated.
By default the enabled languages are C and CXX:
project(C_Only C)
A special value of NONE can also be used with the project() command to
enable no languages:
project(MyProject NONE)
The enable_language() command can be used to enable languages after the
project() command:
enable_language(CXX)
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 corre-
sponding utilities etc.
The ENABLED_LANGUAGES global property contains the languages which are
currently enabled.
VARIABLES AND PROPERTIES
Several variables relate to the language components of a toolchain
which are enabled. CMAKE_<LANG>_COMPILER is the full path to the com-
piler used for <LANG>. CMAKE_<LANG>_COMPILER_ID is the identifier used
by CMake for the compiler and CMAKE_<LANG>_COMPILER_VERSION is the ver-
sion of the compiler.
The CMAKE_<LANG>_FLAGS variables and the configuration-specific equiva-
lents contain flags that will be added to the compile command when com-
piling a file of a particular language.
As the linker is invoked by the compiler driver, CMake needs a way to
determine which compiler to use to invoke the linker. This is calcu-
lated by the LANGUAGE of source files in the target, and in the case of
static libraries, the language of the dependent libraries. The choice
CMake makes may be overridden with the LINKER_LANGUAGE target property.
TOOLCHAIN FEATURES
CMake provides the try_compile() command and wrapper macros such as
CheckCXXSourceCompiles, CheckCXXSymbolExists and CheckIncludeFile to
test capability and availability of various 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.
Some toolchain features have built-in handling in CMake, and do not re-
quire compile-tests. For example, POSITION_INDEPENDENT_CODE allows
specifying that a target should be built as position-independent code,
if the compiler supports that feature. The <LANG>_VISIBILITY_PRESET and
VISIBILITY_INLINES_HIDDEN target properties add flags for hidden visi-
bility, if supported by the compiler.
CROSS COMPILING
If cmake(1) is invoked with the command line parameter -DC-
MAKE_TOOLCHAIN_FILE=path/to/file, the file will be loaded early to set
values for the compilers. The CMAKE_CROSSCOMPILING variable is set to
true when CMake is cross-compiling.
Note that using the CMAKE_SOURCE_DIR or CMAKE_BINARY_DIR variables in-
side 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 try_compile()). In most
cases, where there is a need to evaluate paths inside a toolchain file,
the more appropriate variable to use would be CMAKE_CURRENT_LIST_DIR,
since it always has an unambiguous, predictable value.
Cross Compiling for Linux
A typical cross-compiling toolchain for Linux has content such as:
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)
The CMAKE_SYSTEM_NAME is the CMake-identifier of the target platform to
build for.
The CMAKE_SYSTEM_PROCESSOR is the CMake-identifier of the target archi-
tecture to build for.
The CMAKE_SYSROOT is optional, and may be specified if a sysroot is
available.
The CMAKE_STAGING_PREFIX is also optional. It may be used to specify a
path on the host to install to. The CMAKE_INSTALL_PREFIX is always the
runtime installation location, even when cross-compiling.
The CMAKE_<LANG>_COMPILER variables 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 CMAKE_TRY_COMPILE_TARGET_TYPE variable to
STATIC_LIBRARY to tell CMake not to try to link executables during its
checks.
CMake find_* commands will look in the sysroot, and the
CMAKE_FIND_ROOT_PATH entries by default in all cases, as well as look-
ing 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. Gen-
erally, 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 CMAKE_FIND_ROOT_PATH_MODE_* variables.
Cross Compiling for the Cray Linux Environment
Cross compiling for compute nodes in the Cray Linux Environment can be
done without needing a separate toolchain file. Specifying -DC-
MAKE_SYSTEM_NAME=CrayLinuxEnvironment on the CMake command line will
ensure that the appropriate build settings and search paths are config-
ured. The platform will pull its configuration from the current envi-
ronment variables and will configure a project to use the compiler
wrappers from the Cray Programming Environments PrgEnv-* modules if
present and loaded.
The default configuration of the Cray Programming Environment is to
only support static libraries. This can be overridden and shared li-
braries enabled by setting the CRAYPE_LINK_TYPE environment variable to
dynamic.
Running CMake without specifying CMAKE_SYSTEM_NAME will run the config-
ure step in host mode assuming a standard Linux environment. If not
overridden, the PrgEnv-* compiler wrapper.
CMAKE-TOOLCHAINS(7) CMake CMAKE-TOOLCHAINS(7)
NAME
cmake-toolchains - CMake Toolchains Reference
INTRODUCTION
CMake uses a toolchain of utilities to compile, link libraries and cre-
ate archives, and other tasks to drive the build. The toolchain utili-
ties 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 scenar-
ios, a toolchain file may be specified with information about compiler
and utility paths.
LANGUAGES
Languages are enabled by the project() command. Language-specific
built-in variables, such as CMAKE_CXX_COMPILER, CMAKE_CXX_COMPILER_ID
etc are set by invoking the project() command. If no project command
is in the top-level CMakeLists file, one will be implicitly generated.
By default the enabled languages are C and CXX:
project(C_Only C)
A special value of NONE can also be used with the project() command to
enable no languages:
project(MyProject NONE)
The enable_language() command can be used to enable languages after the
project() command:
enable_language(CXX)
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 corre-
sponding utilities etc.
The ENABLED_LANGUAGES global property contains the languages which are
currently enabled.
VARIABLES AND PROPERTIES
Several variables relate to the language components of a toolchain
which are enabled. CMAKE_<LANG>_COMPILER is the full path to the com-
piler used for <LANG>. CMAKE_<LANG>_COMPILER_ID is the identifier used
by CMake for the compiler and CMAKE_<LANG>_COMPILER_VERSION is the ver-
sion of the compiler.
The CMAKE_<LANG>_FLAGS variables and the configuration-specific equiva-
lents contain flags that will be added to the compile command when com-
piling a file of a particular language.
As the linker is invoked by the compiler driver, CMake needs a way to
determine which compiler to use to invoke the linker. This is calcu-
lated by the LANGUAGE of source files in the target, and in the case of
static libraries, the language of the dependent libraries. The choice
CMake makes may be overridden with the LINKER_LANGUAGE target property.
TOOLCHAIN FEATURES
CMake provides the try_compile() command and wrapper macros such as
CheckCXXSourceCompiles, CheckCXXSymbolExists and CheckIncludeFile to
test capability and availability of various 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.
Some toolchain features have built-in handling in CMake, and do not re-
quire compile-tests. For example, POSITION_INDEPENDENT_CODE allows
specifying that a target should be built as position-independent code,
if the compiler supports that feature. The <LANG>_VISIBILITY_PRESET and
VISIBILITY_INLINES_HIDDEN target properties add flags for hidden visi-
bility, if supported by the compiler.
CROSS COMPILING
If cmake(1) is invoked with the command line parameter -DC-
MAKE_TOOLCHAIN_FILE=path/to/file, the file will be loaded early to set
values for the compilers. The CMAKE_CROSSCOMPILING variable is set to
true when CMake is cross-compiling.
Note that using the CMAKE_SOURCE_DIR or CMAKE_BINARY_DIR variables in-
side 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 try_compile()). In most
cases, where there is a need to evaluate paths inside a toolchain file,
the more appropriate variable to use would be CMAKE_CURRENT_LIST_DIR,
since it always has an unambiguous, predictable value.
Cross Compiling for Linux
A typical cross-compiling toolchain for Linux has content such as:
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)
The CMAKE_SYSTEM_NAME is the CMake-identifier of the target platform to
build for.
The CMAKE_SYSTEM_PROCESSOR is the CMake-identifier of the target archi-
tecture to build for.
The CMAKE_SYSROOT is optional, and may be specified if a sysroot is
available.
The CMAKE_STAGING_PREFIX is also optional. It may be used to specify a
path on the host to install to. The CMAKE_INSTALL_PREFIX is always the
runtime installation location, even when cross-compiling.
The CMAKE_<LANG>_COMPILER variables 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 CMAKE_TRY_COMPILE_TARGET_TYPE variable to
STATIC_LIBRARY to tell CMake not to try to link executables during its
checks.
CMake find_* commands will look in the sysroot, and the
CMAKE_FIND_ROOT_PATH entries by default in all cases, as well as look-
ing 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. Gen-
erally, 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 CMAKE_FIND_ROOT_PATH_MODE_* variables.
Cross Compiling for the Cray Linux Environment
Cross compiling for compute nodes in the Cray Linux Environment can be
done without needing a separate toolchain file. Specifying -DC-
MAKE_SYSTEM_NAME=CrayLinuxEnvironment on the CMake command line will
ensure that the appropriate build settings and search paths are config-
ured. The platform will pull its configuration from the current envi-
ronment variables and will configure a project to use the compiler
wrappers from the Cray Programming Environments PrgEnv-* modules if
present and loaded.
The default configuration of the Cray Programming Environment is to
only support static libraries. This can be overridden and shared li-
braries enabled by setting the CRAYPE_LINK_TYPE environment variable to
dynamic.
Running CMake without specifying CMAKE_SYSTEM_NAME will run the config-
ure step in host mode assuming a standard Linux environment. If not
overridden, the PrgEnv-* compiler wrapper.
CMAKE-TOOLCHAINS(7) CMake CMAKE-TOOLCHAINS(7)
NAME
cmake-toolchains - CMake Toolchains Reference
INTRODUCTION
CMake uses a toolchain of utilities to compile, link libraries and cre-
ate archives, and other tasks to drive the build. The toolchain utili-
ties 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 scenar-
ios, a toolchain file may be specified with information about compiler
and utility paths.
LANGUAGES
Languages are enabled by the project() command. Language-specific
built-in variables, such as CMAKE_CXX_COMPILER, CMAKE_CXX_COMPILER_ID
etc are set by invoking the project() command. If no project command
is in the top-level CMakeLists file, one will be implicitly generated.
By default the enabled languages are C and CXX:
project(C_Only C)
A special value of NONE can also be used with the project() command to
enable no languages:
project(MyProject NONE)
The enable_language() command can be used to enable languages after the
project() command:
enable_language(CXX)
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 corre-
sponding utilities etc.
The ENABLED_LANGUAGES global property contains the languages which are
currently enabled.
VARIABLES AND PROPERTIES
Several variables relate to the language components of a toolchain
which are enabled. CMAKE_<LANG>_COMPILER is the full path to the com-
piler used for <LANG>. CMAKE_<LANG>_COMPILER_ID is the identifier used
by CMake for the compiler and CMAKE_<LANG>_COMPILER_VERSION is the ver-
sion of the compiler.
The CMAKE_<LANG>_FLAGS variables and the configuration-specific equiva-
lents contain flags that will be added to the compile command when com-
piling a file of a particular language.
As the linker is invoked by the compiler driver, CMake needs a way to
determine which compiler to use to invoke the linker. This is calcu-
lated by the LANGUAGE of source files in the target, and in the case of
static libraries, the language of the dependent libraries. The choice
CMake makes may be overridden with the LINKER_LANGUAGE target property.
TOOLCHAIN FEATURES
CMake provides the try_compile() command and wrapper macros such as
CheckCXXSourceCompiles, CheckCXXSymbolExists and CheckIncludeFile to
test capability and availability of various 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.
Some toolchain features have built-in handling in CMake, and do not re-
quire compile-tests. For example, POSITION_INDEPENDENT_CODE allows
specifying that a target should be built as position-independent code,
if the compiler supports that feature. The <LANG>_VISIBILITY_PRESET and
VISIBILITY_INLINES_HIDDEN target properties add flags for hidden visi-
bility, if supported by the compiler.
CROSS COMPILING
If cmake(1) is invoked with the command line parameter -DC-
MAKE_TOOLCHAIN_FILE=path/to/file, the file will be loaded early to set
values for the compilers. The CMAKE_CROSSCOMPILING variable is set to
true when CMake is cross-compiling.
Note that using the CMAKE_SOURCE_DIR or CMAKE_BINARY_DIR variables in-
side 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 try_compile()). In most
cases, where there is a need to evaluate paths inside a toolchain file,
the more appropriate variable to use would be CMAKE_CURRENT_LIST_DIR,
since it always has an unambiguous, predictable value.
Cross Compiling for Linux
A typical cross-compiling toolchain for Linux has content such as:
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)
The CMAKE_SYSTEM_NAME is the CMake-identifier of the target platform to
build for.
The CMAKE_SYSTEM_PROCESSOR is the CMake-identifier of the target archi-
tecture to build for.
The CMAKE_SYSROOT is optional, and may be specified if a sysroot is
available.
The CMAKE_STAGING_PREFIX is also optional. It may be used to specify a
path on the host to install to. The CMAKE_INSTALL_PREFIX is always the
runtime installation location, even when cross-compiling.
The CMAKE_<LANG>_COMPILER variables 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 CMAKE_TRY_COMPILE_TARGET_TYPE variable to
STATIC_LIBRARY to tell CMake not to try to link executables during its
checks.
CMake find_* commands will look in the sysroot, and the
CMAKE_FIND_ROOT_PATH entries by default in all cases, as well as look-
ing 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. Gen-
erally, 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 CMAKE_FIND_ROOT_PATH_MODE_* variables.
Cross Compiling for the Cray Linux Environment
Cross compiling for compute nodes in the Cray Linux Environment can be
done without needing a separate toolchain file. Specifying -DC-
MAKE_SYSTEM_NAME=CrayLinuxEnvironment on the CMake command line will
ensure that the appropriate build settings and search paths are config-
ured. The platform will pull its configuration from the current envi-
ronment variables and will configure a project to use the compiler
wrappers from the Cray Programming Environments PrgEnv-* modules if
present and loaded.
The default configuration of the Cray Programming Environment is to
only support static libraries. This can be overridden and shared li-
braries enabled by setting the CRAYPE_LINK_TYPE environment variable to
dynamic.
Running CMake without specifying CMAKE_SYSTEM_NAME will run the config-
ure step in host mode assuming a standard Linux environment. If not
overridden, the PrgEnv-* compiler wrapper.
CMAKE-TOOLCHAINS(7) CMake CMAKE-TOOLCHAINS(7)
NAME
cmake-toolchains - CMake Toolchains Reference
INTRODUCTION
CMake uses a toolchain of utilities to compile, link libraries and cre-
ate archives, and other tasks to drive the build. The toolchain utili-
ties 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 scenar-
ios, a toolchain file may be specified with information about compiler
and utility paths.
LANGUAGES
Languages are enabled by the project() command. Language-specific
built-in variables, such as CMAKE_CXX_COMPILER, CMAKE_CXX_COMPILER_ID
etc are set by invoking the project() command. If no project command
is in the top-level CMakeLists
3.18.4 September 13, 2021 CMAKE-TOOLCHAINS(7)
Czas wygenerowania: 0.00019 sek.
Created with the man page lookup class by Andrew Collington.
Based on a C man page viewer by Vadim Pavlov
Unicode soft-hyphen fix (as used by RedHat) by Dan Edwards
Some optimisations by Eli Argon
Caching idea and code contribution by James Richardson
Copyright © 2003-2025 Linux.pl
Hosted by Hosting Linux.pl