1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

set: Explicitly unset empty environment variables on Windows

KWSys's SystemTools::PutEnv implementation, on Windows, has long
interpreted `A=` as unset.  This differs from the behavior on other
platforms.  Code the distinction explicitly in `set(ENV{VAR})`.

Issue: #27285
This commit is contained in:
Brad King
2025-10-06 19:48:59 -04:00
parent 723a83d8cd
commit aa5711490f

View File

@@ -24,6 +24,14 @@
namespace {
void setENV(std::string const& var, cm::string_view val)
{
#ifdef _WIN32
if (val.empty()) {
// FIXME(#27285): On Windows, PutEnv previously treated empty as unset.
// KWSys was fixed, but we need to retain the behavior for compatibility.
cmSystemTools::UnPutEnv(var);
return;
}
#endif
cmSystemTools::PutEnv(cmStrCat(var, '=', val));
}
}