diff options
author | Ken Martin <ken.martin@kitware.com> | 2007-12-03 18:35:41 (GMT) |
---|---|---|
committer | Ken Martin <ken.martin@kitware.com> | 2007-12-03 18:35:41 (GMT) |
commit | f4b1c3880be819ea1c996e2754cc231285c4a40e (patch) | |
tree | c5c880392b4c16e669a9df6814a0919226a5ab06 | |
parent | 257b775f70b98e2242f01a252e08a55cdac91993 (diff) | |
download | CMake-f4b1c3880be819ea1c996e2754cc231285c4a40e.zip CMake-f4b1c3880be819ea1c996e2754cc231285c4a40e.tar.gz CMake-f4b1c3880be819ea1c996e2754cc231285c4a40e.tar.bz2 |
ENH: add functions and raise scope
-rw-r--r-- | Source/cmBootstrapCommands.cxx | 8 | ||||
-rw-r--r-- | Source/cmCommands.cxx | 2 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 75 | ||||
-rw-r--r-- | Source/cmMakefile.h | 7 | ||||
-rw-r--r-- | Source/cmake.cxx | 3 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 1 |
6 files changed, 75 insertions, 21 deletions
diff --git a/Source/cmBootstrapCommands.cxx b/Source/cmBootstrapCommands.cxx index 143dad0..5075c61 100644 --- a/Source/cmBootstrapCommands.cxx +++ b/Source/cmBootstrapCommands.cxx @@ -36,7 +36,9 @@ #include "cmElseCommand.cxx" #include "cmEnableTestingCommand.cxx" #include "cmEndForEachCommand.cxx" +#include "cmEndFunctionCommand.cxx" #include "cmEndIfCommand.cxx" +#include "cmEndMacroCommand.cxx" #include "cmExecProgramCommand.cxx" #include "cmExternalMakefileProjectGenerator.cxx" #include "cmFindBase.cxx" @@ -47,6 +49,7 @@ #include "cmFindPathCommand.cxx" #include "cmFindProgramCommand.cxx" #include "cmForEachCommand.cxx" +#include "cmFunctionCommand.cxx" #include "cmGetCMakePropertyCommand.cxx" #include "cmGetFilenameComponentCommand.cxx" #include "cmGetSourceFilePropertyCommand.cxx" @@ -66,6 +69,7 @@ #include "cmMessageCommand.cxx" #include "cmOptionCommand.cxx" #include "cmProjectCommand.cxx" +#include "cmRaiseScopeCommand.cxx" #include "cmSetCommand.cxx" #include "cmSetPropertiesCommand.cxx" #include "cmSetSourceFilesPropertiesCommand.cxx" @@ -95,7 +99,9 @@ void GetBootstrapCommands(std::list<cmCommand*>& commands) commands.push_back(new cmElseCommand); commands.push_back(new cmEnableTestingCommand); commands.push_back(new cmEndForEachCommand); + commands.push_back(new cmEndFunctionCommand); commands.push_back(new cmEndIfCommand); + commands.push_back(new cmEndMacroCommand); commands.push_back(new cmExecProgramCommand); commands.push_back(new cmFileCommand); commands.push_back(new cmFindFileCommand); @@ -104,6 +110,7 @@ void GetBootstrapCommands(std::list<cmCommand*>& commands) commands.push_back(new cmFindPathCommand); commands.push_back(new cmFindProgramCommand); commands.push_back(new cmForEachCommand); + commands.push_back(new cmFunctionCommand); commands.push_back(new cmGetCMakePropertyCommand); commands.push_back(new cmGetFilenameComponentCommand); commands.push_back(new cmGetSourceFilePropertyCommand); @@ -122,6 +129,7 @@ void GetBootstrapCommands(std::list<cmCommand*>& commands) commands.push_back(new cmMessageCommand); commands.push_back(new cmOptionCommand); commands.push_back(new cmProjectCommand); + commands.push_back(new cmRaiseScopeCommand); commands.push_back(new cmSetCommand); commands.push_back(new cmSetPropertiesCommand); commands.push_back(new cmSetSourceFilesPropertiesCommand); diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 9f413d1..42b215b 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -21,7 +21,6 @@ #include "cmDefinePropertyCommand.cxx" #include "cmElseIfCommand.cxx" #include "cmEnableLanguageCommand.cxx" -#include "cmEndMacroCommand.cxx" #include "cmEndWhileCommand.cxx" #include "cmExecuteProcessCommand.cxx" #include "cmExportCommand.cxx" @@ -72,7 +71,6 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands.push_back(new cmDefinePropertyCommand); commands.push_back(new cmElseIfCommand); commands.push_back(new cmEnableLanguageCommand); - commands.push_back(new cmEndMacroCommand); commands.push_back(new cmEndWhileCommand); commands.push_back(new cmExecuteProcessCommand); commands.push_back(new cmExportCommand); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 418b70e..0c2ac47 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -42,6 +42,8 @@ // default is not to be building executables cmMakefile::cmMakefile() { + this->DefinitionStack.push_back(DefinitionMap()); + // Setup the default include file regular expression (match everything). this->IncludeFileRegularExpression = "^.*$"; // Setup the default include complaint regular expression (match nothing). @@ -120,7 +122,7 @@ cmMakefile::cmMakefile(const cmMakefile& mf) this->SourceGroups = mf.SourceGroups; #endif - this->Definitions = mf.Definitions; + this->DefinitionStack.push_back(mf.DefinitionStack.back()); this->LocalGenerator = mf.LocalGenerator; this->FunctionBlockers = mf.FunctionBlockers; this->DataMap = mf.DataMap; @@ -1046,7 +1048,7 @@ void cmMakefile::InitializeFromParent() cmMakefile *parent = this->LocalGenerator->GetParent()->GetMakefile(); // copy the definitions - this->Definitions = parent->Definitions; + this->DefinitionStack.front() = parent->DefinitionStack.back(); // copy include paths this->IncludeDirectories = parent->IncludeDirectories; @@ -1225,7 +1227,7 @@ void cmMakefile::AddDefinition(const char* name, const char* value) #endif this->TemporaryDefinitionKey = name; - this->Definitions[this->TemporaryDefinitionKey] = value; + this->DefinitionStack.back()[this->TemporaryDefinitionKey] = value; #ifdef CMAKE_BUILD_WITH_CMAKE cmVariableWatch* vv = this->GetVariableWatch(); @@ -1274,7 +1276,7 @@ void cmMakefile::AddCacheDefinition(const char* name, const char* value, } this->GetCacheManager()->AddCacheEntry(name, val, doc, type); // if there was a definition then remove it - this->Definitions.erase( DefinitionMap::key_type(name)); + this->DefinitionStack.back().erase( DefinitionMap::key_type(name)); } @@ -1282,13 +1284,17 @@ void cmMakefile::AddDefinition(const char* name, bool value) { if(value) { - this->Definitions.erase( DefinitionMap::key_type(name)); - this->Definitions.insert(DefinitionMap::value_type(name, "ON")); + this->DefinitionStack.back() + .erase( DefinitionMap::key_type(name)); + this->DefinitionStack.back() + .insert(DefinitionMap::value_type(name, "ON")); } else { - this->Definitions.erase( DefinitionMap::key_type(name)); - this->Definitions.insert(DefinitionMap::value_type(name, "OFF")); + this->DefinitionStack.back() + .erase( DefinitionMap::key_type(name)); + this->DefinitionStack.back() + .insert(DefinitionMap::value_type(name, "OFF")); } #ifdef CMAKE_BUILD_WITH_CMAKE cmVariableWatch* vv = this->GetVariableWatch(); @@ -1319,7 +1325,7 @@ void cmMakefile::AddCacheDefinition(const char* name, void cmMakefile::RemoveDefinition(const char* name) { - this->Definitions.erase(DefinitionMap::key_type(name)); + this->DefinitionStack.back().erase(DefinitionMap::key_type(name)); #ifdef CMAKE_BUILD_WITH_CMAKE cmVariableWatch* vv = this->GetVariableWatch(); if ( vv ) @@ -1653,8 +1659,9 @@ const char* cmMakefile::GetRequiredDefinition(const char* name) const bool cmMakefile::IsDefinitionSet(const char* name) const { const char* def = 0; - DefinitionMap::const_iterator pos = this->Definitions.find(name); - if(pos != this->Definitions.end()) + DefinitionMap::const_iterator pos = + this->DefinitionStack.back().find(name); + if(pos != this->DefinitionStack.back().end()) { def = (*pos).second.c_str(); } @@ -1686,8 +1693,9 @@ const char* cmMakefile::GetDefinition(const char* name) const } #endif const char* def = 0; - DefinitionMap::const_iterator pos = this->Definitions.find(name); - if(pos != this->Definitions.end()) + DefinitionMap::const_iterator pos = + this->DefinitionStack.back().find(name); + if(pos != this->DefinitionStack.back().end()) { def = (*pos).second.c_str(); } @@ -1708,8 +1716,9 @@ const char* cmMakefile::GetDefinition(const char* name) const { // are unknown access allowed DefinitionMap::const_iterator pos2 = - this->Definitions.find("CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS"); - if (pos2 != this->Definitions.end() && + this->DefinitionStack.back() + .find("CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS"); + if (pos2 != this->DefinitionStack.back().end() && cmSystemTools::IsOn((*pos2).second.c_str())) { vv->VariableAccessed(name, @@ -1743,8 +1752,8 @@ std::vector<std::string> cmMakefile if ( !cacheonly ) { DefinitionMap::const_iterator it; - for ( it = this->Definitions.begin(); - it != this->Definitions.end(); it ++ ) + for ( it = this->DefinitionStack.back().begin(); + it != this->DefinitionStack.back().end(); it ++ ) { definitions[it->first] = 1; } @@ -2822,6 +2831,38 @@ std::string cmMakefile::GetListFileStack() return tmp.str(); } + +void cmMakefile::PushScope() +{ + this->DefinitionStack.push_back(this->DefinitionStack.back()); +} + +void cmMakefile::PopScope() +{ + this->DefinitionStack.pop_back(); +} + +void cmMakefile::RaiseScope(const char *var) +{ + const char *varDef = this->GetDefinition(var); + + // multiple scopes in this directory? + if (this->DefinitionStack.size() > 1) + { + this->DefinitionStack[this->DefinitionStack.size()-2][var] = varDef; + } + // otherwise do the parent + else + { + cmMakefile *parent = this->LocalGenerator->GetParent()->GetMakefile(); + if (parent) + { + parent->AddDefinition(var,varDef); + } + } +} + + // define properties void cmMakefile::DefineProperties(cmake *cm) { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 7915f08..2d4e61f 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -737,6 +737,11 @@ public: // Define the properties static void DefineProperties(cmake *cm); + // push and pop variable scopes + void PushScope(); + void PopScope(); + void RaiseScope(const char *var); + protected: // add link libraries and directories to the target void AddGlobalLinkInformation(const char* name, cmTarget& target); @@ -787,7 +792,7 @@ protected: std::vector<cmSourceGroup> SourceGroups; #endif - DefinitionMap Definitions; + std::vector<DefinitionMap> DefinitionStack; std::vector<cmCommand*> UsedCommands; cmLocalGenerator* LocalGenerator; bool IsFunctionBlocked(const cmListFileFunction& lff); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index f14bb56..82db89e 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -224,7 +224,8 @@ void cmake::CleanupCommandsAndMacros() for(RegisteredCommandsMap::iterator j = this->Commands.begin(); j != this->Commands.end(); ++j) { - if ( !j->second->IsA("cmMacroHelperCommand") ) + if ( !j->second->IsA("cmMacroHelperCommand") && + !j->second->IsA("cmFunctionHelperCommand")) { commands.push_back(j->second); } diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index efe32b7..1d2610e 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -45,6 +45,7 @@ IF(BUILD_TESTING) ADD_TEST_MACRO(LoadCommand LoadedCommand) ADD_TEST_MACRO(LinkLine LinkLine) ADD_TEST_MACRO(MacroTest miniMacroTest) + ADD_TEST_MACRO(FunctionTest miniFunctionTest) ADD_TEST_MACRO(Properties Properties) ADD_TEST_MACRO(Assembler HelloAsm) ADD_TEST_MACRO(SourceGroups SourceGroups) |