summaryrefslogtreecommitdiffstats
path: root/Help/manual/cmake-generator-expressions.7.rst
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2019-05-07 20:21:17 (GMT)
committerBrad King <brad.king@kitware.com>2019-05-14 18:54:15 (GMT)
commite214abdaab4f8097095a601067b4071194ad01a5 (patch)
treefbc5642c2d890cb5e0d185bc34326963feef52c3 /Help/manual/cmake-generator-expressions.7.rst
parentf84ed796a220c6a4879f08e9003fe5489d8d104d (diff)
downloadCMake-e214abdaab4f8097095a601067b4071194ad01a5.zip
CMake-e214abdaab4f8097095a601067b4071194ad01a5.tar.gz
CMake-e214abdaab4f8097095a601067b4071194ad01a5.tar.bz2
Genex: Add COMPILE_LANG_AND_ID generator expression
Diffstat (limited to 'Help/manual/cmake-generator-expressions.7.rst')
-rw-r--r--Help/manual/cmake-generator-expressions.7.rst36
1 files changed, 36 insertions, 0 deletions
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst
index df06284..f2e6597 100644
--- a/Help/manual/cmake-generator-expressions.7.rst
+++ b/Help/manual/cmake-generator-expressions.7.rst
@@ -158,6 +158,42 @@ Variable Queries
.. _`Boolean COMPILE_LANGUAGE Generator Expression`:
+``$<COMPILE_LANG_AND_ID:language,compiler_id>``
+ ``1`` when the language used for compilation unit matches ``language`` and
+ the CMake's compiler id of the language compiler matches ``compiler_id``,
+ otherwise ``0``. This expression is a short form for the combination of
+ ``$<COMPILE_LANGUAGE:language>`` and ``$<LANG_COMPILER_ID:compiler_id>``.
+ This expression may be used to specify compile options,
+ compile definitions, and include directories for source files of a
+ particular language and compiler combination in a target. For example:
+
+ .. code-block:: cmake
+
+ add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
+ target_compile_definitions(myapp
+ PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,Clang>:COMPILING_CXX_WITH_CLANG>
+ $<$<COMPILE_LANG_AND_ID:CXX,Intel>:COMPILING_CXX_WITH_INTEL>
+ $<$<COMPILE_LANG_AND_ID:C,Clang>:COMPILING_C_WITH_CLANG>
+ )
+
+ This specifies the use of different compile definitions based on both
+ the compiler id and compilation language. This example will have a
+ ``COMPILING_CXX_WITH_CLANG`` compile definition when Clang is the CXX
+ compiler, and ``COMPILING_CXX_WITH_INTEL`` when Intel is the CXX compiler.
+ Likewise when the C compiler is Clang it will only see the ``COMPILING_C_WITH_CLANG``
+ definition.
+
+ Without the ``COMPILE_LANG_AND_ID`` generator expression the same logic
+ would be expressed as:
+
+ .. code-block:: cmake
+
+ target_compile_definitions(myapp
+ PRIVATE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Clang>>:COMPILING_CXX_WITH_CLANG>
+ $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Intel>>:COMPILING_CXX_WITH_INTEL>
+ $<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:Clang>>:COMPILING_C_WITH_CLANG>
+ )
+
``$<COMPILE_LANGUAGE:language>``
``1`` when the language used for compilation unit matches ``language``,
otherwise ``0``. This expression may be used to specify compile options,