summaryrefslogtreecommitdiffstats
path: root/Help
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-11-17 15:15:55 (GMT)
committerBrad King <brad.king@kitware.com>2022-11-18 16:44:52 (GMT)
commit914571a04249ee561a30309197d8e1c1cacbe18b (patch)
tree81bcf00395d68dd29fe3099d4ba588ed7701ede1 /Help
parentad16ae5c70778e6bfd6d30b17a3ad9b248b2a569 (diff)
downloadCMake-914571a04249ee561a30309197d8e1c1cacbe18b.zip
CMake-914571a04249ee561a30309197d8e1c1cacbe18b.tar.gz
CMake-914571a04249ee561a30309197d8e1c1cacbe18b.tar.bz2
Place language standard flags just after CMAKE_<LANG>_FLAGS
Previously we added the language standard flag near the end of all options, even after those added by `add_compile_options` and friends. However, on some compilers such as MSVC, the `-std` flag may reset defaults for flags that precede it on the command line. Move the language standard flag to before all other flags that CMake adds for other abstractions, and before those added by `add_compile_options`. `CMAKE_<LANG>_FLAGS` should still precede the language flags though, because they are meant to be treated as language-wide modifications to the compiler defaults, similar to `$CC $CFLAGS`. Fixes: #23860 Fixes: #24170
Diffstat (limited to 'Help')
-rw-r--r--Help/manual/cmake-compile-features.7.rst22
-rw-r--r--Help/release/dev/lang-std-flag-order.rst7
2 files changed, 29 insertions, 0 deletions
diff --git a/Help/manual/cmake-compile-features.7.rst b/Help/manual/cmake-compile-features.7.rst
index 8073511..1e87ec6 100644
--- a/Help/manual/cmake-compile-features.7.rst
+++ b/Help/manual/cmake-compile-features.7.rst
@@ -282,3 +282,25 @@ versions specified for each:
* ``Clang``: Clang compiler 5.0+.
* ``NVIDIA``: NVIDIA nvcc compiler 7.5+.
+
+.. _`Language Standard Flags`:
+
+Language Standard Flags
+=======================
+
+In order to satisfy requirements specified by the
+:command:`target_compile_features` command or the
+:variable:`CMAKE_<LANG>_STANDARD` variable, CMake may pass a
+language standard flag to the compiler, such as ``-std=c++11``.
+
+For :ref:`Visual Studio Generators`, CMake cannot precisely control
+the placement of the language standard flag on the compiler command line.
+For :ref:`Ninja Generators`, :ref:`Makefile Generators`, and
+:generator:`Xcode`, CMake places the language standard flag just after
+the language-wide flags from :variable:`CMAKE_<LANG>_FLAGS`
+and :variable:`CMAKE_<LANG>_FLAGS_<CONFIG>`.
+
+.. versionchanged:: 3.26
+ The language standard flag is placed before flags specified by other
+ abstractions such as the :command:`target_compile_options` command.
+ Prior to CMake 3.26, the language standard flag was placed after them.
diff --git a/Help/release/dev/lang-std-flag-order.rst b/Help/release/dev/lang-std-flag-order.rst
new file mode 100644
index 0000000..4ef4123
--- /dev/null
+++ b/Help/release/dev/lang-std-flag-order.rst
@@ -0,0 +1,7 @@
+lang-std-flag-order
+-------------------
+
+* :ref:`Language Standard Flags`, such as ``-std=c++11``, when generated due
+ to :command:`target_compile_features` or :variable:`CMAKE_<LANG>_STANDARD`,
+ are now placed before flags added by :command:`target_compile_options`,
+ rather than after them.