summaryrefslogtreecommitdiff
path: root/Help
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-05-16 10:04:48 -0400
committerBrad King <brad.king@kitware.com>2022-05-16 10:39:42 -0400
commit4843a376767c2c4b46e29ed85ac823443317ca40 (patch)
tree0a957181b6b5e352e5793d2ff845b365fed50e59 /Help
parent364fde65ee93588cb519ece09b161c0e8e826c3c (diff)
downloadcmake-4843a376767c2c4b46e29ed85ac823443317ca40.tar.gz
try_compile: Propagate platform variables in project-mode too
Add policy CMP0137 to propagate both our builtin variables and those listed by `CMAKE_TRY_COMPILE_PLATFORM_VARIABLES` to `try_compile` whole-project builds. Inspired-by: Alexander Neumann <Alexander.Neumann@hamburg.de> Fixes: #23219
Diffstat (limited to 'Help')
-rw-r--r--Help/command/try_compile.rst11
-rw-r--r--Help/manual/cmake-policies.7.rst1
-rw-r--r--Help/policy/CMP0137.rst29
-rw-r--r--Help/release/dev/try_compile-project-platform-vars.rst6
-rw-r--r--Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst5
5 files changed, 52 insertions, 0 deletions
diff --git a/Help/command/try_compile.rst b/Help/command/try_compile.rst
index 4b2a63169e..06b236228c 100644
--- a/Help/command/try_compile.rst
+++ b/Help/command/try_compile.rst
@@ -7,6 +7,8 @@ try_compile
Try building some code.
+.. _`Try Compiling Whole Projects`:
+
Try Compiling Whole Projects
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -25,6 +27,15 @@ will not be deleted after this command is run. Specify ``<targetName>`` to
build a specific target instead of the ``all`` or ``ALL_BUILD`` target. See
below for the meaning of other options.
+.. versionchanged:: 3.24
+ CMake variables describing platform settings, and those listed by the
+ :variable:`CMAKE_TRY_COMPILE_PLATFORM_VARIABLES` variable, are propagated
+ into the project's build configuration. See policy :policy:`CMP0137`.
+ Previously this was only done by the
+ :ref:`source file <Try Compiling Source Files>` signature.
+
+.. _`Try Compiling Source Files`:
+
Try Compiling Source Files
^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst
index 259cebbe64..788d086ce1 100644
--- a/Help/manual/cmake-policies.7.rst
+++ b/Help/manual/cmake-policies.7.rst
@@ -58,6 +58,7 @@ Policies Introduced by CMake 3.24
.. toctree::
:maxdepth: 1
+ CMP0137: try_compile() passes platform variables in project mode. </policy/CMP0137>
CMP0136: Watcom runtime library flags are selected by an abstraction. </policy/CMP0136>
CMP0135: ExternalProject ignores timestamps in archives by default for the URL download method. </policy/CMP0135>
CMP0134: Fallback to \"HOST\" Windows registry view when \"TARGET\" view is not usable. </policy/CMP0134>
diff --git a/Help/policy/CMP0137.rst b/Help/policy/CMP0137.rst
new file mode 100644
index 0000000000..2efb9060b0
--- /dev/null
+++ b/Help/policy/CMP0137.rst
@@ -0,0 +1,29 @@
+CMP0137
+-------
+
+.. versionadded:: 3.24
+
+:command:`try_compile` passes platform variables in project mode.
+
+The :command:`try_compile` command :ref:`source file <Try Compiling Source
+Files>` signature propagates CMake variables containing platform settings,
+and those specified by the :variable:`CMAKE_TRY_COMPILE_PLATFORM_VARIABLES`
+variable, into the generated test project. This helps the test project drive
+the toolchain the same way the calling project will. In CMake 3.23 and below,
+the :ref:`whole-project <Try Compiling Whole Projects>` signature does not
+propagate platform variables automatically. CMake 3.24 and above prefer to
+propagate platform variables in the :ref:`whole-project <Try Compiling Whole
+Projects>` signature. This policy provides compatibility with projects that
+have not been updated to expect the behavior.
+
+The ``OLD`` behavior for this policy is to not pass any additional variables to
+the :ref:`whole-project <Try Compiling Whole Projects>` signature.
+The ``NEW`` behavior for this policy is to pass the same variables that the
+:ref:`source file <Try Compiling Source Files>` signature does.
+
+This policy was introduced in CMake version 3.24. Use the
+:command:`cmake_policy` command to set this policy to ``OLD`` or ``NEW``
+explicitly. Unlike many policies, CMake version |release| does *not* warn
+by default when this policy is not set and simply uses ``OLD`` behavior.
+
+.. include:: DEPRECATED.txt
diff --git a/Help/release/dev/try_compile-project-platform-vars.rst b/Help/release/dev/try_compile-project-platform-vars.rst
new file mode 100644
index 0000000000..2f409a396e
--- /dev/null
+++ b/Help/release/dev/try_compile-project-platform-vars.rst
@@ -0,0 +1,6 @@
+try_compile-project-platform-vars
+---------------------------------
+
+* The :command:`try_compile` command
+ :ref:`whole-project <Try Compiling Whole Projects>` signature
+ now propagates platform variables. See policy :policy:`CMP0137`.
diff --git a/Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst b/Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst
index d17851304b..5e84fd0c80 100644
--- a/Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst
+++ b/Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst
@@ -26,3 +26,8 @@ If a user passes ``-DMY_CUSTOM_VARIABLE=SomeValue`` to CMake then this
setting will be made visible to the toolchain file both for the main
project and for test projects generated by the :command:`try_compile`
command source file signature.
+
+.. versionchanged:: 3.24
+ Listed variables are propagated to the :command:`try_compile`
+ :ref:`whole-project <Try Compiling Whole Projects>` signature too.
+ See :policy:`CMP0137`.