diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index ddde18385..2a2b7dc27 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -7,80 +7,174 @@ cmake-generator-expressions(7) .. contents:: -Generator Expressions -===================== +Introduction +============ -Generator expressions are evaluated during build -system generation to produce information specific to each build -configuration. Valid expressions are: +Generator expressions are evaluated during build system generation to produce +information specific to each build configuration. -:: +Generator expressions are allowed in the context of many target properties, +such as :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INCLUDE_DIRECTORIES`, +:prop_tgt:`COMPILE_DEFINITIONS` and others. They may also be used when using +commands to populate those properties, such as :command:`target_link_libraries`, +:command:`target_include_directories`, :command:`target_compile_definitions` +and others. - $<0:...> = empty string (ignores "...") - $<1:...> = content of "..." - $ = '1' if config is "cfg", else '0' - $ = configuration name - $ = '1' if the '...' is true, else '0' - $ = '1' if a is STREQUAL b, else '0' - $ = A literal '>'. Used to compare strings which contain a '>' for example. - $ = A literal ','. Used to compare strings which contain a ',' for example. - $ = A literal ';'. Used to prevent list expansion on an argument with ';'. - $ = joins the list with the content of "..." - $ = Marks ... as being the name of a target. This is required if exporting targets to multiple dependent export sets. The '...' must be a literal name of a target- it may not contain generator expressions. - $ = content of "..." when the property is exported using install(EXPORT), and empty otherwise. - $ = content of "..." when the property is exported using export(), or when the target is used by another target in the same buildsystem. Expands to the empty string otherwise. - $ = The CMake-id of the platform $ = '1' if the The CMake-id of the platform matches comp, otherwise '0'. - $ = The CMake-id of the C compiler used. - $ = '1' if the CMake-id of the C compiler matches comp, otherwise '0'. - $ = The CMake-id of the CXX compiler used. - $ = '1' if the CMake-id of the CXX compiler matches comp, otherwise '0'. - $ = '1' if v1 is a version greater than v2, else '0'. - $ = '1' if v1 is a version less than v2, else '0'. - $ = '1' if v1 is the same version as v2, else '0'. - $ = The version of the C compiler used. - $ = '1' if the version of the C compiler matches ver, otherwise '0'. - $ = The version of the CXX compiler used. - $ = '1' if the version of the CXX compiler matches ver, otherwise '0'. - $ = main file (.exe, .so.1.2, .a) - $ = file used to link (.a, .lib, .so) - $ = file with soname (.so.3) +This means that they enable conditional linking, conditional +definitions used when compiling, and conditional include directories and +more. The conditions may be based on the build configuration, target +properties, platform information or any other queryable information. -where "tgt" is the name of a target. Target file expressions produce -a full path, but _DIR and _NAME versions can produce the directory and -file name components: +Logical Expressions +=================== -:: +Logical expressions are used to create conditional output. The basic +expressions are the ``0`` and ``1`` expressions. Because other logical +expressions evaluate to either ``0`` or ``1``, they can be composed to +create conditional output:: - $/$ - $/$ - $/$ + $<$:DEBUG_MODE> +expands to ``DEBUG_MODE`` when the ``Debug`` configuration is used, and +otherwise expands to nothing. +``$<0:...>`` + Empty string (ignores ``...``) +``$<1:...>`` + Content of ``...`` +``$`` + ``1`` if the ``...`` is true, else ``0`` +``$`` + ``1`` if all ``?`` are ``1``, else ``0`` -:: + The ``?`` must always be either ``0`` or ``1`` in boolean expressions. - $ = The value of the property prop on the target tgt. +``$`` + ``0`` if all ``?`` are ``0``, else ``1`` +``$`` + ``0`` if ``?`` is ``1``, else ``1`` +``$`` + ``1`` if ``a`` is STREQUAL ``b``, else ``0`` +``$`` + ``1`` if config is ``cfg``, else ``0``. This is a case-insensitive comparison. + The mapping in :prop_tgt:`MAP_IMPORTED_CONFIG_` is also considered by + this expression when it is evaluated on a property on an :prop_tgt:`IMPORTED` + target. +``$`` + ``1`` if the CMake-id of the platform matches ``comp``, otherwise ``0``. +``$`` + ``1`` if the CMake-id of the C compiler matches ``comp``, otherwise ``0``. +``$`` + ``1`` if the CMake-id of the CXX compiler matches ``comp``, otherwise ``0``. +``$`` + ``1`` if ``v1`` is a version greater than ``v2``, else ``0``. +``$`` + ``1`` if ``v1`` is a version less than ``v2``, else ``0``. +``$`` + ``1`` if ``v1`` is the same version as ``v2``, else ``0``. +``$`` + ``1`` if the version of the C compiler matches ``ver``, otherwise ``0``. +``$`` + ``1`` if the version of the CXX compiler matches ``ver``, otherwise ``0``. +``$`` + ``1`` if the policy ``pol`` was NEW when the 'head' target was created, + else ``0``. If the policy was not set, the warning message for the policy + will be emitted. This generator expression only works for a subset of + policies. -Note that tgt is not added as a dependency of the target this -expression is evaluated on. +Informational Expressions +========================= -:: +These expressions expand to some information. The information may be used +directly, eg:: - $ = '1' if the policy was NEW when the 'head' target was created, else '0'. If the policy was not set, the warning message for the policy will be emitted. This generator expression only works for a subset of policies. - $ = Content of the install prefix when the target is exported via INSTALL(EXPORT) and empty otherwise. + include_directories(/usr/include/$/) -Boolean expressions: +expands to ``/usr/include/GNU/`` or ``/usr/include/Clang/`` etc, depending on +the Id of the compiler. -:: +These expressions may also may be combined with logical expressions:: - $ = '1' if all '?' are '1', else '0' - $ = '0' if all '?' are '0', else '1' - $ = '0' if '?' is '1', else '1' + $<$,4.2.0>:OLD_COMPILER> -where '?' is always either '0' or '1'. +expands to ``OLD_COMPILER`` if the +:variable:`CMAKE_CXX_COMPILER_VERSION _COMPILER_VERSION>` is less +than 4.2.0. -Expressions with an implicit 'this' target: +``$`` + Configuration name +``$`` + The CMake-id of the platform +``$`` + The CMake-id of the C compiler used. +``$`` + The CMake-id of the CXX compiler used. +``$`` + The version of the C compiler used. +``$`` + The version of the CXX compiler used. +``$`` + Full path to main file (.exe, .so.1.2, .a) where ``tgt`` is the name of a target. +``$`` + Name of main file (.exe, .so.1.2, .a). +``$`` + Directory of main file (.exe, .so.1.2, .a). +``$`` + File used to link (.a, .lib, .so) where ``tgt`` is the name of a target. +``$`` + Name of file used to link (.a, .lib, .so). +``$`` + Directory of file used to link (.a, .lib, .so). +``$`` + File with soname (.so.3) where ``tgt`` is the name of a target. +``$`` + Name of file with soname (.so.3). +``$`` + Directory of with soname (.so.3). +``$`` + Value of the property ``prop`` on the target ``tgt``. -:: + Note that ``tgt`` is not added as a dependency of the target this + expression is evaluated on. +``$`` + Value of the property ``prop`` on the target on which the generator + expression is evaluated. +``$`` + Content of the install prefix when the target is exported via + :command:`install(EXPORT)` and empty otherwise. - $ = The value of the property prop on the target on which the generator expression is evaluated. +Output Expressions +================== + +These expressions generate output, in some cases depending on an input. These +expressions may be combined with other expressions for information or logical +comparison:: + + -I$, -I> + +generates a string of the entries in the :prop_tgt:`INCLUDE_DIRECTORIES` target +property with each entry preceeded by ``-I``. Note that a more-complete use +in this situation would be require first checking if the INCLUDE_DIRECTORIES +property is non-empty:: + + $<$>:-I$, -I>> + +``$`` + Joins the list with the content of ``...`` +``$`` + A literal ``>``. Used to compare strings which contain a ``>`` for example. +``$`` + A literal ``,``. Used to compare strings which contain a ``,`` for example. +``$`` + A literal ``;``. Used to prevent list expansion on an argument with ``;``. +``$`` + Marks ``...`` as being the name of a target. This is required if exporting + targets to multiple dependent export sets. The ``...`` must be a literal + name of a target- it may not contain generator expressions. +``$`` + Content of ``...`` when the property is exported using :command:`install(EXPORT)`, + and empty otherwise. +``$`` + Content of ``...`` when the property is exported using :command:`export`, or + when the target is used by another target in the same buildsystem. Expands to + the empty string otherwise.