Cmake generator expressions
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 LINK_LIBRARIES, INCLUDE_DIRECTORIES, COMPILE_DEFINITIONS and others. They may also be used when using commands to populate those properties, such as target_link_libraries(), target_include_directories(), target_compile_definitions() and others.
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.
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:
expands to DEBUG_MODE when the Debug configuration is used, and otherwise expands to nothing.
Empty string (ignores ...)
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.
0 if all ? are 0, else 1
0 if ? is 1, else 1
1 if a is STREQUAL b, else 0
1 if a is EQUAL b in a numeric comparison, else 0
1 if config is cfg, else 0. This is a case-insensitive comparison. The mapping in MAP_IMPORTED_CONFIG_<CONFIG> is also considered by this expression when it is evaluated on a property on an 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.
These expressions expand to some information. The information may be used directly, eg:
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:
expands to OLD_COMPILER if the CMAKE_CXX_COMPILER_VERSION is less than 4.2.0.
Configuration name. Deprecated. Use CONFIG instead.
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 install(EXPORT) and empty otherwise.
These expressions generate output, in some cases depending on an input. These expressions may be combined with other expressions for information or logical comparison:
generates a string of the entries in the INCLUDE_DIRECTORIES target property with each entry preceeded by -I. Note that a more-complete use in this situation would require first checking if the INCLUDE_DIRECTORIES property is non-empty:
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 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.
Content of ... converted to lower case.
Content of ... converted to upper case.
Content of ... converted to a C identifier.
2000-2014 Kitware, Inc.