cmake-commands(7) ***************** Scripting Commands ================== These commands are always available. break ----- Break from an enclosing foreach or while loop. :: break() Breaks from an enclosing foreach loop or while loop See also the ``continue()`` command. cmake_host_system_information ----------------------------- Query host system specific information. :: cmake_host_system_information(RESULT QUERY ...) Queries system information of the host system on which cmake runs. One or more ```` can be provided to select the information to be queried. The list of queried values is stored in ````. ```` can be one of the following values: :: NUMBER_OF_LOGICAL_CORES = Number of logical cores. NUMBER_OF_PHYSICAL_CORES = Number of physical cores. HOSTNAME = Hostname. FQDN = Fully qualified domain name. TOTAL_VIRTUAL_MEMORY = Total virtual memory in megabytes. AVAILABLE_VIRTUAL_MEMORY = Available virtual memory in megabytes. TOTAL_PHYSICAL_MEMORY = Total physical memory in megabytes. AVAILABLE_PHYSICAL_MEMORY = Available physical memory in megabytes. cmake_minimum_required ---------------------- Set the minimum required version of cmake for a project and update `Policy Settings`_ to match the version given:: cmake_minimum_required(VERSION major.minor[.patch[.tweak]] [FATAL_ERROR]) If the current version of CMake is lower than that required it will stop processing the project and report an error. The ``FATAL_ERROR`` 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. .. note:: Call the ``cmake_minimum_required()`` command at the beginning of the top-level ``CMakeLists.txt`` file even before calling the ``project()`` command. It is important to establish version and policy settings before invoking other commands whose behavior they may affect. See also policy ``CMP0000``. Calling ``cmake_minimum_required()`` inside a ``function()`` limits some effects to the function scope when invoked. Such calls should not be made with the intention of having global effects. Policy Settings ^^^^^^^^^^^^^^^ The ``cmake_minimum_required(VERSION)`` command implicitly invokes the ``cmake_policy(VERSION)`` command to specify that the current project code is written for the given version of CMake. All policies introduced in the specified version or earlier will be set to use NEW behavior. All policies introduced after the specified version 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. When a version higher than 2.4 is specified the command implicitly invokes:: cmake_policy(VERSION major[.minor[.patch[.tweak]]]) which sets the cmake policy version level to the version specified. When version 2.4 or lower is given the command implicitly invokes:: cmake_policy(VERSION 2.4) which enables compatibility features for CMake 2.4 and lower. cmake_parse_arguments --------------------- ``cmake_parse_arguments`` is intended to be used in macros or functions for parsing the arguments given to that macro or function. It processes the arguments and defines a set of variables which hold the values of the respective options. :: cmake_parse_arguments( args...) cmake_parse_arguments(PARSE_ARGV N ) The first signature reads processes arguments passed in the ``args...``. This may be used in either a ``macro()`` or a ``function()``. The ``PARSE_ARGV`` signature is only for use in a ``function()`` body. In this case the arguments that are parsed come from the ``ARGV#`` variables of the calling function. The parsing starts with the Nth argument, where ``N`` is an unsigned integer. This allows for the values to have special characters like ``;`` in them. The ```` 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 ``OPTIONAL`` keyword of the ``install()`` command. The ```` argument contains all keywords for this macro which are followed by one value, like e.g. ``DESTINATION`` keyword of the ``install()`` command. The ```` argument contains all keywords for this macro which can be followed by more than one value, like e.g. the ``TARGETS`` or ``FILES`` keywords of the ``install()`` command. .. note:: All keywords shall be unique. I.e. every keyword shall only be specified once in either ````, ```` or ````. A warning will be emitted if uniqueness is violated. When done, ``cmake_parse_arguments`` will have defined for each of the keywords listed in ````, ```` and ```` a variable composed of the given ```` followed by ``"_"`` and the name of the respective keyword. These variables will then hold the respective value from the argument list. For the ```` keywords this will be ``TRUE`` or ``FALSE``. All remaining arguments are collected in a variable ``_UNPARSED_ARGUMENTS``, this can be checked afterwards to see whether your macro was called with unrecognized parameters. As an example here a ``my_install()`` macro, which takes similar arguments as the real ``install()`` command: function(MY_INSTALL) set(options OPTIONAL FAST) set(oneValueArgs DESTINATION RENAME) set(multiValueArgs TARGETS CONFIGURATIONS) cmake_parse_arguments(MY_INSTALL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) # ... Assume ``my_install()`` has been called like this: my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub) After the ``cmake_parse_arguments`` call the macro will have set the following variables:: 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") You can then continue and process these variables. Keywords terminate lists of values, e.g. if directly after a one_value_keyword another recognized keyword follows, this is interpreted as the beginning of the new option. E.g. ``my_install(TARGETS foo DESTINATION OPTIONAL)`` would result in ``MY_INSTALL_DESTINATION`` set to ``"OPTIONAL"``, but as ``OPTIONAL`` is a keyword itself ``MY_INSTALL_DESTINATION`` will be empty and ``MY_INSTALL_OPTIONAL`` will therefore be set to ``TRUE``. cmake_policy ------------ Manage CMake Policy settings. See the ``cmake-policies(7)`` manual for defined policies. 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 ``CMP`` where ```` is an integer index. Documentation associated with each policy describes the ``OLD`` and ``NEW`` 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 ``OLD`` behavior is assumed and a warning is produced requesting that the policy be set. Setting Policies by CMake Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The ``cmake_policy`` command is used to set policies to ``OLD`` or ``NEW`` behavior. While setting policies individually is supported, we encourage projects to set policies based on CMake versions:: cmake_policy(VERSION major.minor[.patch[.tweak]]) Specify that the current CMake code is written for the given version of CMake. All policies introduced in the specified version or earlier will be set to use ``NEW`` behavior. All policies introduced after the specified version will be unset (unless the ``CMAKE_POLICY_DEFAULT_CMP`` 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. The policy version specified must be at least 2.4 or the command will report an error. Note that the ``cmake_minimum_required(VERSION)`` command implicitly calls ``cmake_policy(VERSION)`` too. Setting Policies Explicitly ^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: cmake_policy(SET CMP NEW) cmake_policy(SET CMP OLD) Tell CMake to use the ``OLD`` or ``NEW`` 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 ``OLD``. Alternatively one may fix the project to work with the new behavior and set the policy state to ``NEW``. .. note:: The ``OLD`` behavior of a policy is ``deprecated by definition`` and may be removed in a future version of CMake. Checking Policy Settings ^^^^^^^^^^^^^^^^^^^^^^^^ :: cmake_policy(GET CMP ) Check whether a given policy is set to ``OLD`` or ``NEW`` behavior. The output ```` value will be ``OLD`` or ``NEW`` if the policy is set, and empty otherwise. CMake Policy Stack ^^^^^^^^^^^^^^^^^^ CMake keeps policy settings on a stack, so changes made by the cmake_policy 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 ``include()`` and ``find_package()`` commands except when invoked with the ``NO_POLICY_SCOPE`` option (see also policy ``CMP0011``). The ``cmake_policy`` command provides an interface to manage custom entries on the policy stack:: cmake_policy(PUSH) cmake_policy(POP) Each ``PUSH`` must have a matching ``POP`` to erase any changes. This is useful to make temporary changes to policy settings. Calls to the ``cmake_minimum_required(VERSION)``, ``cmake_policy(VERSION)``, or ``cmake_policy(SET)`` commands influence only the current top of the policy stack. Commands created by the ``function()`` and ``macro()`` 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. configure_file -------------- Copy a file to another location and modify its contents. :: configure_file( [COPYONLY] [ESCAPE_QUOTES] [@ONLY] [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ]) Copies an ```` file to an ```` file and substitutes variable values referenced as ``@VAR@`` or ``${VAR}`` 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:: #cmakedefine VAR ... will be replaced with either:: #define VAR ... or:: /* #undef VAR */ depending on whether ``VAR`` is set in CMake to any value not considered a false constant by the ``if()`` command. The "..." content on the line after the variable name, if any, is processed as above. Input file lines of the form ``#cmakedefine01 VAR`` will be replaced with either ``#define VAR 1`` or ``#define VAR 0`` similarly. 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 arguments are: ```` Path to the input file. A relative path is treated with respect to the value of ``CMAKE_CURRENT_SOURCE_DIR``. The input path must be a file, not a directory. ```` Path to the output file or directory. A relative path is treated with respect to the value of ``CMAKE_CURRENT_BINARY_DIR``. If the path names an existing directory the output file is placed in that directory with the same file name as the input file. ``COPYONLY`` Copy the file without replacing any variable references or other content. This option may not be used with ``NEWLINE_STYLE``. ``ESCAPE_QUOTES`` Escape any substituted quotes with backslashes (C-style). ``@ONLY`` Restrict variable replacement to references of the form ``@VAR@``. This is useful for configuring scripts that use ``${VAR}`` syntax. ``NEWLINE_STYLE