From aa5711490f067cb03cfaac9b162eb927df84a0c2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 6 Oct 2025 19:48:59 -0400 Subject: [PATCH] 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 --- Source/cmSetCommand.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx index 203c995066..6a34697279 100644 --- a/Source/cmSetCommand.cxx +++ b/Source/cmSetCommand.cxx @@ -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)); } }