diff options
author | Brad King <brad.king@kitware.com> | 2018-01-11 19:32:13 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-01-12 19:27:37 (GMT) |
commit | 506fda1cf026a88378589009b62ca8bf633c5197 (patch) | |
tree | 2095056002a42332f5e8f2741daa29eb8880db10 /Help/manual | |
parent | c2f79c98677d43fb8686f9e4309acddfae8f3dfd (diff) | |
download | CMake-506fda1cf026a88378589009b62ca8bf633c5197.zip CMake-506fda1cf026a88378589009b62ca8bf633c5197.tar.gz CMake-506fda1cf026a88378589009b62ca8bf633c5197.tar.bz2 |
Genex: Enable COMPILE_LANGUAGE for INCLUDE_DIRECTORIES with VS and Xcode
The set of compile flags used for a target's C and C++ sources is based
on the linker language. By default this is always the C++ flags if any
C++ sources appear in the target, and otherwise the C flags. Therefore
we can define the `COMPILE_LANGUAGE` generator expression in
`INCLUDE_DIRECTORIES` to match the selected language.
This is not exactly the same as for other generators, but is the best VS
and Xcode can do. It is also sufficient for many use cases since the
set of include directories for C and C++ is frequently similar but may
be distinct from those for other languages like CUDA.
Fixes: #17435
Diffstat (limited to 'Help/manual')
-rw-r--r-- | Help/manual/cmake-generator-expressions.7.rst | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index 85130a0..0f6d4cf 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -97,27 +97,32 @@ Available logical expressions are: 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 may be used to specify compile options - and compile definitions for source files of a + otherwise ``0``. This expression may be used to specify compile options, + compile definitions, and include directories for source files of a particular language in a target. For example: .. code-block:: cmake - add_executable(myapp main.cpp foo.c bar.cpp) + add_executable(myapp main.cpp foo.c bar.cpp zot.cu) target_compile_options(myapp PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions> ) target_compile_definitions(myapp PRIVATE $<$<COMPILE_LANGUAGE:CXX>:COMPILING_CXX> + $<$<COMPILE_LANGUAGE:CUDA>:COMPILING_CUDA> + ) + target_include_directories(myapp + PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/opt/foo/cxx_headers> ) - This specifies the use of the ``-fno-exceptions`` compile option - and ``COMPILING_CXX`` compile definition for C++ only - (compiler id checks elided). + This specifies the use of the ``-fno-exceptions`` compile option, + ``COMPILING_CXX`` compile definition, and ``cxx_headers`` include + directory for C++ only (compiler id checks elided). It also specifies + a ``COMPILING_CUDA`` compile definition for CUDA. Note that with :ref:`Visual Studio Generators` and :generator:`Xcode` there - is no way to represent target-wide compile definitions separately for - ``C`` and ``CXX`` languages. + is no way to represent target-wide compile definitions or include directories + separately for ``C`` and ``CXX`` languages. Also, with :ref:`Visual Studio Generators` there is no way to represent target-wide flags separately for ``C`` and ``CXX`` languages. Under these generators, expressions for both C and C++ sources will be evaluated @@ -133,16 +138,6 @@ Available logical expressions are: 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 include directories: - - .. code-block:: cmake - - add_executable(myapp main.cpp foo.c bar.cpp) - target_include_directories(myapp - PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/opt/foo/cxx_headers> - ) - Informational Expressions ========================= |