Browse Source

cmake-gui: Unset empty CC,CXX on global generator change

On subsequent runs of configure from cmake-gui the global generator is
swapped.  So on runs other than the first it was setting CC and CXX to
empty when they were otherwise undefined.

Instead, restore them if non-empty and unset them if empty when changing
the global generator and a previous generator exists.

Fixes: #21449
Jake Cobb 4 years ago
parent
commit
c3bd5a6a2c
1 changed files with 6 additions and 3 deletions
  1. 6 3
      Source/cmake.cxx

+ 6 - 3
Source/cmake.cxx

@@ -1751,17 +1751,20 @@ void cmake::SetGlobalGenerator(std::unique_ptr<cmGlobalGenerator> gg)
   }
   }
   if (this->GlobalGenerator) {
   if (this->GlobalGenerator) {
     // restore the original environment variables CXX and CC
     // restore the original environment variables CXX and CC
-    // Restore CC
     std::string env = "CC=";
     std::string env = "CC=";
     if (!this->CCEnvironment.empty()) {
     if (!this->CCEnvironment.empty()) {
       env += this->CCEnvironment;
       env += this->CCEnvironment;
+      cmSystemTools::PutEnv(env);
+    } else {
+      cmSystemTools::UnPutEnv(env);
     }
     }
-    cmSystemTools::PutEnv(env);
     env = "CXX=";
     env = "CXX=";
     if (!this->CXXEnvironment.empty()) {
     if (!this->CXXEnvironment.empty()) {
       env += this->CXXEnvironment;
       env += this->CXXEnvironment;
+      cmSystemTools::PutEnv(env);
+    } else {
+      cmSystemTools::UnPutEnv(env);
     }
     }
-    cmSystemTools::PutEnv(env);
   }
   }
 
 
   // set the new
   // set the new