Forráskód Böngészése

Merge topic 'default_extensions'

4a0485be7f cmStandardLevelResolver: Avoid unnecessary flags, fix unset level logic
29e2b85171 Tests: Simplify RunCMake.CompileFeatures introspection
fc3a1cbdd8 CompilerID: Compiler extensions default detection
2adfd95d79 CompilerID: Rename language_dialect to language_standard
00055d7779 Help: Document CMAKE_<LANG>_STANDARD_DEFAULT
a65bee4cfc Help: Document HIP standard/extensions properties and variables
a40ff1bb5a Help: Make language standard/extensions variable pages less wordy
3feff8379b Help: Generic language standard and extension variables documentation

Acked-by: Kitware Robot <[email protected]>
Merge-request: !6177
Brad King 4 éve
szülő
commit
c55a41c9b2
67 módosított fájl, 819 hozzáadás és 194 törlés
  1. 5 6
      Help/manual/cmake-compile-features.7.rst
  2. 1 0
      Help/manual/cmake-policies.7.rst
  3. 6 0
      Help/manual/cmake-properties.7.rst
  4. 8 0
      Help/manual/cmake-variables.7.rst
  5. 78 0
      Help/policy/CMP0128.rst
  6. 19 0
      Help/prop_tgt/HIP_EXTENSIONS.rst
  7. 48 0
      Help/prop_tgt/HIP_STANDARD.rst
  8. 19 0
      Help/prop_tgt/HIP_STANDARD_REQUIRED.rst
  9. 23 0
      Help/prop_tgt/LANG_EXTENSIONS.rst
  10. 26 0
      Help/prop_tgt/LANG_STANDARD.rst
  11. 26 0
      Help/prop_tgt/LANG_STANDARD_REQUIRED.rst
  12. 10 0
      Help/release/dev/compile-features-standard-logic-rework.rst
  13. 2 5
      Help/variable/CMAKE_CUDA_EXTENSIONS.rst
  14. 2 5
      Help/variable/CMAKE_CUDA_STANDARD.rst
  15. 2 5
      Help/variable/CMAKE_CUDA_STANDARD_REQUIRED.rst
  16. 2 5
      Help/variable/CMAKE_CXX_EXTENSIONS.rst
  17. 2 5
      Help/variable/CMAKE_CXX_STANDARD.rst
  18. 2 5
      Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst
  19. 2 5
      Help/variable/CMAKE_C_EXTENSIONS.rst
  20. 2 5
      Help/variable/CMAKE_C_STANDARD.rst
  21. 2 5
      Help/variable/CMAKE_C_STANDARD_REQUIRED.rst
  22. 10 0
      Help/variable/CMAKE_HIP_EXTENSIONS.rst
  23. 10 0
      Help/variable/CMAKE_HIP_STANDARD.rst
  24. 10 0
      Help/variable/CMAKE_HIP_STANDARD_REQUIRED.rst
  25. 19 0
      Help/variable/CMAKE_LANG_EXTENSIONS.rst
  26. 7 0
      Help/variable/CMAKE_LANG_EXTENSIONS_DEFAULT.rst
  27. 19 0
      Help/variable/CMAKE_LANG_STANDARD.rst
  28. 7 0
      Help/variable/CMAKE_LANG_STANDARD_DEFAULT.rst
  29. 19 0
      Help/variable/CMAKE_LANG_STANDARD_REQUIRED.rst
  30. 2 5
      Help/variable/CMAKE_OBJCXX_EXTENSIONS.rst
  31. 2 5
      Help/variable/CMAKE_OBJCXX_STANDARD.rst
  32. 2 5
      Help/variable/CMAKE_OBJCXX_STANDARD_REQUIRED.rst
  33. 2 5
      Help/variable/CMAKE_OBJC_EXTENSIONS.rst
  34. 2 5
      Help/variable/CMAKE_OBJC_STANDARD.rst
  35. 2 5
      Help/variable/CMAKE_OBJC_STANDARD_REQUIRED.rst
  36. 2 0
      Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst
  37. 1 0
      Modules/CMakeCCompiler.cmake.in
  38. 22 10
      Modules/CMakeCCompilerId.c.in
  39. 1 0
      Modules/CMakeCUDACompiler.cmake.in
  40. 13 2
      Modules/CMakeCUDACompilerId.cu.in
  41. 1 0
      Modules/CMakeCXXCompiler.cmake.in
  42. 14 2
      Modules/CMakeCXXCompilerId.cpp.in
  43. 6 1
      Modules/CMakeDetermineCompilerId.cmake
  44. 1 0
      Modules/CMakeHIPCompiler.cmake.in
  45. 11 2
      Modules/CMakeHIPCompilerId.hip.in
  46. 1 0
      Modules/CMakeOBJCCompiler.cmake.in
  47. 19 10
      Modules/CMakeOBJCCompilerId.m.in
  48. 1 0
      Modules/CMakeOBJCXXCompiler.cmake.in
  49. 11 2
      Modules/CMakeOBJCXXCompilerId.mm.in
  50. 12 6
      Modules/Compiler/CMakeCommonCompilerMacros.cmake
  51. 1 0
      Modules/Compiler/IAR-C.cmake
  52. 1 1
      Modules/Compiler/IAR-CXX.cmake
  53. 4 1
      Source/cmPolicies.h
  54. 72 15
      Source/cmStandardLevelResolver.cxx
  55. 1 1
      Tests/RunCMake/CMakeLists.txt
  56. 8 0
      Tests/RunCMake/CompileFeatures/CMP0128WarnMatch-stderr.txt
  57. 7 0
      Tests/RunCMake/CompileFeatures/CMP0128WarnMatch.cmake
  58. 8 0
      Tests/RunCMake/CompileFeatures/CMP0128WarnUnset-stderr.txt
  59. 6 0
      Tests/RunCMake/CompileFeatures/CMP0128WarnUnset.cmake
  60. 8 0
      Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag-build-check.cmake
  61. 9 0
      Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag.cmake
  62. 119 16
      Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake
  63. 12 0
      Tests/RunCMake/CompileFeatures/UnsetStandard-build-check.cmake
  64. 8 0
      Tests/RunCMake/CompileFeatures/UnsetStandard.cmake
  65. 38 0
      Tests/RunCMake/CompileFeatures/compiler_introspection.cmake
  66. 1 1
      Tests/RunCMake/CompileFeatures/empty.c
  67. 0 43
      Tests/RunCMake/CompileFeatures/generate_feature_list.cmake

+ 5 - 6
Help/manual/cmake-compile-features.7.rst

@@ -118,14 +118,13 @@ as well as any dependents (that may include headers from ``mylib``).
 Availability of Compiler Extensions
 -----------------------------------
 
-Because the :prop_tgt:`CXX_EXTENSIONS` target property is ``ON`` by default,
-CMake uses extended variants of language dialects by default, such as
-``-std=gnu++11`` instead of ``-std=c++11``.  That target property may be
-set to ``OFF`` to use the non-extended variant of the dialect flag.  Note
-that because most compilers enable extensions by default, this could
-expose cross-platform bugs in user code or in the headers of third-party
+The :prop_tgt:`<LANG>_EXTENSIONS` target property defaults to the compiler's
+efault. Note that because most compilers enable extensions by default, this
+may expose cross-platform bugs in user code or in the headers of third-party
 dependencies.
 
+:prop_tgt:`<LANG>_EXTENSIONS` used to default to ``ON``. See :policy:`CMP0128`.
+
 Optional Compile Features
 =========================
 

+ 1 - 0
Help/manual/cmake-policies.7.rst

@@ -57,6 +57,7 @@ Policies Introduced by CMake 3.22
 .. toctree::
    :maxdepth: 1
 
+   CMP0128: Selection of language standard and extension flags improved. </policy/CMP0128>
    CMP0127: cmake_dependent_option() supports full Condition Syntax. </policy/CMP0127>
 
 Policies Introduced by CMake 3.21

+ 6 - 0
Help/manual/cmake-properties.7.rst

@@ -215,6 +215,9 @@ Properties on Targets
    /prop_tgt/GNUtoMS
    /prop_tgt/HAS_CXX
    /prop_tgt/HIP_ARCHITECTURES
+   /prop_tgt/HIP_EXTENSIONS
+   /prop_tgt/HIP_STANDARD
+   /prop_tgt/HIP_STANDARD_REQUIRED
    /prop_tgt/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
    /prop_tgt/IMPORTED
    /prop_tgt/IMPORTED_COMMON_LANGUAGE_RUNTIME
@@ -274,8 +277,11 @@ Properties on Targets
    /prop_tgt/LANG_COMPILER_LAUNCHER
    /prop_tgt/LANG_CPPCHECK
    /prop_tgt/LANG_CPPLINT
+   /prop_tgt/LANG_EXTENSIONS
    /prop_tgt/LANG_INCLUDE_WHAT_YOU_USE
    /prop_tgt/LANG_LINKER_LAUNCHER
+   /prop_tgt/LANG_STANDARD
+   /prop_tgt/LANG_STANDARD_REQUIRED
    /prop_tgt/LANG_VISIBILITY_PRESET
    /prop_tgt/LIBRARY_OUTPUT_DIRECTORY
    /prop_tgt/LIBRARY_OUTPUT_DIRECTORY_CONFIG

+ 8 - 0
Help/manual/cmake-variables.7.rst

@@ -528,6 +528,9 @@ Variables for Languages
    /variable/CMAKE_Fortran_MODDIR_FLAG
    /variable/CMAKE_Fortran_MODOUT_FLAG
    /variable/CMAKE_HIP_ARCHITECTURES
+   /variable/CMAKE_HIP_EXTENSIONS
+   /variable/CMAKE_HIP_STANDARD
+   /variable/CMAKE_HIP_STANDARD_REQUIRED
    /variable/CMAKE_ISPC_HEADER_DIRECTORY
    /variable/CMAKE_ISPC_HEADER_SUFFIX
    /variable/CMAKE_ISPC_INSTRUCTION_SETS
@@ -549,6 +552,8 @@ Variables for Languages
    /variable/CMAKE_LANG_CREATE_SHARED_LIBRARY
    /variable/CMAKE_LANG_CREATE_SHARED_MODULE
    /variable/CMAKE_LANG_CREATE_STATIC_LIBRARY
+   /variable/CMAKE_LANG_EXTENSIONS
+   /variable/CMAKE_LANG_EXTENSIONS_DEFAULT
    /variable/CMAKE_LANG_FLAGS
    /variable/CMAKE_LANG_FLAGS_CONFIG
    /variable/CMAKE_LANG_FLAGS_CONFIG_INIT
@@ -577,8 +582,11 @@ Variables for Languages
    /variable/CMAKE_LANG_SIMULATE_VERSION
    /variable/CMAKE_LANG_SIZEOF_DATA_PTR
    /variable/CMAKE_LANG_SOURCE_FILE_EXTENSIONS
+   /variable/CMAKE_LANG_STANDARD
+   /variable/CMAKE_LANG_STANDARD_DEFAULT
    /variable/CMAKE_LANG_STANDARD_INCLUDE_DIRECTORIES
    /variable/CMAKE_LANG_STANDARD_LIBRARIES
+   /variable/CMAKE_LANG_STANDARD_REQUIRED
    /variable/CMAKE_OBJC_EXTENSIONS
    /variable/CMAKE_OBJC_STANDARD
    /variable/CMAKE_OBJC_STANDARD_REQUIRED

+ 78 - 0
Help/policy/CMP0128.rst

@@ -0,0 +1,78 @@
+CMP0128
+-------
+
+.. versionadded:: 3.22
+
+When this policy is set to ``NEW``:
+
+* :prop_tgt:`<LANG>_EXTENSIONS` is initialized to
+  :variable:`CMAKE_<LANG>_EXTENSIONS_DEFAULT`.
+
+* Extensions are correctly disabled/enabled if :prop_tgt:`<LANG>_STANDARD` is
+  unset.
+
+* Standard mode-affecting flags aren't added unless necessary to achieve the
+  specified mode.
+
+The ``OLD`` behavior:
+
+* Initializes :prop_tgt:`<LANG>_EXTENSIONS` to ``ON``.
+
+* Always adds a flag if :prop_tgt:`<LANG>_STANDARD` is set and
+  :prop_tgt:`<LANG>_STANDARD_REQUIRED` is ``OFF``.
+
+* If :prop_tgt:`<LANG>_STANDARD` is unset:
+
+  * Doesn't disable extensions even if :prop_tgt:`<LANG>_EXTENSIONS` is
+    ``OFF``.
+
+  * Fails to enable extensions if :prop_tgt:`<LANG>_EXTENSIONS` is ``ON``
+    except for the ``IAR`` compiler.
+
+Code may need to be updated for the ``NEW`` behavior in the following cases:
+
+* If :prop_tgt:`<LANG>_EXTENSIONS` matches
+  :variable:`CMAKE_<LANG>_EXTENSIONS_DEFAULT` or is unset and the compiler's
+  default satisfies :prop_tgt:`<LANG>_STANDARD` but the compiled code requires
+  the exact standard specified.
+  Such code should set :prop_tgt:`<LANG>_STANDARD_REQUIRED` to ``ON``.
+
+  For example:
+
+  .. code-block:: cmake
+
+    cmake_minimum_required(VERSION |release|)
+    project(example C)
+
+    add_executable(exe main.c)
+    set_property(TARGET exe PROPERTY C_STANDARD 99)
+
+  If the compiler defaults to C11 then the standard specification for C99 is
+  satisfied and CMake will pass no flags. ``main.c`` will no longer compile if
+  it is incompatible with C11.
+
+* If a standard mode flag previously overridden by CMake's and not used during
+  compiler detection now takes effect due to CMake no longer adding one as the
+  default detected is appropriate.
+
+  Such code should be converted to either:
+
+  * Use :prop_tgt:`<LANG>_STANDARD` and :prop_tgt:`<LANG>_EXTENSIONS` instead
+    of manually adding flags.
+
+  * Or ensure the manually-specified flags are used during compiler detection.
+
+If compiler flags affecting the standard mode are used during compiler
+detection (for example in :manual:`a toolchain file <cmake-toolchains(7)>`
+using :variable:`CMAKE_<LANG>_FLAGS_INIT`) then they will affect the detected
+default :variable:`standard <CMAKE_<LANG>_STANDARD_DEFAULT>` and
+:variable:`extensions <CMAKE_<LANG>_EXTENSIONS_DEFAULT>`.
+
+Unlike many policies, CMake version |release| does *not* warn when the policy
+is not set and simply uses the ``OLD`` behavior. Use the
+:command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
+See documentation of the
+:variable:`CMAKE_POLICY_WARNING_CMP0128 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
+variable to control the warning.
+
+.. include:: DEPRECATED.txt

+ 19 - 0
Help/prop_tgt/HIP_EXTENSIONS.rst

@@ -0,0 +1,19 @@
+HIP_EXTENSIONS
+--------------
+
+.. versionadded:: 3.21
+
+Boolean specifying whether compiler specific extensions are requested.
+
+This property specifies whether compiler specific extensions should be
+used.  For some compilers, this results in adding a flag such
+as ``-std=gnu++11`` instead of ``-std=c++11`` to the compile line.  This
+property is ``ON`` by default. The basic HIP/C++ standard level is
+controlled by the :prop_tgt:`HIP_STANDARD` target property.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.
+
+This property is initialized by the value of
+the :variable:`CMAKE_HIP_EXTENSIONS` variable if it is set when a target
+is created.

+ 48 - 0
Help/prop_tgt/HIP_STANDARD.rst

@@ -0,0 +1,48 @@
+HIP_STANDARD
+------------
+
+.. versionadded:: 3.21
+
+The HIP/C++ standard requested to build this target.
+
+Supported values are:
+
+``98``
+  HIP C++98
+
+``11``
+  HIP C++11
+
+``14``
+  HIP C++14
+
+``17``
+  HIP C++17
+
+``20``
+  HIP C++20
+
+``23``
+  HIP C++23
+
+If the value requested does not result in a compile flag being added for
+the compiler in use, a previous standard flag will be added instead.  This
+means that using:
+
+.. code-block:: cmake
+
+  set_property(TARGET tgt PROPERTY HIP_STANDARD 11)
+
+with a compiler which does not support ``-std=gnu++11`` or an equivalent
+flag will not result in an error or warning, but will instead add the
+``-std=gnu++98`` flag if supported.  This "decay" behavior may be controlled
+with the :prop_tgt:`HIP_STANDARD_REQUIRED` target property.
+Additionally, the :prop_tgt:`HIP_EXTENSIONS` target property may be used to
+control whether compiler-specific extensions are enabled on a per-target basis.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.
+
+This property is initialized by the value of
+the :variable:`CMAKE_HIP_STANDARD` variable if it is set when a target
+is created.

+ 19 - 0
Help/prop_tgt/HIP_STANDARD_REQUIRED.rst

@@ -0,0 +1,19 @@
+HIP_STANDARD_REQUIRED
+---------------------
+
+.. versionadded:: 3.21
+
+Boolean describing whether the value of :prop_tgt:`HIP_STANDARD` is a requirement.
+
+If this property is set to ``ON``, then the value of the
+:prop_tgt:`HIP_STANDARD` target property is treated as a requirement.  If this
+property is ``OFF`` or unset, the :prop_tgt:`HIP_STANDARD` target property is
+treated as optional and may "decay" to a previous standard if the requested is
+not available.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.
+
+This property is initialized by the value of
+the :variable:`CMAKE_HIP_STANDARD_REQUIRED` variable if it is set when a
+target is created.

+ 23 - 0
Help/prop_tgt/LANG_EXTENSIONS.rst

@@ -0,0 +1,23 @@
+<LANG>_EXTENSIONS
+-----------------
+
+The variations are:
+
+* :prop_tgt:`C_EXTENSIONS`
+* :prop_tgt:`CXX_EXTENSIONS`
+* :prop_tgt:`CUDA_EXTENSIONS`
+* :prop_tgt:`HIP_EXTENSIONS`
+* :prop_tgt:`OBJC_EXTENSIONS`
+* :prop_tgt:`OBJCXX_EXTENSIONS`
+
+These properties specify whether compiler-specific extensions are requested.
+
+These properties are initialized by the value of the
+:variable:`CMAKE_<LANG>_EXTENSIONS` variable if it is set when a target is
+created.
+
+For supported CMake versions see the respective pages.
+To control language standard versions see :prop_tgt:`<LANG>_STANDARD`.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.

+ 26 - 0
Help/prop_tgt/LANG_STANDARD.rst

@@ -0,0 +1,26 @@
+<LANG>_STANDARD
+---------------
+
+The variations are:
+
+* :prop_tgt:`C_STANDARD`
+* :prop_tgt:`CXX_STANDARD`
+* :prop_tgt:`CUDA_STANDARD`
+* :prop_tgt:`HIP_STANDARD`
+* :prop_tgt:`OBJC_STANDARD`
+* :prop_tgt:`OBJCXX_STANDARD`
+
+These properties specify language standard versions which are requested. When a
+newer standard is specified than is supported by the compiler, then it will
+fallback to the latest supported standard. This "decay" behavior may be
+controlled with the :prop_tgt:`<LANG>_STANDARD_REQUIRED` target property.
+
+These properties are initialized by the value of the
+:variable:`CMAKE_<LANG>_STANDARD` variable if it is set when a target is
+created.
+
+For supported values and CMake versions see the respective pages.
+To control compiler-specific extensions see :prop_tgt:`<LANG>_EXTENSIONS`.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.

+ 26 - 0
Help/prop_tgt/LANG_STANDARD_REQUIRED.rst

@@ -0,0 +1,26 @@
+<LANG>_STANDARD_REQUIRED
+------------------------
+
+The variations are:
+
+* :prop_tgt:`C_STANDARD_REQUIRED`
+* :prop_tgt:`CXX_STANDARD_REQUIRED`
+* :prop_tgt:`CUDA_STANDARD_REQUIRED`
+* :prop_tgt:`HIP_STANDARD_REQUIRED`
+* :prop_tgt:`OBJC_STANDARD_REQUIRED`
+* :prop_tgt:`OBJCXX_STANDARD_REQUIRED`
+
+These properties specify whether the value of :prop_tgt:`<LANG>_STANDARD` is a
+requirement. When ``OFF`` or unset, the :prop_tgt:`<LANG>_STANDARD` target
+property is treated as optional and may "decay" to a previous standard if the
+requested is not available.
+
+These properties are initialized by the value of the
+:variable:`CMAKE_<LANG>_STANDARD_REQUIRED` variable if it is set when a target
+is created.
+
+For supported CMake versions see the respective pages.
+To control language standard versions see :prop_tgt:`<LANG>_STANDARD`.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.

+ 10 - 0
Help/release/dev/compile-features-standard-logic-rework.rst

@@ -0,0 +1,10 @@
+compile-features-standard-logic-rework
+--------------------------------------
+
+* The :manual:`Compile Features <cmake-compile-features(7)>` functionality now
+  correctly disables or enables compiler extensions when no standard level is
+  specified and avoids unnecessarily adding language standard flags if the
+  requested settings match the compiler's defaults. See :policy:`CMP0128`.
+
+* :prop_tgt:`<LANG>_EXTENSIONS` is initialized to
+  :variable:`CMAKE_<LANG>_EXTENSIONS_DEFAULT`. See :policy:`CMP0128`.

+ 2 - 5
Help/variable/CMAKE_CUDA_EXTENSIONS.rst

@@ -3,11 +3,8 @@ CMAKE_CUDA_EXTENSIONS
 
 .. versionadded:: 3.8
 
-Default value for :prop_tgt:`CUDA_EXTENSIONS` property of targets.
-
-This variable is used to initialize the :prop_tgt:`CUDA_EXTENSIONS`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`CUDA_EXTENSIONS` target property if set when a
+target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_CUDA_STANDARD.rst

@@ -3,11 +3,8 @@ CMAKE_CUDA_STANDARD
 
 .. versionadded:: 3.8
 
-Default value for :prop_tgt:`CUDA_STANDARD` property of targets.
-
-This variable is used to initialize the :prop_tgt:`CUDA_STANDARD`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`CUDA_STANDARD` target property if set when a
+target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_CUDA_STANDARD_REQUIRED.rst

@@ -3,11 +3,8 @@ CMAKE_CUDA_STANDARD_REQUIRED
 
 .. versionadded:: 3.8
 
-Default value for :prop_tgt:`CUDA_STANDARD_REQUIRED` property of targets.
-
-This variable is used to initialize the :prop_tgt:`CUDA_STANDARD_REQUIRED`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`CUDA_STANDARD_REQUIRED` target property if set
+when a target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_CXX_EXTENSIONS.rst

@@ -3,11 +3,8 @@ CMAKE_CXX_EXTENSIONS
 
 .. versionadded:: 3.1
 
-Default value for :prop_tgt:`CXX_EXTENSIONS` property of targets.
-
-This variable is used to initialize the :prop_tgt:`CXX_EXTENSIONS`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`CXX_EXTENSIONS` target property if set when a
+target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_CXX_STANDARD.rst

@@ -3,11 +3,8 @@ CMAKE_CXX_STANDARD
 
 .. versionadded:: 3.1
 
-Default value for :prop_tgt:`CXX_STANDARD` property of targets.
-
-This variable is used to initialize the :prop_tgt:`CXX_STANDARD`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`CXX_STANDARD` target property if set when a target
+is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_CXX_STANDARD_REQUIRED.rst

@@ -3,11 +3,8 @@ CMAKE_CXX_STANDARD_REQUIRED
 
 .. versionadded:: 3.1
 
-Default value for :prop_tgt:`CXX_STANDARD_REQUIRED` property of targets.
-
-This variable is used to initialize the :prop_tgt:`CXX_STANDARD_REQUIRED`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`CXX_STANDARD_REQUIRED` target property if set when
+a target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_C_EXTENSIONS.rst

@@ -3,11 +3,8 @@ CMAKE_C_EXTENSIONS
 
 .. versionadded:: 3.1
 
-Default value for :prop_tgt:`C_EXTENSIONS` property of targets.
-
-This variable is used to initialize the :prop_tgt:`C_EXTENSIONS`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`C_EXTENSIONS` target property if set when a target
+is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_C_STANDARD.rst

@@ -3,11 +3,8 @@ CMAKE_C_STANDARD
 
 .. versionadded:: 3.1
 
-Default value for :prop_tgt:`C_STANDARD` property of targets.
-
-This variable is used to initialize the :prop_tgt:`C_STANDARD`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`C_STANDARD` target property if set when a target
+is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_C_STANDARD_REQUIRED.rst

@@ -3,11 +3,8 @@ CMAKE_C_STANDARD_REQUIRED
 
 .. versionadded:: 3.1
 
-Default value for :prop_tgt:`C_STANDARD_REQUIRED` property of targets.
-
-This variable is used to initialize the :prop_tgt:`C_STANDARD_REQUIRED`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`C_STANDARD_REQUIRED` target property if set when
+a target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 10 - 0
Help/variable/CMAKE_HIP_EXTENSIONS.rst

@@ -0,0 +1,10 @@
+CMAKE_HIP_EXTENSIONS
+--------------------
+
+.. versionadded:: 3.21
+
+Default value for :prop_tgt:`HIP_EXTENSIONS` target property if set when a
+target is created.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.

+ 10 - 0
Help/variable/CMAKE_HIP_STANDARD.rst

@@ -0,0 +1,10 @@
+CMAKE_HIP_STANDARD
+------------------
+
+.. versionadded:: 3.21
+
+Default value for :prop_tgt:`HIP_STANDARD` target property if set when a target
+is created.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.

+ 10 - 0
Help/variable/CMAKE_HIP_STANDARD_REQUIRED.rst

@@ -0,0 +1,10 @@
+CMAKE_HIP_STANDARD_REQUIRED
+---------------------------
+
+.. versionadded:: 3.21
+
+Default value for :prop_tgt:`HIP_STANDARD_REQUIRED` target property if set when
+a target is created.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.

+ 19 - 0
Help/variable/CMAKE_LANG_EXTENSIONS.rst

@@ -0,0 +1,19 @@
+CMAKE_<LANG>_EXTENSIONS
+-----------------------
+
+The variations are:
+
+* :variable:`CMAKE_C_EXTENSIONS`
+* :variable:`CMAKE_CXX_EXTENSIONS`
+* :variable:`CMAKE_CUDA_EXTENSIONS`
+* :variable:`CMAKE_HIP_EXTENSIONS`
+* :variable:`CMAKE_OBJC_EXTENSIONS`
+* :variable:`CMAKE_OBJCXX_EXTENSIONS`
+
+Default values for :prop_tgt:`<LANG>_EXTENSIONS` target properties if set when
+a target is created.
+
+For supported CMake versions see the respective pages.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.

+ 7 - 0
Help/variable/CMAKE_LANG_EXTENSIONS_DEFAULT.rst

@@ -0,0 +1,7 @@
+CMAKE_<LANG>_EXTENSIONS_DEFAULT
+-------------------------------
+
+.. versionadded:: 3.22
+
+Default value used when the :prop_tgt:`<LANG>_EXTENSIONS` target property is
+not set. Initialized during compiler detection to the compiler's default.

+ 19 - 0
Help/variable/CMAKE_LANG_STANDARD.rst

@@ -0,0 +1,19 @@
+CMAKE_<LANG>_STANDARD
+---------------------
+
+The variations are:
+
+* :variable:`CMAKE_C_STANDARD`
+* :variable:`CMAKE_CXX_STANDARD`
+* :variable:`CMAKE_CUDA_STANDARD`
+* :variable:`CMAKE_HIP_STANDARD`
+* :variable:`CMAKE_OBJC_STANDARD`
+* :variable:`CMAKE_OBJCXX_STANDARD`
+
+Default values for :prop_tgt:`<LANG>_STANDARD` target properties if set when a
+target is created.
+
+For supported CMake versions see the respective pages.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.

+ 7 - 0
Help/variable/CMAKE_LANG_STANDARD_DEFAULT.rst

@@ -0,0 +1,7 @@
+CMAKE_<LANG>_STANDARD_DEFAULT
+-----------------------------
+
+.. versionadded:: 3.9
+
+The compiler's default standard for the language ``<LANG>``. Empty if the
+compiler has no conception of standard levels.

+ 19 - 0
Help/variable/CMAKE_LANG_STANDARD_REQUIRED.rst

@@ -0,0 +1,19 @@
+CMAKE_<LANG>_STANDARD_REQUIRED
+------------------------------
+
+The variations are:
+
+* :variable:`CMAKE_C_STANDARD_REQUIRED`
+* :variable:`CMAKE_CXX_STANDARD_REQUIRED`
+* :variable:`CMAKE_CUDA_STANDARD_REQUIRED`
+* :variable:`CMAKE_HIP_STANDARD_REQUIRED`
+* :variable:`CMAKE_OBJC_STANDARD_REQUIRED`
+* :variable:`CMAKE_OBJCXX_STANDARD_REQUIRED`
+
+Default values for :prop_tgt:`<LANG>_STANDARD_REQUIRED` target properties if
+set when a target is created.
+
+For supported CMake versions see the respective pages.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_OBJCXX_EXTENSIONS.rst

@@ -3,11 +3,8 @@ CMAKE_OBJCXX_EXTENSIONS
 
 .. versionadded:: 3.16
 
-Default value for :prop_tgt:`OBJCXX_EXTENSIONS` property of targets.
-
-This variable is used to initialize the :prop_tgt:`OBJCXX_EXTENSIONS`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`OBJCXX_EXTENSIONS` target property if set when a
+target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_OBJCXX_STANDARD.rst

@@ -3,11 +3,8 @@ CMAKE_OBJCXX_STANDARD
 
 .. versionadded:: 3.16
 
-Default value for :prop_tgt:`OBJCXX_STANDARD` property of targets.
-
-This variable is used to initialize the :prop_tgt:`OBJCXX_STANDARD`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`OBJCXX_STANDARD` target property if set when a
+target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_OBJCXX_STANDARD_REQUIRED.rst

@@ -3,11 +3,8 @@ CMAKE_OBJCXX_STANDARD_REQUIRED
 
 .. versionadded:: 3.16
 
-Default value for :prop_tgt:`OBJCXX_STANDARD_REQUIRED` property of targets.
-
-This variable is used to initialize the :prop_tgt:`OBJCXX_STANDARD_REQUIRED`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`OBJCXX_STANDARD_REQUIRED` target property if set
+when a target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_OBJC_EXTENSIONS.rst

@@ -3,11 +3,8 @@ CMAKE_OBJC_EXTENSIONS
 
 .. versionadded:: 3.16
 
-Default value for :prop_tgt:`OBJC_EXTENSIONS` property of targets.
-
-This variable is used to initialize the :prop_tgt:`OBJC_EXTENSIONS`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`OBJC_EXTENSIONS` target property if set when a
+target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_OBJC_STANDARD.rst

@@ -3,11 +3,8 @@ CMAKE_OBJC_STANDARD
 
 .. versionadded:: 3.16
 
-Default value for :prop_tgt:`OBJC_STANDARD` property of targets.
-
-This variable is used to initialize the :prop_tgt:`OBJC_STANDARD`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`OBJC_STANDARD` target property if set when a
+target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 5
Help/variable/CMAKE_OBJC_STANDARD_REQUIRED.rst

@@ -3,11 +3,8 @@ CMAKE_OBJC_STANDARD_REQUIRED
 
 .. versionadded:: 3.16
 
-Default value for :prop_tgt:`OBJC_STANDARD_REQUIRED` property of targets.
-
-This variable is used to initialize the :prop_tgt:`OBJC_STANDARD_REQUIRED`
-property on all targets.  See that target property for additional
-information.
+Default value for :prop_tgt:`OBJC_STANDARD_REQUIRED` target property if set
+when a target is created.
 
 See the :manual:`cmake-compile-features(7)` manual for information on
 compile features and a list of supported compilers.

+ 2 - 0
Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst

@@ -32,6 +32,8 @@ only for the policies that do not warn by default:
   policy :policy:`CMP0116`.
 * ``CMAKE_POLICY_WARNING_CMP0126`` controls the warning for
   policy :policy:`CMP0126`.
+* ``CMAKE_POLICY_WARNING_CMP0128`` controls the warning for
+  policy :policy:`CMP0128`.
 
 This variable should not be set by a project in CMake code.  Project
 developers running CMake may set this variable in their cache to

+ 1 - 0
Modules/CMakeCCompiler.cmake.in

@@ -5,6 +5,7 @@ set(CMAKE_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@")
 set(CMAKE_C_COMPILER_VERSION_INTERNAL "@CMAKE_C_COMPILER_VERSION_INTERNAL@")
 set(CMAKE_C_COMPILER_WRAPPER "@CMAKE_C_COMPILER_WRAPPER@")
 set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "@CMAKE_C_STANDARD_COMPUTED_DEFAULT@")
+set(CMAKE_C_EXTENSIONS_COMPUTED_DEFAULT "@CMAKE_C_EXTENSIONS_COMPUTED_DEFAULT@")
 set(CMAKE_C_COMPILE_FEATURES "@CMAKE_C_COMPILE_FEATURES@")
 set(CMAKE_C90_COMPILE_FEATURES "@CMAKE_C90_COMPILE_FEATURES@")
 set(CMAKE_C99_COMPILE_FEATURES "@CMAKE_C99_COMPILE_FEATURES@")

+ 22 - 10
Modules/CMakeCCompilerId.c.in

@@ -41,23 +41,34 @@ char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
 
 #if !defined(__STDC__) && !defined(__clang__)
 # if defined(_MSC_VER) || defined(__ibmxl__) || defined(__IBMC__)
-#  define C_DIALECT "90"
+#  define C_VERSION "90"
 # else
-#  define C_DIALECT
+#  define C_VERSION
 # endif
 #elif __STDC_VERSION__ > 201710L
-# define C_DIALECT "23"
+# define C_VERSION "23"
 #elif __STDC_VERSION__ >= 201710L
-# define C_DIALECT "17"
+# define C_VERSION "17"
 #elif __STDC_VERSION__ >= 201000L
-# define C_DIALECT "11"
+# define C_VERSION "11"
 #elif __STDC_VERSION__ >= 199901L
-# define C_DIALECT "99"
+# define C_VERSION "99"
 #else
-# define C_DIALECT "90"
+# define C_VERSION "90"
 #endif
-const char* info_language_dialect_default =
-  "INFO" ":" "dialect_default[" C_DIALECT "]";
+const char* info_language_standard_default =
+  "INFO" ":" "standard_default[" C_VERSION "]";
+
+const char* info_language_extensions_default = "INFO" ":" "extensions_default["
+// !defined(_MSC_VER) to exclude Clang's MSVC compatibility mode.
+#if (defined(__clang__) || defined(__GNUC__) ||                               \
+     defined(__TI_COMPILER_VERSION__)) &&                                     \
+  !defined(__STRICT_ANSI__) && !defined(_MSC_VER)
+  "ON"
+#else
+  "OFF"
+#endif
+"]";
 
 /*--------------------------------------------------------------------------*/
 
@@ -89,7 +100,8 @@ int main(int argc, char* argv[])
 #if defined(__CRAYXT_COMPUTE_LINUX_TARGET)
   require += info_cray[argc];
 #endif
-  require += info_language_dialect_default[argc];
+  require += info_language_standard_default[argc];
+  require += info_language_extensions_default[argc];
   (void)argv;
   return require;
 }

+ 1 - 0
Modules/CMakeCUDACompiler.cmake.in

@@ -6,6 +6,7 @@ set(CMAKE_CUDA_COMPILER_VERSION "@CMAKE_CUDA_COMPILER_VERSION@")
 set(CMAKE_CUDA_DEVICE_LINKER "@CMAKE_CUDA_DEVICE_LINKER@")
 set(CMAKE_CUDA_FATBINARY "@CMAKE_CUDA_FATBINARY@")
 set(CMAKE_CUDA_STANDARD_COMPUTED_DEFAULT "@CMAKE_CUDA_STANDARD_COMPUTED_DEFAULT@")
+set(CMAKE_CUDA_EXTENSIONS_COMPUTED_DEFAULT "@CMAKE_CUDA_EXTENSIONS_COMPUTED_DEFAULT@")
 set(CMAKE_CUDA_COMPILE_FEATURES "@CMAKE_CUDA_COMPILE_FEATURES@")
 set(CMAKE_CUDA03_COMPILE_FEATURES "@CMAKE_CUDA03_COMPILE_FEATURES@")
 set(CMAKE_CUDA11_COMPILE_FEATURES "@CMAKE_CUDA11_COMPILE_FEATURES@")

+ 13 - 2
Modules/CMakeCUDACompilerId.cu.in

@@ -16,7 +16,7 @@ char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
 @CMAKE_CUDA_COMPILER_ID_PLATFORM_CONTENT@
 @CMAKE_CUDA_COMPILER_ID_ERROR_FOR_TEST@
 
-const char* info_language_dialect_default = "INFO" ":" "dialect_default["
+const char* info_language_standard_default = "INFO" ":" "standard_default["
 #if __cplusplus > 202002L
   "23"
 #elif __cplusplus > 201703L
@@ -32,6 +32,16 @@ const char* info_language_dialect_default = "INFO" ":" "dialect_default["
 #endif
 "]";
 
+const char* info_language_extensions_default = "INFO" ":" "extensions_default["
+// !defined(_MSC_VER) to exclude Clang's MSVC compatibility mode.
+#if (defined(__clang__) || defined(__GNUC__)) && !defined(__STRICT_ANSI__) && \
+  !defined(_MSC_VER)
+  "ON"
+#else
+  "OFF"
+#endif
+"]";
+
 /*--------------------------------------------------------------------------*/
 
 int main(int argc, char* argv[])
@@ -48,7 +58,8 @@ int main(int argc, char* argv[])
 #ifdef SIMULATE_VERSION_MAJOR
   require += info_simulate_version[argc];
 #endif
-  require += info_language_dialect_default[argc];
+  require += info_language_standard_default[argc];
+  require += info_language_extensions_default[argc];
   (void)argv;
   return require;
 }

+ 1 - 0
Modules/CMakeCXXCompiler.cmake.in

@@ -5,6 +5,7 @@ set(CMAKE_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@")
 set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "@CMAKE_CXX_COMPILER_VERSION_INTERNAL@")
 set(CMAKE_CXX_COMPILER_WRAPPER "@CMAKE_CXX_COMPILER_WRAPPER@")
 set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "@CMAKE_CXX_STANDARD_COMPUTED_DEFAULT@")
+set(CMAKE_CXX_EXTENSIONS_COMPUTED_DEFAULT "@CMAKE_CXX_EXTENSIONS_COMPUTED_DEFAULT@")
 set(CMAKE_CXX_COMPILE_FEATURES "@CMAKE_CXX_COMPILE_FEATURES@")
 set(CMAKE_CXX98_COMPILE_FEATURES "@CMAKE_CXX98_COMPILE_FEATURES@")
 set(CMAKE_CXX11_COMPILE_FEATURES "@CMAKE_CXX11_COMPILE_FEATURES@")

+ 14 - 2
Modules/CMakeCXXCompilerId.cpp.in

@@ -49,7 +49,7 @@ char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
 #  define CXX_STD __cplusplus
 #endif
 
-const char* info_language_dialect_default = "INFO" ":" "dialect_default["
+const char* info_language_standard_default = "INFO" ":" "standard_default["
 #if CXX_STD > 202002L
   "23"
 #elif CXX_STD > 201703L
@@ -65,6 +65,17 @@ const char* info_language_dialect_default = "INFO" ":" "dialect_default["
 #endif
 "]";
 
+const char* info_language_extensions_default = "INFO" ":" "extensions_default["
+// !defined(_MSC_VER) to exclude Clang's MSVC compatibility mode.
+#if (defined(__clang__) || defined(__GNUC__) ||                               \
+     defined(__TI_COMPILER_VERSION__)) &&                                     \
+  !defined(__STRICT_ANSI__) && !defined(_MSC_VER)
+  "ON"
+#else
+  "OFF"
+#endif
+"]";
+
 /*--------------------------------------------------------------------------*/
 
 int main(int argc, char* argv[])
@@ -87,7 +98,8 @@ int main(int argc, char* argv[])
 #if defined(__CRAYXT_COMPUTE_LINUX_TARGET)
   require += info_cray[argc];
 #endif
-  require += info_language_dialect_default[argc];
+  require += info_language_standard_default[argc];
+  require += info_language_extensions_default[argc];
   (void)argv;
   return require;
 }

+ 6 - 1
Modules/CMakeDetermineCompilerId.cmake

@@ -267,6 +267,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
   set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
   set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
   set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT}" PARENT_SCOPE)
+  set(CMAKE_${lang}_EXTENSIONS_COMPUTED_DEFAULT "${CMAKE_${lang}_EXTENSIONS_COMPUTED_DEFAULT}" PARENT_SCOPE)
   set(CMAKE_${lang}_COMPILER_PRODUCED_OUTPUT "${COMPILER_${lang}_PRODUCED_OUTPUT}" PARENT_SCOPE)
   set(CMAKE_${lang}_COMPILER_PRODUCED_FILES "${COMPILER_${lang}_PRODUCED_FILES}" PARENT_SCOPE)
 endfunction()
@@ -881,9 +882,12 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
       if("${info}" MATCHES "INFO:qnxnto\\[\\]")
         set(COMPILER_QNXNTO 1)
       endif()
-      if("${info}" MATCHES "INFO:dialect_default\\[([^]\"]*)\\]")
+      if("${info}" MATCHES "INFO:standard_default\\[([^]\"]*)\\]")
         set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_MATCH_1}")
       endif()
+      if("${info}" MATCHES "INFO:extensions_default\\[([^]\"]*)\\]")
+        set(CMAKE_${lang}_EXTENSIONS_COMPUTED_DEFAULT "${CMAKE_MATCH_1}")
+      endif()
     endforeach()
 
     # Construct compiler version from components if needed.
@@ -993,6 +997,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
   set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
   set(COMPILER_QNXNTO "${COMPILER_QNXNTO}" PARENT_SCOPE)
   set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT}" PARENT_SCOPE)
+  set(CMAKE_${lang}_EXTENSIONS_COMPUTED_DEFAULT "${CMAKE_${lang}_EXTENSIONS_COMPUTED_DEFAULT}" PARENT_SCOPE)
 endfunction()
 
 #-----------------------------------------------------------------------------

+ 1 - 0
Modules/CMakeHIPCompiler.cmake.in

@@ -2,6 +2,7 @@ set(CMAKE_HIP_COMPILER "@CMAKE_HIP_COMPILER@")
 set(CMAKE_HIP_COMPILER_ID "@CMAKE_HIP_COMPILER_ID@")
 set(CMAKE_HIP_COMPILER_VERSION "@CMAKE_HIP_COMPILER_VERSION@")
 set(CMAKE_HIP_STANDARD_COMPUTED_DEFAULT "@CMAKE_HIP_STANDARD_COMPUTED_DEFAULT@")
+set(CMAKE_HIP_EXTENSIONS_COMPUTED_DEFAULT "@CMAKE_HIP_EXTENSIONS_COMPUTED_DEFAULT@")
 set(CMAKE_HIP_COMPILE_FEATURES "@CMAKE_HIP_COMPILE_FEATURES@")
 set(CMAKE_HIP98_COMPILE_FEATURES "@CMAKE_HIP03_COMPILE_FEATURES@")
 set(CMAKE_HIP11_COMPILE_FEATURES "@CMAKE_HIP11_COMPILE_FEATURES@")

+ 11 - 2
Modules/CMakeHIPCompilerId.hip.in

@@ -16,7 +16,7 @@ char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
 @CMAKE_HIP_COMPILER_ID_PLATFORM_CONTENT@
 @CMAKE_HIP_COMPILER_ID_ERROR_FOR_TEST@
 
-const char* info_language_dialect_default = "INFO" ":" "dialect_default["
+const char* info_language_standard_default = "INFO" ":" "standard_default["
 #if __cplusplus > 202002L
   "23"
 #elif __cplusplus > 201703L
@@ -32,6 +32,14 @@ const char* info_language_dialect_default = "INFO" ":" "dialect_default["
 #endif
 "]";
 
+const char* info_language_extensions_default = "INFO" ":" "extensions_default["
+#if (defined(__clang__) || defined(__GNUC__)) && !defined(__STRICT_ANSI__)
+  "ON"
+#else
+  "OFF"
+#endif
+"]";
+
 /*--------------------------------------------------------------------------*/
 
 int main(int argc, char* argv[])
@@ -48,7 +56,8 @@ int main(int argc, char* argv[])
 #ifdef SIMULATE_VERSION_MAJOR
   require += info_simulate_version[argc];
 #endif
-  require += info_language_dialect_default[argc];
+  require += info_language_standard_default[argc];
+  require += info_language_extensions_default[argc];
   (void)argv;
   return require;
 }

+ 1 - 0
Modules/CMakeOBJCCompiler.cmake.in

@@ -5,6 +5,7 @@ set(CMAKE_OBJC_COMPILER_VERSION "@CMAKE_OBJC_COMPILER_VERSION@")
 set(CMAKE_OBJC_COMPILER_VERSION_INTERNAL "@CMAKE_OBJC_COMPILER_VERSION_INTERNAL@")
 set(CMAKE_OBJC_COMPILER_WRAPPER "@CMAKE_OBJC_COMPILER_WRAPPER@")
 set(CMAKE_OBJC_STANDARD_COMPUTED_DEFAULT "@CMAKE_OBJC_STANDARD_COMPUTED_DEFAULT@")
+set(CMAKE_OBJC_EXTENSIONS_COMPUTED_DEFAULT "@CMAKE_OBJC_EXTENSIONS_COMPUTED_DEFAULT@")
 set(CMAKE_OBJC_COMPILE_FEATURES "@CMAKE_OBJC_COMPILE_FEATURES@")
 set(CMAKE_OBJC90_COMPILE_FEATURES "@CMAKE_OBJC90_COMPILE_FEATURES@")
 set(CMAKE_OBJC99_COMPILE_FEATURES "@CMAKE_OBJC99_COMPILE_FEATURES@")

+ 19 - 10
Modules/CMakeOBJCCompilerId.m.in

@@ -23,23 +23,31 @@ char const* qnxnto = "INFO" ":" "qnxnto[]";
 #if !defined(__STDC__)
 # if (defined(_MSC_VER) && !defined(__clang__)) \
   || (defined(__ibmxl__) || defined(__IBMC__))
-#  define C_DIALECT "90"
+#  define C_VERSION "90"
 # else
-#  define C_DIALECT
+#  define C_VERSION
 # endif
 #elif __STDC_VERSION__ > 201710L
-# define C_DIALECT "23"
+# define C_VERSION "23"
 #elif __STDC_VERSION__ >= 201710L
-# define C_DIALECT "17"
+# define C_VERSION "17"
 #elif __STDC_VERSION__ >= 201000L
-# define C_DIALECT "11"
+# define C_VERSION "11"
 #elif __STDC_VERSION__ >= 199901L
-# define C_DIALECT "99"
+# define C_VERSION "99"
 #else
-# define C_DIALECT "90"
+# define C_VERSION "90"
 #endif
-const char* info_language_dialect_default =
-  "INFO" ":" "dialect_default[" C_DIALECT "]";
+const char* info_language_standard_default =
+  "INFO" ":" "standard_default[" C_VERSION "]";
+
+const char* info_language_extensions_default = "INFO" ":" "extensions_default["
+#if (defined(__clang__) || defined(__GNUC__)) && !defined(__STRICT_ANSI__)
+  "ON"
+#else
+  "OFF"
+#endif
+"]";
 
 /*--------------------------------------------------------------------------*/
 
@@ -61,7 +69,8 @@ int main(int argc, char* argv[])
 #ifdef SIMULATE_VERSION_MAJOR
   require += info_simulate_version[argc];
 #endif
-  require += info_language_dialect_default[argc];
+  require += info_language_standard_default[argc];
+  require += info_language_extensions_default[argc];
   (void)argv;
   return require;
 }

+ 1 - 0
Modules/CMakeOBJCXXCompiler.cmake.in

@@ -5,6 +5,7 @@ set(CMAKE_OBJCXX_COMPILER_VERSION "@CMAKE_OBJCXX_COMPILER_VERSION@")
 set(CMAKE_OBJCXX_COMPILER_VERSION_INTERNAL "@CMAKE_OBJCXX_COMPILER_VERSION_INTERNAL@")
 set(CMAKE_OBJCXX_COMPILER_WRAPPER "@CMAKE_OBJCXX_COMPILER_WRAPPER@")
 set(CMAKE_OBJCXX_STANDARD_COMPUTED_DEFAULT "@CMAKE_OBJCXX_STANDARD_COMPUTED_DEFAULT@")
+set(CMAKE_OBJCXX_EXTENSIONS_COMPUTED_DEFAULT "@CMAKE_OBJCXX_EXTENSIONS_COMPUTED_DEFAULT@")
 set(CMAKE_OBJCXX_COMPILE_FEATURES "@CMAKE_OBJCXX_COMPILE_FEATURES@")
 set(CMAKE_OBJCXX98_COMPILE_FEATURES "@CMAKE_OBJCXX98_COMPILE_FEATURES@")
 set(CMAKE_OBJCXX11_COMPILE_FEATURES "@CMAKE_OBJCXX11_COMPILE_FEATURES@")

+ 11 - 2
Modules/CMakeOBJCXXCompilerId.mm.in

@@ -29,7 +29,7 @@ char const* qnxnto = "INFO" ":" "qnxnto[]";
 #define CXX_STD __cplusplus
 #endif
 
-const char* info_language_dialect_default = "INFO" ":" "dialect_default["
+const char* info_language_standard_default = "INFO" ":" "standard_default["
 #if CXX_STD > 202002L
   "23"
 #elfif CXX_STD > 201703L
@@ -45,6 +45,14 @@ const char* info_language_dialect_default = "INFO" ":" "dialect_default["
 #endif
 "]";
 
+const char* info_language_extensions_default = "INFO" ":" "extensions_default["
+#if (defined(__clang__) || defined(__GNUC__)) && !defined(__STRICT_ANSI__)
+  "ON"
+#else
+  "OFF"
+#endif
+"]";
+
 /*--------------------------------------------------------------------------*/
 
 int main(int argc, char* argv[])
@@ -64,7 +72,8 @@ int main(int argc, char* argv[])
 #ifdef SIMULATE_VERSION_MAJOR
   require += info_simulate_version[argc];
 #endif
-  require += info_language_dialect_default[argc];
+  require += info_language_standard_default[argc];
+  require += info_language_extensions_default[argc];
   (void)argv;
   return require;
 }

+ 12 - 6
Modules/Compiler/CMakeCommonCompilerMacros.cmake

@@ -38,20 +38,26 @@ macro(__compiler_check_default_language_standard lang stdver1 std1)
   # support for language standards, then don't bother.
   if (CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL "${stdver1}")
     if (NOT CMAKE_${lang}_COMPILER_FORCED)
-      if (NOT CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT)
-        message(FATAL_ERROR "CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT should be set for ${CMAKE_${lang}_COMPILER_ID} (${CMAKE_${lang}_COMPILER}) version ${CMAKE_${lang}_COMPILER_VERSION}")
+      if (NOT CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT OR NOT DEFINED CMAKE_${lang}_EXTENSIONS_COMPUTED_DEFAULT)
+        message(FATAL_ERROR "CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT and CMAKE_${lang}_EXTENSIONS_COMPUTED_DEFAULT should be set for ${CMAKE_${lang}_COMPILER_ID} (${CMAKE_${lang}_COMPILER}) version ${CMAKE_${lang}_COMPILER_VERSION}")
       endif ()
       set(CMAKE_${lang}_STANDARD_DEFAULT ${CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT})
+      set(CMAKE_${lang}_EXTENSIONS_DEFAULT ${CMAKE_${lang}_EXTENSIONS_COMPUTED_DEFAULT})
     else ()
       list(REVERSE __std_ver_pairs)
       foreach (__std_ver_pair IN LISTS __std_ver_pairs)
         string(REGEX MATCH "([^ ]+) (.+)" __std_ver_pair "${__std_ver_pair}")
         set(__stdver ${CMAKE_MATCH_1})
         set(__std ${CMAKE_MATCH_2})
-        if (CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL __stdver AND
-          NOT DEFINED CMAKE_${lang}_STANDARD_DEFAULT)
-          # Compiler id was forced so just guess the default standard level.
-          set(CMAKE_${lang}_STANDARD_DEFAULT ${__std})
+        # Compiler id was forced so just guess the defaults.
+        if (CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL __stdver)
+          if(NOT DEFINED CMAKE_${lang}_EXTENSIONS_DEFAULT)
+            # Currently known compilers default to enabling extensions.
+            set(CMAKE_${lang}_EXTENSIONS_DEFAULT ON)
+          endif()
+          if(NOT DEFINED CMAKE_${lang}_STANDARD_DEFAULT)
+            set(CMAKE_${lang}_STANDARD_DEFAULT ${__std})
+          endif()
         endif ()
         unset(__std)
         unset(__stdver)

+ 1 - 0
Modules/Compiler/IAR-C.cmake

@@ -14,6 +14,7 @@ if(NOT DEFINED CMAKE_C_COMPILER_VERSION)
   message(FATAL_ERROR "CMAKE_C_COMPILER_VERSION not detected.  This should be automatic.")
 endif()
 
+# Unused after CMP0128
 set(CMAKE_C_EXTENSION_COMPILE_OPTION -e)
 
 if(CMAKE_C_COMPILER_VERSION_INTERNAL VERSION_GREATER 7)

+ 1 - 1
Modules/Compiler/IAR-CXX.cmake

@@ -27,7 +27,7 @@ if(NOT CMAKE_IAR_CXX_FLAG)
 endif()
 
 set(CMAKE_CXX_STANDARD_COMPILE_OPTION "")
-set(CMAKE_CXX_EXTENSION_COMPILE_OPTION -e)
+set(CMAKE_CXX_EXTENSION_COMPILE_OPTION -e) # Unused after CMP0128
 
 set(CMAKE_CXX${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT}_STANDARD_COMPILE_OPTION "")
 set(CMAKE_CXX${CMAKE_CXX_STANDARD_COMPUTED_DEFAULT}_EXTENSION_COMPILE_OPTION -e)

+ 4 - 1
Source/cmPolicies.h

@@ -382,7 +382,10 @@ class cmMakefile;
          21, 0, cmPolicies::WARN)                                             \
   SELECT(POLICY, CMP0127,                                                     \
          "cmake_dependent_option() supports full Condition Syntax.", 3, 22,   \
-         0, cmPolicies::WARN)
+         0, cmPolicies::WARN)                                                 \
+  SELECT(POLICY, CMP0128,                                                     \
+         "Selection of language standard and extension flags improved.", 3,   \
+         22, 0, cmPolicies::WARN)
 
 #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
 #define CM_FOR_EACH_POLICY_ID(POLICY)                                         \

+ 72 - 15
Source/cmStandardLevelResolver.cxx

@@ -20,6 +20,7 @@
 #include "cmGlobalGenerator.h"
 #include "cmMakefile.h"
 #include "cmMessageType.h"
+#include "cmPolicies.h"
 #include "cmStringAlgorithms.h"
 #include "cmTarget.h"
 #include "cmValue.h"
@@ -83,25 +84,62 @@ struct StandardLevelComputer
       return std::string{};
     }
 
+    cmPolicies::PolicyStatus const cmp0128{ makefile->GetPolicyStatus(
+      cmPolicies::CMP0128) };
+    bool const defaultExt{ cmIsOn(*makefile->GetDefinition(
+      cmStrCat("CMAKE_", this->Language, "_EXTENSIONS_DEFAULT"))) };
     bool ext = true;
+
+    if (cmp0128 == cmPolicies::NEW) {
+      ext = defaultExt;
+    }
+
     if (cmValue extPropValue = target->GetLanguageExtensions(this->Language)) {
-      if (cmIsOff(*extPropValue)) {
-        ext = false;
-      }
+      ext = cmIsOn(*extPropValue);
     }
 
+    std::string const type{ ext ? "EXTENSION" : "STANDARD" };
+
     cmValue standardProp = target->GetLanguageStandard(this->Language, config);
     if (!standardProp) {
-      if (ext) {
-        // No language standard is specified and extensions are not disabled.
-        // Check if this compiler needs a flag to enable extensions.
-        return cmStrCat("CMAKE_", this->Language, "_EXTENSION_COMPILE_OPTION");
+      if (cmp0128 == cmPolicies::NEW) {
+        // Add extension flag if compiler's default doesn't match.
+        if (ext != defaultExt) {
+          return cmStrCat("CMAKE_", this->Language, *defaultStd, "_", type,
+                          "_COMPILE_OPTION");
+        }
+      } else {
+        if (cmp0128 == cmPolicies::WARN &&
+            makefile->PolicyOptionalWarningEnabled(
+              "CMAKE_POLICY_WARNING_CMP0128") &&
+            ext != defaultExt) {
+          const char* state{};
+          if (ext) {
+            if (!makefile->GetDefinition(cmStrCat(
+                  "CMAKE_", this->Language, "_EXTENSION_COMPILE_OPTION"))) {
+              state = "enabled";
+            }
+          } else {
+            state = "disabled";
+          }
+          if (state) {
+            makefile->IssueMessage(
+              MessageType::AUTHOR_WARNING,
+              cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0128),
+                       "\nFor compatibility with older versions of CMake, "
+                       "compiler extensions won't be ",
+                       state, "."));
+          }
+        }
+
+        if (ext) {
+          return cmStrCat("CMAKE_", this->Language,
+                          "_EXTENSION_COMPILE_OPTION");
+        }
       }
       return std::string{};
     }
 
-    std::string const type = ext ? "EXTENSION" : "STANDARD";
-
     if (target->GetLanguageStandardRequired(this->Language)) {
       std::string option_flag = cmStrCat(
         "CMAKE_", this->Language, *standardProp, "_", type, "_COMPILE_OPTION");
@@ -121,6 +159,25 @@ struct StandardLevelComputer
       return option_flag;
     }
 
+    // If the request matches the compiler's defaults we don't need to add
+    // anything.
+    if (*standardProp == *defaultStd && ext == defaultExt) {
+      if (cmp0128 == cmPolicies::NEW) {
+        return std::string{};
+      }
+
+      if (cmp0128 == cmPolicies::WARN &&
+          makefile->PolicyOptionalWarningEnabled(
+            "CMAKE_POLICY_WARNING_CMP0128")) {
+        makefile->IssueMessage(
+          MessageType::AUTHOR_WARNING,
+          cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0128),
+                   "\nFor compatibility with older versions of CMake, "
+                   "unnecessary flags for language standard or compiler "
+                   "extensions may be added."));
+      }
+    }
+
     std::string standardStr(*standardProp);
     if (this->Language == "CUDA" && standardStr == "98") {
       standardStr = "03";
@@ -147,17 +204,17 @@ struct StandardLevelComputer
       return std::string{};
     }
 
-    // If the standard requested is older than the compiler's default
-    // then we need to use a flag to change it.
-    if (stdIt <= defaultStdIt) {
+    // If the standard requested is older than the compiler's default or the
+    // extension mode doesn't match then we need to use a flag.
+    if (stdIt < defaultStdIt) {
       auto offset = std::distance(cm::cbegin(stds), stdIt);
       return cmStrCat("CMAKE_", this->Language, stdsStrings[offset], "_", type,
                       "_COMPILE_OPTION");
     }
 
-    // The standard requested is at least as new as the compiler's default,
-    // and the standard request is not required.  Decay to the newest standard
-    // for which a flag is defined.
+    // The compiler's default is at least as new as the requested standard,
+    // and the requested standard is not required.  Decay to the newest
+    // standard for which a flag is defined.
     for (; defaultStdIt < stdIt; --stdIt) {
       auto offset = std::distance(cm::cbegin(stds), stdIt);
       std::string option_flag =

+ 1 - 1
Tests/RunCMake/CMakeLists.txt

@@ -310,7 +310,7 @@ add_RunCMake_test(TargetProperties)
 add_RunCMake_test(ToolchainFile)
 add_RunCMake_test(find_dependency)
 add_RunCMake_test(CompileDefinitions)
-add_RunCMake_test(CompileFeatures)
+add_RunCMake_test(CompileFeatures -DCMake_NO_C_STANDARD=${CMake_NO_C_STANDARD} -DCMake_NO_CXX_STANDARD=${CMake_NO_CXX_STANDARD})
 add_RunCMake_test(Policy)
 add_RunCMake_test(PolicyScope)
 add_RunCMake_test(WriteBasicConfigVersionFile)

+ 8 - 0
Tests/RunCMake/CompileFeatures/CMP0128WarnMatch-stderr.txt

@@ -0,0 +1,8 @@
+CMake Warning \(dev\) in CMakeLists\.txt:
+  Policy CMP0128 is not set: Selection of language standard and extension
+  flags improved\.  Run "cmake --help-policy CMP0128" for policy details\.  Use
+  the cmake_policy command to set the policy and suppress this warning\.
+
+  For compatibility with older versions of CMake, unnecessary flags for
+  language standard or compiler extensions may be added.
+This warning is for project developers\.  Use -Wno-dev to suppress it\.

+ 7 - 0
Tests/RunCMake/CompileFeatures/CMP0128WarnMatch.cmake

@@ -0,0 +1,7 @@
+enable_language(@lang@)
+cmake_policy(SET CMP0128 OLD)
+set(CMAKE_POLICY_WARNING_CMP0128 ON)
+
+set(CMAKE_@lang@_EXTENSIONS @extensions_default@)
+set(CMAKE_@lang@_STANDARD @standard_default@)
+add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@")

+ 8 - 0
Tests/RunCMake/CompileFeatures/CMP0128WarnUnset-stderr.txt

@@ -0,0 +1,8 @@
+CMake Warning \(dev\) in CMakeLists\.txt:
+  Policy CMP0128 is not set: Selection of language standard and extension
+  flags improved\.  Run "cmake --help-policy CMP0128" for policy details\.  Use
+  the cmake_policy command to set the policy and suppress this warning\.
+
+  For compatibility with older versions of CMake, compiler extensions won't
+  be @opposite@\.
+This warning is for project developers\.  Use -Wno-dev to suppress it\.

+ 6 - 0
Tests/RunCMake/CompileFeatures/CMP0128WarnUnset.cmake

@@ -0,0 +1,6 @@
+enable_language(@lang@)
+cmake_policy(SET CMP0128 OLD)
+set(CMAKE_POLICY_WARNING_CMP0128 ON)
+
+set(CMAKE_@lang@_EXTENSIONS @extensions_opposite@)
+add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@")

+ 8 - 0
Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag-build-check.cmake

@@ -0,0 +1,8 @@
+foreach(flag @flags@)
+  string(FIND "${actual_stdout}" "${flag}" position)
+
+  if(NOT position EQUAL -1)
+    set(RunCMake_TEST_FAILED "\"${flag}\" compile flag found.")
+    break()
+  endif()
+endforeach()

+ 9 - 0
Tests/RunCMake/CompileFeatures/NoUnnecessaryFlag.cmake

@@ -0,0 +1,9 @@
+enable_language(@lang@)
+
+# Make sure the compile command is not hidden.
+string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}")
+string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}")
+
+set(CMAKE_@lang@_EXTENSIONS @extensions_default@)
+set(CMAKE_@lang@_STANDARD @standard_default@)
+add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@")

+ 119 - 16
Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake

@@ -9,17 +9,8 @@ run_cmake(NotAFeature_OriginDebugGenex)
 run_cmake(NotAFeature_OriginDebugTransitive)
 run_cmake(NotAFeature_OriginDebugCommand)
 
-run_cmake(generate_feature_list)
-file(READ
-  "${RunCMake_BINARY_DIR}/generate_feature_list-build/c_features.txt"
-  C_FEATURES
-)
-file(READ
-  "${RunCMake_BINARY_DIR}/generate_feature_list-build/cxx_features.txt"
-  CXX_FEATURES
-)
-include("${RunCMake_BINARY_DIR}/generate_feature_list-build/c_standard_default.cmake")
-include("${RunCMake_BINARY_DIR}/generate_feature_list-build/cxx_standard_default.cmake")
+run_cmake(compiler_introspection)
+include("${RunCMake_BINARY_DIR}/compiler_introspection-build/info.cmake")
 
 if (NOT C_FEATURES)
   run_cmake(NoSupportedCFeatures)
@@ -43,21 +34,133 @@ elseif (cxx_std_98 IN_LIST CXX_FEATURES AND cxx_std_11 IN_LIST CXX_FEATURES)
   unset(RunCMake_TEST_OPTIONS)
 endif()
 
+configure_file("${RunCMake_SOURCE_DIR}/CMakeLists.txt" "${RunCMake_BINARY_DIR}/CMakeLists.txt" COPYONLY)
+
+macro(test_build)
+  set(test ${name}-${lang})
+
+  configure_file("${RunCMake_SOURCE_DIR}/${name}.cmake" "${RunCMake_BINARY_DIR}/${test}.cmake" @ONLY)
+  if(EXISTS "${RunCMake_SOURCE_DIR}/${name}-build-check.cmake")
+    configure_file("${RunCMake_SOURCE_DIR}/${name}-build-check.cmake" "${RunCMake_BINARY_DIR}/${test}-build-check.cmake" @ONLY)
+  endif()
+  if(EXISTS "${RunCMake_SOURCE_DIR}/${name}-stderr.txt")
+    configure_file("${RunCMake_SOURCE_DIR}/${name}-stderr.txt" "${RunCMake_BINARY_DIR}/${test}-stderr.txt" @ONLY)
+  endif()
+
+  set(RunCMake_SOURCE_DIR "${RunCMake_BINARY_DIR}")
+  set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${test}-build")
+  run_cmake(${test})
+  set(RunCMake_TEST_NO_CLEAN 1)
+  run_cmake_command(${test}-build ${CMAKE_COMMAND} --build . ${ARGN})
+endmacro()
+
+# Mangle flags such as they're in verbose build output.
+macro(mangle_flags variable)
+  set(result "${${variable}}")
+
+  if(RunCMake_GENERATOR MATCHES "Visual Studio" AND MSVC_TOOLSET_VERSION GREATER_EQUAL 141)
+    string(REPLACE "-" "/" result "${result}")
+  elseif(RunCMake_GENERATOR STREQUAL "Xcode" AND CMAKE_XCODE_BUILD_SYSTEM GREATER_EQUAL 12)
+    string(REPLACE "=" [[\\=]] result "${result}")
+  endif()
+
+  string(REPLACE ";" " " result "${result}")
+  list(APPEND flags "${result}")
+endmacro()
+
+function(test_unset_standard)
+  if(extensions_opposite)
+    set(flag_ext "_EXT")
+  endif()
+
+  set(flag "${${lang}${${lang}_STANDARD_DEFAULT}${flag_ext}_FLAG}")
+
+  if(NOT flag)
+    return()
+  endif()
+
+  mangle_flags(flag)
+
+  set(name UnsetStandard)
+  set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0128=NEW)
+  test_build(--verbose)
+endfunction()
+
+function(test_no_unnecessary_flag)
+  set(standard_flag "${${lang}${${lang}_STANDARD_DEFAULT}_FLAG}")
+  set(extension_flag "${${lang}${${lang}_STANDARD_DEFAULT}_EXT_FLAG}")
+
+  if(NOT standard_flag AND NOT extension_flag)
+    return()
+  endif()
+
+  mangle_flags(standard_flag)
+  mangle_flags(extension_flag)
+
+  set(name NoUnnecessaryFlag)
+  set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0128=NEW)
+  test_build(--verbose)
+endfunction()
+
+function(test_cmp0128_warn_match)
+  set(name CMP0128WarnMatch)
+  test_build()
+endfunction()
+
+function(test_cmp0128_warn_unset)
+  # For compilers that had CMAKE_<LANG>_EXTENSION_COMPILE_OPTION (only IAR)
+  # there is no behavioural change and thus no warning.
+  if(NOT "${${lang}_EXT_FLAG}" STREQUAL "")
+    return()
+  endif()
+
+  if(extensions_opposite)
+    set(opposite "enabled")
+  else()
+    set(opposite "disabled")
+  endif()
+
+  set(name CMP0128WarnUnset)
+  test_build()
+endfunction()
+
+function(test_lang lang ext)
+  if(CMake_NO_${lang}_STANDARD)
+    return()
+  endif()
+
+  set(extensions_default "${${lang}_EXTENSIONS_DEFAULT}")
+  set(standard_default "${${lang}_STANDARD_DEFAULT}")
+
+  if(extensions_default)
+    set(extensions_opposite OFF)
+  else()
+    set(extensions_opposite ON)
+  endif()
+
+  test_unset_standard()
+  test_no_unnecessary_flag()
+  test_cmp0128_warn_match()
+  test_cmp0128_warn_unset()
+endfunction()
+
+if(C_STANDARD_DEFAULT)
+  test_lang(C c)
+endif()
+
 if(CXX_STANDARD_DEFAULT)
   run_cmake(NotAStandard)
 
   foreach(standard 98 11)
-    file(READ
-      "${RunCMake_BINARY_DIR}/generate_feature_list-build/cxx${standard}_flag.txt"
-      CXX${standard}_FLAG
-    )
     if (CXX${standard}_FLAG STREQUAL NOTFOUND)
       run_cmake(RequireCXX${standard})
       run_cmake(RequireCXX${standard}Variable)
     endif()
-    if (CXX${standard}EXT_FLAG STREQUAL NOTFOUND)
+    if (CXX${standard}_EXT_FLAG STREQUAL NOTFOUND)
       run_cmake(RequireCXX${standard}Ext)
       run_cmake(RequireCXX${standard}ExtVariable)
     endif()
   endforeach()
+
+  test_lang(CXX cpp)
 endif()

+ 12 - 0
Tests/RunCMake/CompileFeatures/UnsetStandard-build-check.cmake

@@ -0,0 +1,12 @@
+foreach(flag @flags@)
+  string(FIND "${actual_stdout}" "${flag}" position)
+
+  if(NOT position EQUAL -1)
+    set(found TRUE)
+    break()
+  endif()
+endforeach()
+
+if(NOT found)
+  set(RunCMake_TEST_FAILED "No compile flags from \"@flags@\" found for CMAKE_@lang@_EXTENSIONS=@extensions_opposite@.")
+endif()

+ 8 - 0
Tests/RunCMake/CompileFeatures/UnsetStandard.cmake

@@ -0,0 +1,8 @@
+enable_language(@lang@)
+
+# Make sure the compile command is not hidden.
+string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}")
+string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_@lang@_COMPILE_OBJECT "${CMAKE_@lang@_COMPILE_OBJECT}")
+
+set(CMAKE_@lang@_EXTENSIONS @extensions_opposite@)
+add_library(foo "@RunCMake_SOURCE_DIR@/empty.@ext@")

+ 38 - 0
Tests/RunCMake/CompileFeatures/compiler_introspection.cmake

@@ -0,0 +1,38 @@
+enable_language(C CXX)
+
+set(info "")
+
+if(MSVC_TOOLSET_VERSION)
+  string(APPEND info "
+set(MSVC_TOOLSET_VERSION ${MSVC_TOOLSET_VERSION})
+
+")
+endif()
+
+if(CMAKE_XCODE_BUILD_SYSTEM)
+  string(APPEND info "
+set(CMAKE_XCODE_BUILD_SYSTEM ${CMAKE_XCODE_BUILD_SYSTEM})
+
+")
+endif()
+
+macro(info lang)
+  string(APPEND info "\
+set(${lang}_STANDARD_DEFAULT ${CMAKE_${lang}_STANDARD_DEFAULT})
+set(${lang}_EXTENSIONS_DEFAULT ${CMAKE_${lang}_EXTENSIONS_DEFAULT})
+set(${lang}_FEATURES ${CMAKE_${lang}_COMPILE_FEATURES})
+
+set(${lang}_EXT_FLAG ${CMAKE_${lang}_EXTENSION_COMPILE_OPTION})
+")
+
+  foreach(standard ${ARGN})
+    string(APPEND info "\
+set(${lang}${standard}_FLAG ${CMAKE_${lang}${standard}_STANDARD_COMPILE_OPTION})
+set(${lang}${standard}_EXT_FLAG ${CMAKE_${lang}${standard}_EXTENSION_COMPILE_OPTION})
+")
+  endforeach()
+endmacro()
+
+info(C 90 99 11 17 23)
+info(CXX 98 11 14 17 20 23)
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" "${info}")

+ 1 - 1
Tests/RunCMake/CompileFeatures/empty.c

@@ -1,7 +1,7 @@
 #ifdef _WIN32
 __declspec(dllexport)
 #endif
-  int empty()
+  int empty(void)
 {
   return 0;
 }

+ 0 - 43
Tests/RunCMake/CompileFeatures/generate_feature_list.cmake

@@ -1,43 +0,0 @@
-
-enable_language(C)
-
-file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/c_features.txt"
-  "${CMAKE_C_COMPILE_FEATURES}"
-)
-
-file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx_features.txt"
-  "${CMAKE_CXX_COMPILE_FEATURES}"
-)
-
-if(DEFINED CMAKE_C_STANDARD_DEFAULT)
-  set(c_standard_default_code "set(C_STANDARD_DEFAULT \"${CMAKE_C_STANDARD_DEFAULT}\")\n")
-else()
-  set(c_standard_default_code "unset(C_STANDARD_DEFAULT)\n")
-endif()
-file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/c_standard_default.cmake" "${c_standard_default_code}")
-
-if(DEFINED CMAKE_CXX_STANDARD_DEFAULT)
-  set(cxx_standard_default_code "set(CXX_STANDARD_DEFAULT \"${CMAKE_CXX_STANDARD_DEFAULT}\")\n")
-else()
-  set(cxx_standard_default_code "unset(CXX_STANDARD_DEFAULT)\n")
-endif()
-file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx_standard_default.cmake" "${cxx_standard_default_code}")
-
-foreach(standard 98 11)
-  set(CXX${standard}_FLAG NOTFOUND)
-  if (DEFINED CMAKE_CXX${standard}_STANDARD_COMPILE_OPTION)
-    set(CXX${standard}_FLAG ${CMAKE_CXX${standard}_STANDARD_COMPILE_OPTION})
-  endif()
-
-  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx${standard}_flag.txt"
-    "${CXX${standard}_FLAG}"
-  )
-  set(CXX${standard}EXT_FLAG NOTFOUND)
-  if (DEFINED CMAKE_CXX${standard}_EXTENSION_COMPILE_OPTION)
-    set(CXX${standard}EXT_FLAG ${CMAKE_CXX${standard}_EXTENSION_COMPILE_OPTION})
-  endif()
-
-  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cxx${standard}ext_flag.txt"
-    "${CXX${standard}EXT_FLAG}"
-  )
-endforeach()