.\" Man page generated from reStructuredText. . .TH "CMAKE-COMMANDS" "7" "September 13, 2021" "3.18.4" "CMake" .SH NAME cmake-commands \- CMake Language Command Reference . .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 .. .SH SCRIPTING COMMANDS .sp These commands are always available. .SS break .sp Break from an enclosing foreach or while loop. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C break() .ft P .fi .UNINDENT .UNINDENT .sp Breaks from an enclosing \fBforeach()\fP or \fBwhile()\fP loop. .sp See also the \fBcontinue()\fP command. .SS cmake_host_system_information .sp Query host system specific information. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_host_system_information(RESULT QUERY ...) .ft P .fi .UNINDENT .UNINDENT .sp Queries system information of the host system on which cmake runs. One or more \fB\fP can be provided to select the information to be queried. The list of queried values is stored in \fB\fP\&. .sp \fB\fP can be one of the following values: .TS center; |l|l|. _ T{ Key T} T{ Description T} _ T{ \fBNUMBER_OF_LOGICAL_CORES\fP T} T{ Number of logical cores T} _ T{ \fBNUMBER_OF_PHYSICAL_CORES\fP T} T{ Number of physical cores T} _ T{ \fBHOSTNAME\fP T} T{ Hostname T} _ T{ \fBFQDN\fP T} T{ Fully qualified domain name T} _ T{ \fBTOTAL_VIRTUAL_MEMORY\fP T} T{ Total virtual memory in MiB [1] T} _ T{ \fBAVAILABLE_VIRTUAL_MEMORY\fP T} T{ Available virtual memory in MiB [1] T} _ T{ \fBTOTAL_PHYSICAL_MEMORY\fP T} T{ Total physical memory in MiB [1] T} _ T{ \fBAVAILABLE_PHYSICAL_MEMORY\fP T} T{ Available physical memory in MiB [1] T} _ T{ \fBIS_64BIT\fP T} T{ One if processor is 64Bit T} _ T{ \fBHAS_FPU\fP T} T{ One if processor has floating point unit T} _ T{ \fBHAS_MMX\fP T} T{ One if processor supports MMX instructions T} _ T{ \fBHAS_MMX_PLUS\fP T} T{ One if processor supports Ext. MMX instructions T} _ T{ \fBHAS_SSE\fP T} T{ One if processor supports SSE instructions T} _ T{ \fBHAS_SSE2\fP T} T{ One if processor supports SSE2 instructions T} _ T{ \fBHAS_SSE_FP\fP T} T{ One if processor supports SSE FP instructions T} _ T{ \fBHAS_SSE_MMX\fP T} T{ One if processor supports SSE MMX instructions T} _ T{ \fBHAS_AMD_3DNOW\fP T} T{ One if processor supports 3DNow instructions T} _ T{ \fBHAS_AMD_3DNOW_PLUS\fP T} T{ One if processor supports 3DNow+ instructions T} _ T{ \fBHAS_IA64\fP T} T{ One if IA64 processor emulating x86 T} _ T{ \fBHAS_SERIAL_NUMBER\fP T} T{ One if processor has serial number T} _ T{ \fBPROCESSOR_SERIAL_NUMBER\fP T} T{ Processor serial number T} _ T{ \fBPROCESSOR_NAME\fP T} T{ Human readable processor name T} _ T{ \fBPROCESSOR_DESCRIPTION\fP T} T{ Human readable full processor description T} _ T{ \fBOS_NAME\fP T} T{ See \fBCMAKE_HOST_SYSTEM_NAME\fP T} _ T{ \fBOS_RELEASE\fP T} T{ The OS sub\-type e.g. on Windows \fBProfessional\fP T} _ T{ \fBOS_VERSION\fP T} T{ The OS build ID T} _ T{ \fBOS_PLATFORM\fP T} T{ See \fBCMAKE_HOST_SYSTEM_PROCESSOR\fP T} _ .TE .SH FOOTNOTES .IP [1] 5 One MiB (mebibyte) is equal to 1024x1024 bytes. .SS cmake_language .sp Call meta\-operations on CMake commands. .SS Synopsis .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_language(\fI\%CALL\fP [...]) cmake_language(\fI\%EVAL\fP CODE ...) .ft P .fi .UNINDENT .UNINDENT .SS Introduction .sp This command will call meta\-operations on built\-in CMake commands or those created via the \fBmacro()\fP or \fBfunction()\fP commands. .sp \fBcmake_language\fP does not introduce a new variable or policy scope. .SS Calling Commands .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_language(CALL [...]) .ft P .fi .UNINDENT .UNINDENT .sp Calls the named \fB\fP with the given arguments (if any). For example, the code: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C set(message_command "message") cmake_language(CALL ${message_command} STATUS "Hello World!") .ft P .fi .UNINDENT .UNINDENT .sp is equivalent to .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C message(STATUS "Hello World!") .ft P .fi .UNINDENT .UNINDENT .sp \fBNOTE:\fP .INDENT 0.0 .INDENT 3.5 To ensure consistency of the code, the following commands are not allowed: .INDENT 0.0 .IP \(bu 2 \fBif\fP / \fBelseif\fP / \fBelse\fP / \fBendif\fP .IP \(bu 2 \fBwhile\fP / \fBendwhile\fP .IP \(bu 2 \fBforeach\fP / \fBendforeach\fP .IP \(bu 2 \fBfunction\fP / \fBendfunction\fP .IP \(bu 2 \fBmacro\fP / \fBendmacro\fP .UNINDENT .UNINDENT .UNINDENT .SS Evaluating Code .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_language(EVAL CODE ...) .ft P .fi .UNINDENT .UNINDENT .sp Evaluates the \fB...\fP as CMake code. .sp For example, the code: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C set(A TRUE) set(B TRUE) set(C TRUE) set(condition "(A AND B) OR C") cmake_language(EVAL CODE " if (${condition}) message(STATUS TRUE) else() message(STATUS FALSE) endif()" ) .ft P .fi .UNINDENT .UNINDENT .sp is equivalent to .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C set(A TRUE) set(B TRUE) set(C TRUE) set(condition "(A AND B) OR C") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/eval.cmake " if (${condition}) message(STATUS TRUE) else() message(STATUS FALSE) endif()" ) include(${CMAKE_CURRENT_BINARY_DIR}/eval.cmake) .ft P .fi .UNINDENT .UNINDENT .SS cmake_minimum_required .sp Require a minimum version of cmake. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_minimum_required(VERSION [...] [FATAL_ERROR]) .ft P .fi .UNINDENT .UNINDENT .sp Sets the minimum required version of cmake for a project. Also updates the policy settings as explained below. .sp \fB\fP and the optional \fB\fP are each CMake versions of the form \fBmajor.minor[.patch[.tweak]]\fP, and the \fB\&...\fP is literal. .sp If the running version of CMake is lower than the \fB\fP required version it will stop processing the project and report an error. The optional \fB\fP version, if specified, must be at least the \fB\fP version and affects policy settings as described below. If the running version of CMake is older than 3.12, the extra \fB\&...\fP dots will be seen as version component separators, resulting in the \fB\&...\fP part being ignored and preserving the pre\-3.12 behavior of basing policies on \fB\fP\&. .sp The \fBFATAL_ERROR\fP option is accepted but ignored by CMake 2.6 and higher. It should be specified so CMake versions 2.4 and lower fail with an error instead of just a warning. .sp \fBNOTE:\fP .INDENT 0.0 .INDENT 3.5 Call the \fBcmake_minimum_required()\fP command at the beginning of the top\-level \fBCMakeLists.txt\fP file even before calling the \fBproject()\fP command. It is important to establish version and policy settings before invoking other commands whose behavior they may affect. See also policy \fBCMP0000\fP\&. .sp Calling \fBcmake_minimum_required()\fP inside a \fBfunction()\fP limits some effects to the function scope when invoked. Such calls should not be made with the intention of having global effects. .UNINDENT .UNINDENT .SS Policy Settings .sp The \fBcmake_minimum_required(VERSION)\fP command implicitly invokes the \fBcmake_policy(VERSION)\fP command to specify that the current project code is written for the given range of CMake versions. All policies known to the running version of CMake and introduced in the \fB\fP (or \fB\fP, if specified) version or earlier will be set to use \fBNEW\fP behavior. All policies introduced in later versions will be unset. This effectively requests behavior preferred as of a given CMake version and tells newer CMake versions to warn about their new policies. .sp When a \fB\fP version higher than 2.4 is specified the command implicitly invokes .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_policy(VERSION [...]) .ft P .fi .UNINDENT .UNINDENT .sp which sets CMake policies based on the range of versions specified. When a \fB\fP version 2.4 or lower is given the command implicitly invokes .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_policy(VERSION 2.4[...]) .ft P .fi .UNINDENT .UNINDENT .sp which enables compatibility features for CMake 2.4 and lower. .SS cmake_parse_arguments .sp Parse function or macro arguments. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_parse_arguments( ...) cmake_parse_arguments(PARSE_ARGV ) .ft P .fi .UNINDENT .UNINDENT .sp This command is for use in macros or functions. It processes the arguments given to that macro or function, and defines a set of variables which hold the values of the respective options. .sp The first signature reads processes arguments passed in the \fB...\fP\&. This may be used in either a \fBmacro()\fP or a \fBfunction()\fP\&. .sp The \fBPARSE_ARGV\fP signature is only for use in a \fBfunction()\fP body. In this case the arguments that are parsed come from the \fBARGV#\fP variables of the calling function. The parsing starts with the \fB\fP\-th argument, where \fB\fP is an unsigned integer. This allows for the values to have special characters like \fB;\fP in them. .sp The \fB\fP argument contains all options for the respective macro, i.e. keywords which can be used when calling the macro without any value following, like e.g. the \fBOPTIONAL\fP keyword of the \fBinstall()\fP command. .sp The \fB\fP argument contains all keywords for this macro which are followed by one value, like e.g. \fBDESTINATION\fP keyword of the \fBinstall()\fP command. .sp The \fB\fP argument contains all keywords for this macro which can be followed by more than one value, like e.g. the \fBTARGETS\fP or \fBFILES\fP keywords of the \fBinstall()\fP command. .sp \fBNOTE:\fP .INDENT 0.0 .INDENT 3.5 All keywords shall be unique. I.e. every keyword shall only be specified once in either \fB\fP, \fB\fP or \fB\fP\&. A warning will be emitted if uniqueness is violated. .UNINDENT .UNINDENT .sp When done, \fBcmake_parse_arguments\fP will consider for each of the keywords listed in \fB\fP, \fB\fP and \fB\fP a variable composed of the given \fB\fP followed by \fB"_"\fP and the name of the respective keyword. These variables will then hold the respective value from the argument list or be undefined if the associated option could not be found. For the \fB\fP keywords, these will always be defined, to \fBTRUE\fP or \fBFALSE\fP, whether the option is in the argument list or not. .sp All remaining arguments are collected in a variable \fB_UNPARSED_ARGUMENTS\fP that will be undefined if all arguments were recognized. This can be checked afterwards to see whether your macro was called with unrecognized parameters. .sp \fB\fP and \fB\fP that were given no values at all are collected in a variable \fB_KEYWORDS_MISSING_VALUES\fP that will be undefined if all keywords received values. This can be checked to see if there were keywords without any values given. .sp Consider the following example macro, \fBmy_install()\fP, which takes similar arguments to the real \fBinstall()\fP command: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C macro(my_install) set(options OPTIONAL FAST) set(oneValueArgs DESTINATION RENAME) set(multiValueArgs TARGETS CONFIGURATIONS) cmake_parse_arguments(MY_INSTALL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) # ... .ft P .fi .UNINDENT .UNINDENT .sp Assume \fBmy_install()\fP has been called like this: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub CONFIGURATIONS) .ft P .fi .UNINDENT .UNINDENT .sp After the \fBcmake_parse_arguments\fP call the macro will have set or undefined the following variables: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C MY_INSTALL_OPTIONAL = TRUE MY_INSTALL_FAST = FALSE # was not used in call to my_install MY_INSTALL_DESTINATION = "bin" MY_INSTALL_RENAME # was not used MY_INSTALL_TARGETS = "foo;bar" MY_INSTALL_CONFIGURATIONS # was not used MY_INSTALL_UNPARSED_ARGUMENTS = "blub" # nothing expected after "OPTIONAL" MY_INSTALL_KEYWORDS_MISSING_VALUES = "CONFIGURATIONS" # No value for "CONFIGURATIONS" given .ft P .fi .UNINDENT .UNINDENT .sp You can then continue and process these variables. .sp Keywords terminate lists of values, e.g. if directly after a \fBone_value_keyword\fP another recognized keyword follows, this is interpreted as the beginning of the new option. E.g. \fBmy_install(TARGETS foo DESTINATION OPTIONAL)\fP would result in \fBMY_INSTALL_DESTINATION\fP set to \fB"OPTIONAL"\fP, but as \fBOPTIONAL\fP is a keyword itself \fBMY_INSTALL_DESTINATION\fP will be empty (but added to \fBMY_INSTALL_KEYWORDS_MISSING_VALUES\fP) and \fBMY_INSTALL_OPTIONAL\fP will therefore be set to \fBTRUE\fP\&. .SS cmake_policy .sp Manage CMake Policy settings. See the \fBcmake\-policies(7)\fP manual for defined policies. .sp As CMake evolves it is sometimes necessary to change existing behavior in order to fix bugs or improve implementations of existing features. The CMake Policy mechanism is designed to help keep existing projects building as new versions of CMake introduce changes in behavior. Each new policy (behavioral change) is given an identifier of the form \fBCMP\fP where \fB\fP is an integer index. Documentation associated with each policy describes the \fBOLD\fP and \fBNEW\fP behavior and the reason the policy was introduced. Projects may set each policy to select the desired behavior. When CMake needs to know which behavior to use it checks for a setting specified by the project. If no setting is available the \fBOLD\fP behavior is assumed and a warning is produced requesting that the policy be set. .SS Setting Policies by CMake Version .sp The \fBcmake_policy\fP command is used to set policies to \fBOLD\fP or \fBNEW\fP behavior. While setting policies individually is supported, we encourage projects to set policies based on CMake versions: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_policy(VERSION [...]) .ft P .fi .UNINDENT .UNINDENT .sp \fB\fP and the optional \fB\fP are each CMake versions of the form \fBmajor.minor[.patch[.tweak]]\fP, and the \fB\&...\fP is literal. The \fB\fP version must be at least \fB2.4\fP and at most the running version of CMake. The \fB\fP version, if specified, must be at least the \fB\fP version but may exceed the running version of CMake. If the running version of CMake is older than 3.12, the extra \fB\&...\fP dots will be seen as version component separators, resulting in the \fB\&...\fP part being ignored and preserving the pre\-3.12 behavior of basing policies on \fB\fP\&. .sp This specifies that the current CMake code is written for the given range of CMake versions. All policies known to the running version of CMake and introduced in the \fB\fP (or \fB\fP, if specified) version or earlier will be set to use \fBNEW\fP behavior. All policies introduced in later versions will be unset (unless the \fBCMAKE_POLICY_DEFAULT_CMP\fP variable sets a default). This effectively requests behavior preferred as of a given CMake version and tells newer CMake versions to warn about their new policies. .sp Note that the \fBcmake_minimum_required(VERSION)\fP command implicitly calls \fBcmake_policy(VERSION)\fP too. .SS Setting Policies Explicitly .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_policy(SET CMP NEW) cmake_policy(SET CMP OLD) .ft P .fi .UNINDENT .UNINDENT .sp Tell CMake to use the \fBOLD\fP or \fBNEW\fP behavior for a given policy. Projects depending on the old behavior of a given policy may silence a policy warning by setting the policy state to \fBOLD\fP\&. Alternatively one may fix the project to work with the new behavior and set the policy state to \fBNEW\fP\&. .sp \fBNOTE:\fP .INDENT 0.0 .INDENT 3.5 The \fBOLD\fP behavior of a policy is \fBdeprecated by definition\fP and may be removed in a future version of CMake. .UNINDENT .UNINDENT .SS Checking Policy Settings .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_policy(GET CMP ) .ft P .fi .UNINDENT .UNINDENT .sp Check whether a given policy is set to \fBOLD\fP or \fBNEW\fP behavior. The output \fB\fP value will be \fBOLD\fP or \fBNEW\fP if the policy is set, and empty otherwise. .SS CMake Policy Stack .sp CMake keeps policy settings on a stack, so changes made by the \fBcmake_policy\fP command affect only the top of the stack. A new entry on the policy stack is managed automatically for each subdirectory to protect its parents and siblings. CMake also manages a new entry for scripts loaded by \fBinclude()\fP and \fBfind_package()\fP commands except when invoked with the \fBNO_POLICY_SCOPE\fP option (see also policy \fBCMP0011\fP). The \fBcmake_policy\fP command provides an interface to manage custom entries on the policy stack: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C cmake_policy(PUSH) cmake_policy(POP) .ft P .fi .UNINDENT .UNINDENT .sp Each \fBPUSH\fP must have a matching \fBPOP\fP to erase any changes. This is useful to make temporary changes to policy settings. Calls to the \fBcmake_minimum_required(VERSION)\fP, \fBcmake_policy(VERSION)\fP, or \fBcmake_policy(SET)\fP commands influence only the current top of the policy stack. .sp Commands created by the \fBfunction()\fP and \fBmacro()\fP commands record policy settings when they are created and use the pre\-record policies when they are invoked. If the function or macro implementation sets policies, the changes automatically propagate up through callers until they reach the closest nested policy stack entry. .SS configure_file .sp Copy a file to another location and modify its contents. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C configure_file( [COPYONLY] [ESCAPE_QUOTES] [@ONLY] [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ]) .ft P .fi .UNINDENT .UNINDENT .sp Copies an \fB\fP file to an \fB\fP file and substitutes variable values referenced as \fB@VAR@\fP or \fB${VAR}\fP in the input file content. Each variable reference will be replaced with the current value of the variable, or the empty string if the variable is not defined. Furthermore, input lines of the form .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C #cmakedefine VAR ... .ft P .fi .UNINDENT .UNINDENT .sp will be replaced with either .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C #define VAR ... .ft P .fi .UNINDENT .UNINDENT .sp or .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C /* #undef VAR */ .ft P .fi .UNINDENT .UNINDENT .sp depending on whether \fBVAR\fP is set in CMake to any value not considered a false constant by the \fBif()\fP command. The “…” content on the line after the variable name, if any, is processed as above. Input file lines of the form \fB#cmakedefine01 VAR\fP will be replaced with either \fB#define VAR 1\fP or \fB#define VAR 0\fP similarly. The result lines (with the exception of the \fB#undef\fP comments) can be indented using spaces and/or tabs between the \fB#\fP character and the \fBcmakedefine\fP or \fBcmakedefine01\fP words. This whitespace indentation will be preserved in the output lines: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C # cmakedefine VAR # cmakedefine01 VAR .ft P .fi .UNINDENT .UNINDENT .sp will be replaced, if \fBVAR\fP is defined, with .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C # define VAR # define VAR 1 .ft P .fi .UNINDENT .UNINDENT .sp If the input file is modified the build system will re\-run CMake to re\-configure the file and generate the build system again. The generated file is modified and its timestamp updated on subsequent cmake runs only if its content is changed. .sp The arguments are: .INDENT 0.0 .TP .B \fB\fP Path to the input file. A relative path is treated with respect to the value of \fBCMAKE_CURRENT_SOURCE_DIR\fP\&. The input path must be a file, not a directory. .TP .B \fB\fP Path to the output file or directory. A relative path is treated with respect to the value of \fBCMAKE_CURRENT_BINARY_DIR\fP\&. If the path names an existing directory the output file is placed in that directory with the same file name as the input file. .TP .B \fBCOPYONLY\fP Copy the file without replacing any variable references or other content. This option may not be used with \fBNEWLINE_STYLE\fP\&. .TP .B \fBESCAPE_QUOTES\fP Escape any substituted quotes with backslashes (C\-style). .TP .B \fB@ONLY\fP Restrict variable replacement to references of the form \fB@VAR@\fP\&. This is useful for configuring scripts that use \fB${VAR}\fP syntax. .TP .B \fBNEWLINE_STYLE