summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Barre <sebastien.barre@kitware.com>2001-08-18 16:52:19 (GMT)
committerSebastien Barre <sebastien.barre@kitware.com>2001-08-18 16:52:19 (GMT)
commitce4f2718f2e56aec5ff39a70354da3368fd2dc49 (patch)
tree4f073d64b7917f40f7037d14b864e1366dd59da8
parentc151f30861d83e8f0f1d3823fc14c7952c3c6555 (diff)
downloadCMake-ce4f2718f2e56aec5ff39a70354da3368fd2dc49.zip
CMake-ce4f2718f2e56aec5ff39a70354da3368fd2dc49.tar.gz
CMake-ce4f2718f2e56aec5ff39a70354da3368fd2dc49.tar.bz2
Support for $ENV{VAR} syntax (lookup in the environment vars)
-rw-r--r--Modules/FindDart.cmake1
-rw-r--r--Source/cmMakefile.cxx64
2 files changed, 52 insertions, 13 deletions
diff --git a/Modules/FindDart.cmake b/Modules/FindDart.cmake
index 2e40d68..5895492 100644
--- a/Modules/FindDart.cmake
+++ b/Modules/FindDart.cmake
@@ -4,6 +4,7 @@
#
FIND_PATH(DART_ROOT README.INSTALL
+ $ENV{DART_ROOT}
${PROJECT_SOURCE_DIR}/Dart
/usr/share/Dart
"C:/Program Files/Dart"
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 9a482bd..8cddaf5 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -837,6 +837,8 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
{
// This method replaces ${VAR} and @VAR@ where VAR is looked up
// in the m_Definitions map, if not found in the map, nothing is expanded.
+ // It also supports the $ENV{VAR} syntax where VAR is looked up in
+ // the current environment variables.
// start by look for $ or @ in the string
std::string::size_type markerPos = source.find_first_of("$@");
@@ -856,7 +858,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
// and add it to the result
result += source.substr(currentPos, markerPos - currentPos);
char endVariableMarker; // what is the end of the variable @ or }
- int markerStartSize = 1; // size of the start marker 1 or 2
+ int markerStartSize = 1; // size of the start marker 1 or 2 or 5
if(source[markerPos] == '$')
{
// ${var} case
@@ -865,6 +867,14 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
endVariableMarker = '}';
markerStartSize = 2;
}
+ // $ENV{var} case
+ else if(markerPos+4 < source.size() &&
+ source[markerPos+4] == '{' &&
+ !source.compare(markerPos+1, 3, "ENV"))
+ {
+ endVariableMarker = '}';
+ markerStartSize = 5;
+ }
else
{
// bogus $ with no { so add $ to result and move on
@@ -878,7 +888,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
// @VAR case
endVariableMarker = '@';
}
- // if it was a valid variable (started with @ or ${ )
+ // if it was a valid variable (started with @ or ${ or $ENV{ )
if(endVariableMarker != ' ')
{
markerPos += markerStartSize; // move past marker
@@ -894,7 +904,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
}
else
{
- result += "${";
+ result += (markerStartSize == 5 ? "$ENV{" : "${");
}
currentPos = markerPos;
}
@@ -902,20 +912,41 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
{
// good variable remove it
std::string var = source.substr(markerPos, endVariablePos - markerPos);
- DefinitionMap::const_iterator pos = m_Definitions.find(var.c_str());
- // if found add to result, if not, then it gets blanked
- if(pos != m_Definitions.end())
+ bool found = false;
+ if (markerStartSize == 5) // $ENV{
{
- if (escapeQuotes)
+ char *ptr = getenv(var.c_str());
+ if (ptr)
{
- result += cmSystemTools::EscapeQuotes((*pos).second.c_str());
+ if (escapeQuotes)
+ {
+ result += cmSystemTools::EscapeQuotes(ptr);
+ }
+ else
+ {
+ result += ptr;
+ }
+ found = true;
}
- else
+ }
+ else
+ {
+ DefinitionMap::const_iterator pos = m_Definitions.find(var.c_str());
+ if(pos != m_Definitions.end())
{
- result += (*pos).second;
+ if (escapeQuotes)
+ {
+ result += cmSystemTools::EscapeQuotes((*pos).second.c_str());
+ }
+ else
+ {
+ result += (*pos).second;
+ }
+ found = true;
}
}
- else
+ // if found add to result, if not, then it gets blanked
+ if (!found)
{
// if no definition is found then add the var back
if(endVariableMarker == '@')
@@ -926,7 +957,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
}
else
{
- result += "${";
+ result += (markerStartSize == 5 ? "$ENV{" : "${");
result += var;
result += "}";
}
@@ -944,11 +975,18 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
void cmMakefile::RemoveVariablesInString(std::string& source) const
{
cmRegularExpression var("(\\${[A-Za-z_0-9]*})");
- cmRegularExpression var2("(@[A-Za-z_0-9]*@)");
while (var.find(source))
{
source.erase(var.start(),var.end() - var.start());
}
+
+ cmRegularExpression varb("(\\$ENV{[A-Za-z_0-9]*})");
+ while (varb.find(source))
+ {
+ source.erase(varb.start(),varb.end() - varb.start());
+ }
+
+ cmRegularExpression var2("(@[A-Za-z_0-9]*@)");
while (var2.find(source))
{
source.erase(var2.start(),var2.end() - var2.start());