diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2003-01-09 16:28:29 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2003-01-09 16:28:29 (GMT) |
commit | 384523a3153d911853f8c7fffbc8c1b7bb9ca421 (patch) | |
tree | 25886b1a1d25cf003747fde42278918186852b56 /Source | |
parent | eff6a204327aeba3916c2d5c2f79d90881ef9430 (diff) | |
download | CMake-384523a3153d911853f8c7fffbc8c1b7bb9ca421.zip CMake-384523a3153d911853f8c7fffbc8c1b7bb9ca421.tar.gz CMake-384523a3153d911853f8c7fffbc8c1b7bb9ca421.tar.bz2 |
restore the environment for cxx and cc in global generator
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 56 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 2 |
2 files changed, 53 insertions, 5 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 71d3568..a6c4500 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -21,10 +21,46 @@ cmGlobalGenerator::cmGlobalGenerator() { + // Save the environment variables CXX and CC + m_CXXEnvironment = getenv("CXX"); + m_CCEnvironment = getenv("CC"); } cmGlobalGenerator::~cmGlobalGenerator() -{ +{ + // restore the original environment variables CXX and CC + // Restor CC + static char envCC[5000]; + std::string env = "CC="; + if(m_CCEnvironment) + { + env += m_CCEnvironment; + } + unsigned int size = env.size(); + if(size > 4999) + { + size = 4999; + } + strncpy(envCC, env.c_str(), size); + envCC[4999] = 0; + putenv(envCC); + + // Restore CXX + static char envCXX[5000]; + env = "CXX="; + if(m_CXXEnvironment) + { + env += m_CXXEnvironment; + } + size = env.size(); + if(size > 4999) + { + size = 4999; + } + strncpy(envCXX, env.c_str(), size); + envCXX[4999] = 0; + putenv(envCXX); + // Delete any existing cmLocalGenerators unsigned int i; for (i = 0; i < m_LocalGenerators.size(); ++i) @@ -118,8 +154,13 @@ void cmGlobalGenerator::EnableLanguage(const char* lang, static char envCC[5000]; std::string env = "CC=${CMAKE_C_COMPILER}"; mf->ExpandVariablesInString(env); - strncpy(envCC, env.c_str(), 4999); - envCC[4999] = 0; + unsigned int size = env.size(); + if(size > 4999) + { + size = 4999; + } + strncpy(envCC, env.c_str(), size); + envCC[size] = 0; putenv(envCC); } } @@ -141,8 +182,13 @@ void cmGlobalGenerator::EnableLanguage(const char* lang, if(mf->GetDefinition("CMAKE_CXX_COMPILER")) { std::string env = "CXX=${CMAKE_CXX_COMPILER}"; - mf->ExpandVariablesInString(env); - strncpy(envCXX, env.c_str(), 4999); + mf->ExpandVariablesInString(env); + unsigned int size = env.size(); + if(size > 4999) + { + size = 4999; + } + strncpy(envCXX, env.c_str(), size); envCXX[4999] = 0; putenv(envCXX); } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index ee2a1cb..3d61d9d 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -109,6 +109,8 @@ protected: private: std::map<cmStdString, bool> m_LanguageEnabled; + const char* m_CXXEnvironment; + const char* m_CCEnvironment; }; #endif |