summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2004-01-26 13:32:46 -0500
committerBill Hoffman <bill.hoffman@kitware.com>2004-01-26 13:32:46 -0500
commit222e9a2876fccaf5b7da399430b4ec0e4db5d4d4 (patch)
treec59ac6ae8d4ac8c5bd5f6417b8ce1f828c93039a
parentdd7f85a9dc791440b48138aecfff02fb934c1027 (diff)
downloadcmake-222e9a2876fccaf5b7da399430b4ec0e4db5d4d4.tar.gz
BUG: fix put/get env problems
-rw-r--r--Source/cmCTest.cxx20
-rw-r--r--Source/cmGlobalGenerator.cxx25
-rw-r--r--Source/cmSystemTools.cxx24
-rw-r--r--Source/cmSystemTools.h4
-rw-r--r--Source/cmake.cxx50
-rw-r--r--Source/cmake.h4
6 files changed, 58 insertions, 69 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 37ed8f8fe4..c64211d4d6 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -3019,28 +3019,12 @@ int cmCTest::RunConfigurationScript()
// set any environment variables
if (ctestEnv)
{
- static char ctestEnvStatic[100][5000];
std::vector<std::string> envArgs;
cmSystemTools::ExpandListArgument(ctestEnv,envArgs);
- int numArgs = envArgs.size();
- // we have a hard limit of 100 env args due to stupid format of putenv
- if (numArgs > 100)
- {
- numArgs = 100;
- }
// for each variable/argument do a putenv
- int i;
- for (i = 0; i < numArgs; ++i)
+ for (unsigned i = 0; i < envArgs.size(); ++i)
{
- // also limit args to be at most 4K long
- std::string::size_type size = envArgs[i].size();
- if(size > 4999)
- {
- size = 4999;
- }
- strncpy(ctestEnvStatic[i], envArgs[i].c_str(), size);
- ctestEnvStatic[i][size] = 0;
- putenv(ctestEnvStatic[i]);
+ cmSystemTools::PutEnv(envArgs[i].c_str());
}
}
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 794033eeca..e22b82fcbe 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -43,7 +43,7 @@ cmGlobalGenerator::~cmGlobalGenerator()
m_LocalGenerators.clear();
}
-
+
void cmGlobalGenerator::EnableLanguage(const char* lang,
cmMakefile *mf)
{
@@ -116,7 +116,6 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
systemFile += "/Modules/CMakeDetermineSystem.cmake";
mf->ReadListFile(0, systemFile.c_str());
}
-
// check for a C compiler and configure it
if(!isLocal &&
!this->GetLanguageEnabled("C") &&
@@ -137,20 +136,11 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
this->SetLanguageEnabled("C");
// put CC in the environment in case user scripts want
// to run configure
- // see man putenv for explaination of this stupid code...
if(mf->GetDefinition("CMAKE_C_COMPILER"))
{
- static char envCC[5000];
std::string env = "CC=${CMAKE_C_COMPILER}";
mf->ExpandVariablesInString(env);
- unsigned int size = static_cast<unsigned int>(env.size());
- if(size > 4999)
- {
- size = 4999;
- }
- strncpy(envCC, env.c_str(), size);
- envCC[size] = 0;
- putenv(envCC);
+ cmSystemTools::PutEnv(env.c_str());
}
}
@@ -166,20 +156,11 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
this->SetLanguageEnabled("CXX");
// put CXX in the environment in case user scripts want
// to run configure
- // see man putenv for explaination of this stupid code...
- static char envCXX[5000];
if(mf->GetDefinition("CMAKE_CXX_COMPILER"))
{
std::string env = "CXX=${CMAKE_CXX_COMPILER}";
mf->ExpandVariablesInString(env);
- unsigned int size = static_cast<unsigned int>(env.size());
- if(size > 4999)
- {
- size = 4999;
- }
- strncpy(envCXX, env.c_str(), size);
- envCXX[size] = 0;
- putenv(envCXX);
+ cmSystemTools::PutEnv(env.c_str());
}
}
// check for a Java compiler and configure it
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 9f0ea3df5f..fe6cfa6f3d 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -1177,3 +1177,27 @@ std::string cmSystemTools::RelativePath(const char* local, const char* remote)
relativePath += relativeSplit[i];
return relativePath;
}
+class cmDeletingCharVector : public std::vector<char*>
+{
+public:
+ ~cmDeletingCharVector()
+ {
+ for(std::vector<char*>::iterator i = this->begin();
+ i != this->end(); ++i)
+ {
+ delete *i;
+ }
+ }
+};
+
+
+bool cmSystemTools::PutEnv(const char* value)
+{
+ static cmDeletingCharVector localEnvironment;
+ char* envVar = new char[strlen(value)+1];
+ strcpy(envVar, value);
+ putenv(envVar);
+ // save the pointer in the static vector so that it can
+ // be deleted on exit
+ localEnvironment.push_back(envVar);
+}
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 4c5e4252e3..a8bbc8be76 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -256,6 +256,10 @@ public:
static std::string RelativePath(const char* local, const char* remote);
///! split a path by separator into an array of strings, default is /
static std::vector<cmStdString> SplitString(const char* s, char separator = '/');
+ /** put a string into the environment
+ of the form var=value */
+ static bool PutEnv(const char* value);
+
private:
static bool s_ForceUnixPaths;
static bool s_RunCommandHideConsole;
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 50170c68e0..c1c26989d5 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -84,8 +84,7 @@ cmake::cmake()
// encode the MAKEFLAGS variable in a strange way.
if(getenv("MAKEFLAGS"))
{
- static char makeflags[] = "MAKEFLAGS=";
- putenv(makeflags);
+ cmSystemTools::PutEnv("MAKEFLAGS=");
}
m_Local = false;
@@ -876,36 +875,18 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
delete m_GlobalGenerator;
// restore the original environment variables CXX and CC
// Restor CC
- static char envCC[5000];
std::string env = "CC=";
- if(m_CCEnvironment)
+ if(m_CCEnvironment.size())
{
env += m_CCEnvironment;
}
- std::string::size_type size = env.size();
- if(size > 4999)
- {
- size = 4999;
- }
- strncpy(envCC, env.c_str(), size);
- envCC[size] = 0;
- putenv(envCC);
-
- // Restore CXX
- static char envCXX[5000];
+ cmSystemTools::PutEnv(env.c_str());
env = "CXX=";
- if(m_CXXEnvironment)
+ if(m_CXXEnvironment.size())
{
env += m_CXXEnvironment;
}
- size = env.size();
- if(size > 4999)
- {
- size = 4999;
- }
- strncpy(envCXX, env.c_str(), size);
- envCXX[size] = 0;
- putenv(envCXX);
+ cmSystemTools::PutEnv(env.c_str());
}
// set the new
@@ -915,9 +896,24 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
// on windows.
cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
// Save the environment variables CXX and CC
- m_CXXEnvironment = getenv("CXX");
- m_CCEnvironment = getenv("CC");
-
+ const char* cxx = getenv("CXX");
+ const char* cc = getenv("CC");
+ if(cxx)
+ {
+ m_CXXEnvironment = cxx;
+ }
+ else
+ {
+ m_CXXEnvironment = "";
+ }
+ if(cc)
+ {
+ m_CCEnvironment = cc;
+ }
+ else
+ {
+ m_CCEnvironment = "";
+ }
// set the cmake instance just to be sure
gg->SetCMakeInstance(this);
}
diff --git a/Source/cmake.h b/Source/cmake.h
index d818070439..833b45424b 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -298,8 +298,8 @@ private:
bool m_InTryCompile;
bool m_ScriptMode;
std::string m_CMakeCommand;
- const char* m_CXXEnvironment;
- const char* m_CCEnvironment;
+ std::string m_CXXEnvironment;
+ std::string m_CCEnvironment;
bool m_DebugTryCompile;
};