diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2019-05-07 20:21:17 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-05-14 18:54:15 (GMT) |
commit | e214abdaab4f8097095a601067b4071194ad01a5 (patch) | |
tree | fbc5642c2d890cb5e0d185bc34326963feef52c3 /Help | |
parent | f84ed796a220c6a4879f08e9003fe5489d8d104d (diff) | |
download | CMake-e214abdaab4f8097095a601067b4071194ad01a5.zip CMake-e214abdaab4f8097095a601067b4071194ad01a5.tar.gz CMake-e214abdaab4f8097095a601067b4071194ad01a5.tar.bz2 |
Genex: Add COMPILE_LANG_AND_ID generator expression
Diffstat (limited to 'Help')
-rw-r--r-- | Help/manual/cmake-generator-expressions.7.rst | 36 | ||||
-rw-r--r-- | Help/release/dev/genex-COMPILE_LANG_AND_ID.rst | 7 |
2 files changed, 43 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, diff --git a/Help/release/dev/genex-COMPILE_LANG_AND_ID.rst b/Help/release/dev/genex-COMPILE_LANG_AND_ID.rst new file mode 100644 index 0000000..27e0ebd --- /dev/null +++ b/Help/release/dev/genex-COMPILE_LANG_AND_ID.rst @@ -0,0 +1,7 @@ +genex-COMPILE_LANG_AND_ID +-------------------------- + +* A new ``COMPILE_LANG_AND_ID`` generator expression was introduced to + allow specification of compile options for target files based on the + :variable:`CMAKE_<LANG>_COMPILER_ID` and :prop_sf:`LANGUAGE` and of + each source file. |