summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-05-16 14:16:34 (GMT)
committerBrad King <brad.king@kitware.com>2022-05-16 14:47:21 (GMT)
commita6562ff57908e6f03ef44eb0438ba9937f28174c (patch)
tree66891e45efadaa7589705021e66d96a476088e82
parent4843a376767c2c4b46e29ed85ac823443317ca40 (diff)
downloadCMake-a6562ff57908e6f03ef44eb0438ba9937f28174c.zip
CMake-a6562ff57908e6f03ef44eb0438ba9937f28174c.tar.gz
CMake-a6562ff57908e6f03ef44eb0438ba9937f28174c.tar.bz2
try_compile: Add option to skip passing platform variables
Add a `CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES` variable to tell `try_compile` not to pass platform variables to the test project. Issue: #23219
-rw-r--r--Help/command/try_compile.rst4
-rw-r--r--Help/manual/cmake-variables.7.rst1
-rw-r--r--Help/policy/CMP0137.rst4
-rw-r--r--Help/release/dev/try_compile-project-platform-vars.rst4
-rw-r--r--Help/variable/CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES.rst10
-rw-r--r--Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst4
-rw-r--r--Source/cmCoreTryCompile.cxx7
-rw-r--r--Tests/RunCMake/try_compile/CMP0137-Common.cmake8
-rw-r--r--Tests/RunCMake/try_compile/CMP0137-NEW-stdout.txt3
-rw-r--r--Tests/RunCMake/try_compile/CMP0137-WARN-stdout.txt3
10 files changed, 45 insertions, 3 deletions
diff --git a/Help/command/try_compile.rst b/Help/command/try_compile.rst
index 06b2362..806a98d 100644
--- a/Help/command/try_compile.rst
+++ b/Help/command/try_compile.rst
@@ -216,3 +216,7 @@ a build configuration.
.. versionchanged:: 3.14
For the :generator:`Green Hills MULTI` generator the GHS toolset and target
system customization cache variables are also propagated into the test project.
+
+.. versionadded:: 3.24
+ The :variable:`CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES` variable may be
+ set to disable passing platform variables into the test project.
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 80160b6..41f2f30 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -502,6 +502,7 @@ Variables that Control the Build
/variable/CMAKE_STATIC_LINKER_FLAGS_CONFIG_INIT
/variable/CMAKE_STATIC_LINKER_FLAGS_INIT
/variable/CMAKE_TRY_COMPILE_CONFIGURATION
+ /variable/CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES
/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
/variable/CMAKE_TRY_COMPILE_TARGET_TYPE
/variable/CMAKE_UNITY_BUILD
diff --git a/Help/policy/CMP0137.rst b/Help/policy/CMP0137.rst
index 2efb906..ba3cb9c 100644
--- a/Help/policy/CMP0137.rst
+++ b/Help/policy/CMP0137.rst
@@ -21,6 +21,10 @@ 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.
+Regardless of the policy setting, the
+:variable:`CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES` variable may be set
+to suppress passing the platform variables through either signature.
+
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
diff --git a/Help/release/dev/try_compile-project-platform-vars.rst b/Help/release/dev/try_compile-project-platform-vars.rst
index 2f409a3..06596d4 100644
--- a/Help/release/dev/try_compile-project-platform-vars.rst
+++ b/Help/release/dev/try_compile-project-platform-vars.rst
@@ -4,3 +4,7 @@ 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`.
+
+* The :variable:`CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES` variable
+ was added to tell the :command:`try_compile` command not to
+ pass any platform variables to the test project.
diff --git a/Help/variable/CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES.rst b/Help/variable/CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES.rst
new file mode 100644
index 0000000..944caa5
--- /dev/null
+++ b/Help/variable/CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES.rst
@@ -0,0 +1,10 @@
+CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES
+---------------------------------------
+
+Set to a true value to tell the :command:`try_compile` command not
+to propagate any platform variables into the test project.
+
+The :command:`try_compile` command normally passes some CMake variables
+that configure the platform and toolchain behavior into test projects.
+See policy :policy:`CMP0137`. This variable may be set to disable
+that behavior.
diff --git a/Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst b/Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst
index 5e84fd0..6b26d14 100644
--- a/Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst
+++ b/Help/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.rst
@@ -31,3 +31,7 @@ command source file signature.
Listed variables are propagated to the :command:`try_compile`
:ref:`whole-project <Try Compiling Whole Projects>` signature too.
See :policy:`CMP0137`.
+
+.. versionadded:: 3.24
+ The :variable:`CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES` variable may be
+ set to disable passing platform variables into the test project.
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 39c2b3a..caa413b 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -872,9 +872,10 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
}
// Forward a set of variables to the inner project cache.
- if (this->SrcFileSignature ||
- this->Makefile->GetPolicyStatus(cmPolicies::CMP0137) ==
- cmPolicies::NEW) {
+ if ((this->SrcFileSignature ||
+ this->Makefile->GetPolicyStatus(cmPolicies::CMP0137) ==
+ cmPolicies::NEW) &&
+ !this->Makefile->IsOn("CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES")) {
std::set<std::string> vars;
vars.insert(&c_properties[lang_property_start],
&c_properties[lang_property_start + lang_property_size]);
diff --git a/Tests/RunCMake/try_compile/CMP0137-Common.cmake b/Tests/RunCMake/try_compile/CMP0137-Common.cmake
index 867475d..2c1bc0d 100644
--- a/Tests/RunCMake/try_compile/CMP0137-Common.cmake
+++ b/Tests/RunCMake/try_compile/CMP0137-Common.cmake
@@ -6,3 +6,11 @@ try_compile(RESULT_VAR
${CMAKE_CURRENT_SOURCE_DIR}/CMP0137
TestCMP0137)
include(${CMAKE_CURRENT_BINARY_DIR}/CMP0137-build/info.cmake OPTIONAL)
+
+message(STATUS "Enabling CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES")
+set(CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES 1)
+try_compile(RESULT_VAR
+ ${CMAKE_CURRENT_BINARY_DIR}/CMP0137-build2
+ ${CMAKE_CURRENT_SOURCE_DIR}/CMP0137
+ TestCMP0137)
+include(${CMAKE_CURRENT_BINARY_DIR}/CMP0137-build2/info.cmake OPTIONAL)
diff --git a/Tests/RunCMake/try_compile/CMP0137-NEW-stdout.txt b/Tests/RunCMake/try_compile/CMP0137-NEW-stdout.txt
index 0a6bb38..abc61dc 100644
--- a/Tests/RunCMake/try_compile/CMP0137-NEW-stdout.txt
+++ b/Tests/RunCMake/try_compile/CMP0137-NEW-stdout.txt
@@ -1,2 +1,5 @@
-- CMAKE_ENABLE_EXPORTS='1'
-- FOO='2'
+-- Enabling CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES
+-- CMAKE_ENABLE_EXPORTS=''
+-- FOO=''
diff --git a/Tests/RunCMake/try_compile/CMP0137-WARN-stdout.txt b/Tests/RunCMake/try_compile/CMP0137-WARN-stdout.txt
index fda1e41..2e4bebe 100644
--- a/Tests/RunCMake/try_compile/CMP0137-WARN-stdout.txt
+++ b/Tests/RunCMake/try_compile/CMP0137-WARN-stdout.txt
@@ -1,2 +1,5 @@
-- CMAKE_ENABLE_EXPORTS=''
-- FOO=''
+-- Enabling CMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES
+-- CMAKE_ENABLE_EXPORTS=''
+-- FOO=''