summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2022-03-23 03:31:04 (GMT)
committerBrad King <brad.king@kitware.com>2022-03-29 13:42:59 (GMT)
commit05e510bf0bf8d730b03e8b389d088919825b4b5a (patch)
tree12fc8e73e25bf76f2e6b243ce4469dae64c84370 /Source
parent774a9eb210c09da97135cb733828752e627c96c7 (diff)
downloadCMake-05e510bf0bf8d730b03e8b389d088919825b4b5a.zip
CMake-05e510bf0bf8d730b03e8b389d088919825b4b5a.tar.gz
CMake-05e510bf0bf8d730b03e8b389d088919825b4b5a.tar.bz2
CMP0132: Don't set compiler environment variables on first run
When running CMake for the first time in a build tree, for some generators CMake would set compiler environment variables like CC, CXX, etc. when the corresponding language is enabled. That behavior was never documented and can result in different behavior between the first and subsequent runs. Add a policy to no longer set those environment variables. Fixes: #21378
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGlobalGenerator.cxx4
-rw-r--r--Source/cmPolicies.h5
2 files changed, 7 insertions, 2 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index baa54e5..fb84cd1 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -759,7 +759,9 @@ void cmGlobalGenerator::EnableLanguage(
needTestLanguage[lang] = true;
// Some generators like visual studio should not use the env variables
// So the global generator can specify that in this variable
- if (!mf->GetDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV")) {
+ if ((mf->GetPolicyStatus(cmPolicies::CMP0132) == cmPolicies::OLD ||
+ mf->GetPolicyStatus(cmPolicies::CMP0132) == cmPolicies::WARN) &&
+ !mf->GetDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV")) {
// put ${CMake_(LANG)_COMPILER_ENV_VAR}=${CMAKE_(LANG)_COMPILER
// into the environment, in case user scripts want to run
// configure, or sub cmakes
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 3b9d067..434c51c 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -393,7 +393,10 @@ class cmMakefile;
3, 24, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0131, \
"LINK_LIBRARIES supports the LINK_ONLY generator expression.", 3, \
- 24, 0, cmPolicies::WARN)
+ 24, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0132, \
+ "Do not set compiler environment variables on first run", 3, 24, 0, \
+ cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \