summaryrefslogtreecommitdiffstats
path: root/Help
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-11-17 19:46:53 (GMT)
committerBrad King <brad.king@kitware.com>2017-11-20 18:51:25 (GMT)
commit2ae880fa8f04a2026939b1df9613b64a301aa522 (patch)
treea0b87a17d369cb7b81360752bdbb8ab4d9ebdd29 /Help
parent2b7d59f3109483bfa45dc41e2a2f6a2f82addfec (diff)
downloadCMake-2ae880fa8f04a2026939b1df9613b64a301aa522.zip
CMake-2ae880fa8f04a2026939b1df9613b64a301aa522.tar.gz
CMake-2ae880fa8f04a2026939b1df9613b64a301aa522.tar.bz2
Genex: Enable COMPILE_LANGUAGE for COMPILE_OPTIONS with Visual Studio
Since commit v3.9.0-rc4~3^2~1 (VS: Fix target_compile_options for CUDA, 2017-06-21), the evaluation of `COMPILE_LANGUAGE` receives the proper language. 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 `COMPILE_OPTIONS` to match the selected language. This is not exactly the same as for other generators, but is the best VS can do. It is also sufficient for many use cases since the set of allowed flags for C and C++ is almost the same in Visual Studio. Furthermore, since the VS generator moves many of the flags to declarative `.vcxproj` elements, it will automatically avoid passing C++ flags for C sources. Issue: #17435
Diffstat (limited to 'Help')
-rw-r--r--Help/manual/cmake-generator-expressions.7.rst12
-rw-r--r--Help/release/dev/extend-compile-language-genex.rst7
2 files changed, 14 insertions, 5 deletions
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst
index bddb174..dc5621a 100644
--- a/Help/manual/cmake-generator-expressions.7.rst
+++ b/Help/manual/cmake-generator-expressions.7.rst
@@ -97,7 +97,7 @@ 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 used to specify compile options for
+ otherwise ``0``. This expression may be 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):
@@ -109,10 +109,12 @@ Available logical expressions are:
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:
+ Note that with :ref:`Visual Studio Generators` there is no way to represent
+ target-wide flags separately for ``C`` and ``CXX`` languages. Under these
+ generators, target-wide flags for both C and C++ sources will be evaluated
+ using ``CXX`` if there are any C++ sources and otherwise using ``C``.
+ A workaround is to create separate libraries for each source file language
+ instead:
.. code-block:: cmake
diff --git a/Help/release/dev/extend-compile-language-genex.rst b/Help/release/dev/extend-compile-language-genex.rst
new file mode 100644
index 0000000..0a0a669
--- /dev/null
+++ b/Help/release/dev/extend-compile-language-genex.rst
@@ -0,0 +1,7 @@
+extend-compile-language-genex
+-----------------------------
+
+* The ``COMPILE_LANGUAGE`` :manual:`generator expression
+ <cmake-generator-expressions(7)>` may now be used with
+ :ref:`Visual Studio Generators` in :prop_tgt:`COMPILE_OPTIONS`
+ and :command:`file(GENERATE)`.