diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2001-11-20 22:51:03 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2001-11-20 22:51:03 (GMT) |
commit | f7fae15d39d6e290686487778485734227415088 (patch) | |
tree | 4d9b374c6b9cbee02781bf442ab078cfdd449f87 | |
parent | f3d63c1932f5a9d2b159ccddf9acd09f8c5358c2 (diff) | |
download | CMake-f7fae15d39d6e290686487778485734227415088.zip CMake-f7fae15d39d6e290686487778485734227415088.tar.gz CMake-f7fae15d39d6e290686487778485734227415088.tar.bz2 |
ENH: add command line arguments to set cache entries
-rw-r--r-- | Source/cmCacheManager.cxx | 65 | ||||
-rw-r--r-- | Source/cmCacheManager.h | 6 | ||||
-rw-r--r-- | Source/cmake.cxx | 36 | ||||
-rw-r--r-- | Source/cmake.h | 7 |
4 files changed, 69 insertions, 45 deletions
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index a45ae32..3d6ac98 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -114,6 +114,32 @@ bool cmCacheManager::LoadCache(const char* path, return this->LoadCache(path, internal, emptySet, emptySet); } +bool cmCacheManager::ParseEntry(const char* entry, + std::string& var, + std::string& value, + CacheEntryType& type) +{ + // input line is: key:type=value + cmRegularExpression reg("^([^:]*):([^=]*)=(.*[^\t ]|[\t ]*)[\t ]*$"); + // input line is: "key":type=value + cmRegularExpression regQuoted("^\"([^\"]*)\":([^=]*)=(.*[^\t ]|[\t ]*)[\t ]*$"); + if(regQuoted.find(entry)) + { + var = regQuoted.match(1); + type = cmCacheManager::StringToType(regQuoted.match(2).c_str()); + value = regQuoted.match(3); + return true; + } + else if (reg.find(entry)) + { + var = reg.match(1); + type = cmCacheManager::StringToType(reg.match(2).c_str()); + value = reg.match(3); + return true; + } + return false; +} + bool cmCacheManager::LoadCache(const char* path, bool internal, std::set<std::string>& excludes, @@ -167,12 +193,10 @@ bool cmCacheManager::LoadCache(const char* path, continue; } } - if(regQuoted.find(realbuffer)) + if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.m_Value, e.m_Type)) { - entryKey = regQuoted.match(1); if ( excludes.find(entryKey) == excludes.end() ) { - e.m_Type = cmCacheManager::StringToType(regQuoted.match(2).c_str()); // Load internal values if internal is set. // If the entry is not internal to the cache being loaded // or if it is in the list of internal entries to be @@ -192,43 +216,10 @@ bool cmCacheManager::LoadCache(const char* path, e.m_HelpString += path; e.m_HelpString += "/CMakeCache.txt" ; } - e.m_Value = regQuoted.match(3); m_Cache[entryKey] = e; } } } - else if (reg.find(realbuffer)) - { - entryKey = reg.match(1); - if ( excludes.find(entryKey) == excludes.end() ) - { - e.m_Type = cmCacheManager::StringToType(reg.match(2).c_str()); - // only load internal values if internal is set - // Load internal values if internal is set. - // If the entry is not internal to the cache being loaded - // or if it is in the list of internal entries to be - // imported, load it. - if ( internal || (e.m_Type != INTERNAL) || - (includes.find(entryKey) != includes.end()) ) - { - // If we are loading the cache from another project, - // make all loaded entries internal so that it is - // not visible in the gui - if (!internal) - { - e.m_Type = INTERNAL; - e.m_HelpString = "DO NOT EDIT, "; - e.m_HelpString += entryKey; - e.m_HelpString += " loaded from external file. " - "To change this value edit this file: "; - e.m_HelpString += path; - e.m_HelpString += "/CMakeCache.txt"; - } - e.m_Value = reg.match(3); - m_Cache[entryKey] = e; - } - } - } else { cmSystemTools::Error("Parse error in cache file ", cacheFile.c_str(), @@ -247,6 +238,8 @@ bool cmCacheManager::LoadCache(const char* path, "current loaded cache", cmCacheManager::INTERNAL); } + // check to make sure the cache directory has not + // been moved if ( internal && this->GetCacheValue("CMAKE_CACHEFILE_DIR") ) { std::string currentcwd = path; diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index 59e776c..154b0ae 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -102,6 +102,12 @@ public: ///! Remove an entry from the cache void RemoveCacheEntry(const char* key); + ///! Break up a line like VAR:type="value" into var, type and value + static bool ParseEntry(const char* entry, + std::string& var, + std::string& value, + CacheEntryType& type); + protected: ///! Add an entry into the cache void AddCacheEntry(const char* key, const char* value, diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 30fde30..946cf16 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -80,6 +80,35 @@ void cmake::Usage(const char* program) } // Parse the args +void cmake::SetCacheArgs(cmMakefile& builder, const std::vector<std::string>& args) +{ + for(unsigned int i=1; i < args.size(); ++i) + { + std::string arg = args[i]; + if(arg.find("-D",0) == 0) + { + std::string entry = arg.substr(2); + std::string var, value; + cmCacheManager::CacheEntryType type; + if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type)) + { + cmCacheManager::GetInstance()->AddCacheEntry( + var.c_str(), + cmSystemTools::EscapeSpaces(value.c_str()).c_str(), + "No help, variable specified on the command line.", + type); + std::cerr << "parse entry " << var.c_str()<< " " << value.c_str() << "\n"; + } + else + { + std::cerr << "Parse error in command line argument: " << arg << "\n" + << "Should be: VAR:type=value\n"; + } + } + } +} + +// Parse the args void cmake::SetArgs(cmMakefile& builder, const std::vector<std::string>& args) { m_Local = false; @@ -136,11 +165,6 @@ void cmake::SetArgs(cmMakefile& builder, const std::vector<std::string>& args) std::string path = arg.substr(2); builder.SetHomeOutputDirectory(path.c_str()); } - else if(arg.find("-D",0) == 0) - { - std::string value = arg.substr(2); - builder.AddDefinition(value.c_str(), true); - } else if(arg.find("-V",0) == 0) { m_Verbose = true; @@ -315,6 +339,8 @@ int cmake::Generate(const std::vector<std::string>& args, bool buildMakefiles) // Read and parse the input makefile mf.MakeStartDirectoriesCurrent(); cmCacheManager::GetInstance()->LoadCache(&mf); + // extract command line arguments that might add cache entries + this->SetCacheArgs(mf, args); // no generator specified on the command line if(!mf.GetMakefileGenerator()) { diff --git a/Source/cmake.h b/Source/cmake.h index ff9d11f..4502d32 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -65,11 +65,10 @@ class cmake */ int Generate(const std::vector<std::string>&, bool buildMakefiles = true); - /** - * Generate the SourceFilesList from the SourceLists. This should only be - * done once to be safe. - */ + ///! Parse command line arguments void SetArgs(cmMakefile& builder, const std::vector<std::string>&); + ///! Parse command line arguments that might set cache values + void SetCacheArgs(cmMakefile& builder, const std::vector<std::string>&); /** * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries |