summaryrefslogtreecommitdiffstats
path: root/Help/manual/cmake-generator-expressions.7.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Help/manual/cmake-generator-expressions.7.rst')
-rw-r--r--Help/manual/cmake-generator-expressions.7.rst54
1 files changed, 49 insertions, 5 deletions
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst
index c47a7c4..189c3ef 100644
--- a/Help/manual/cmake-generator-expressions.7.rst
+++ b/Help/manual/cmake-generator-expressions.7.rst
@@ -40,10 +40,6 @@ otherwise expands to nothing.
Available logical expressions are:
-``$<0:...>``
- Empty string (ignores ``...``)
-``$<1:...>``
- Content of ``...``
``$<BOOL:...>``
``1`` if the ``...`` is true, else ``0``
``$<AND:?[,?]...>``
@@ -92,7 +88,47 @@ Available logical expressions are:
increases the required :prop_tgt:`C_STANDARD` or :prop_tgt:`CXX_STANDARD`
for the 'head' target, an error is reported. See the
:manual:`cmake-compile-features(7)` manual for information on
- compile features.
+ compile features and a list of supported compilers.
+``$<COMPILE_LANGUAGE:lang>``
+ ``1`` when the language used for compilation unit matches ``lang``,
+ otherwise ``0``. This expression used to specify compile options for
+ source files of a particular language in a target. For example, to specify
+ the use of the ``-fno-exceptions`` compile option (compiler id checks
+ elided):
+
+ .. code-block:: cmake
+
+ add_executable(myapp main.cpp foo.c bar.cpp)
+ target_compile_options(myapp
+ PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
+ )
+
+ This generator expression has limited use because it is not possible to
+ use it with the Visual Studio generators. Portable buildsystems would
+ not use this expression, and would create separate libraries for each
+ source file language instead:
+
+ .. code-block:: cmake
+
+ add_library(myapp_c foo.c)
+ add_library(myapp_cxx foo.c)
+ target_compile_options(myapp_cxx PUBLIC -fno-exceptions)
+ add_executable(myapp main.cpp)
+ target_link_libraries(myapp myapp_c myapp_cxx)
+
+ The ``Makefile`` and ``Ninja`` based generators can also use this
+ expression to specify compile-language specific compile definitions
+ and include directories:
+
+ .. code-block:: cmake
+
+ add_executable(myapp main.cpp foo.c bar.cpp)
+ target_compile_definitions(myapp
+ PRIVATE $<$<COMPILE_LANGUAGE:CXX>:COMPILING_CXX>
+ )
+ target_include_directories(myapp
+ PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/opt/foo/cxx_headers>
+ )
Informational Expressions
=========================
@@ -174,6 +210,10 @@ Available informational expressions are:
``$<INSTALL_PREFIX>``
Content of the install prefix when the target is exported via
:command:`install(EXPORT)` and empty otherwise.
+``$<COMPILE_LANGUAGE>``
+ The compile language of source files when evaluating compile options. See
+ the unary version for notes about portability of this generator
+ expression.
Output Expressions
==================
@@ -197,6 +237,10 @@ where ``${prop}`` refers to a helper variable::
Available output expressions are:
+``$<0:...>``
+ Empty string (ignores ``...``)
+``$<1:...>``
+ Content of ``...``
``$<JOIN:list,...>``
Joins the list with the content of ``...``
``$<ANGLE-R>``