summaryrefslogtreecommitdiffstats
path: root/Source/cmCacheManager.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmCacheManager.cxx')
-rw-r--r--Source/cmCacheManager.cxx179
1 files changed, 43 insertions, 136 deletions
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
index 45e92ce..54209c5 100644
--- a/Source/cmCacheManager.cxx
+++ b/Source/cmCacheManager.cxx
@@ -12,7 +12,6 @@
#include "cmCacheManager.h"
#include "cmSystemTools.h"
-#include "cmCacheManager.h"
#include "cmGeneratedFileStream.h"
#include "cmMakefile.h"
#include "cmake.h"
@@ -23,17 +22,6 @@
#include <cmsys/FStream.hxx>
#include <cmsys/RegularExpression.hxx>
-const char* cmCacheManagerTypes[] =
-{ "BOOL",
- "PATH",
- "FILEPATH",
- "STRING",
- "INTERNAL",
- "STATIC",
- "UNINITIALIZED",
- 0
-};
-
cmCacheManager::cmCacheManager(cmake* cm)
{
this->CacheMajorVersion = 0;
@@ -41,57 +29,10 @@ cmCacheManager::cmCacheManager(cmake* cm)
this->CMakeInstance = cm;
}
-const char* cmCacheManager::TypeToString(cmCacheManager::CacheEntryType type)
-{
- if ( type > 6 )
- {
- return cmCacheManagerTypes[6];
- }
- return cmCacheManagerTypes[type];
-}
-
-cmCacheManager::CacheEntryType cmCacheManager::StringToType(const char* s)
-{
- int i = 0;
- while(cmCacheManagerTypes[i])
- {
- if(strcmp(s, cmCacheManagerTypes[i]) == 0)
- {
- return static_cast<CacheEntryType>(i);
- }
- ++i;
- }
- return STRING;
-}
-
-bool cmCacheManager::IsType(const char* s)
-{
- for(int i=0; cmCacheManagerTypes[i]; ++i)
- {
- if(strcmp(s, cmCacheManagerTypes[i]) == 0)
- {
- return true;
- }
- }
- return false;
-}
-
-bool cmCacheManager::LoadCache(cmMakefile* mf)
-{
- return this->LoadCache(mf->GetHomeOutputDirectory());
-}
-
-
bool cmCacheManager::LoadCache(const std::string& path)
{
- return this->LoadCache(path,true);
-}
-
-bool cmCacheManager::LoadCache(const std::string& path,
- bool internal)
-{
std::set<std::string> emptySet;
- return this->LoadCache(path, internal, emptySet, emptySet);
+ return this->LoadCache(path, true, emptySet, emptySet);
}
static bool ParseEntryWithoutType(const std::string& entry,
@@ -135,7 +76,7 @@ static bool ParseEntryWithoutType(const std::string& entry,
bool cmCacheManager::ParseEntry(const std::string& entry,
std::string& var,
std::string& value,
- CacheEntryType& type)
+ cmState::CacheEntryType& type)
{
// input line is: key:type=value
static cmsys::RegularExpression reg(
@@ -147,14 +88,14 @@ bool cmCacheManager::ParseEntry(const std::string& entry,
if(regQuoted.find(entry))
{
var = regQuoted.match(1);
- type = cmCacheManager::StringToType(regQuoted.match(2).c_str());
+ type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str());
value = regQuoted.match(3);
flag = true;
}
else if (reg.find(entry))
{
var = reg.match(1);
- type = cmCacheManager::StringToType(reg.match(2).c_str());
+ type = cmState::StringToCacheEntryType(reg.match(2).c_str());
value = reg.match(3);
flag = true;
}
@@ -186,11 +127,7 @@ void cmCacheManager::CleanCMakeFiles(const std::string& path)
cmsys::Glob globIt;
globIt.FindFiles(glob);
std::vector<std::string> files = globIt.GetFiles();
- for(std::vector<std::string>::iterator i = files.begin();
- i != files.end(); ++i)
- {
- cmSystemTools::RemoveFile(*i);
- }
+ std::for_each(files.begin(), files.end(), cmSystemTools::RemoveFile);
}
bool cmCacheManager::LoadCache(const std::string& path,
@@ -224,7 +161,6 @@ bool cmCacheManager::LoadCache(const std::string& path,
// Format is key:type=value
std::string helpString;
CacheEntry e;
- e.Properties.SetCMakeInstance(this->CMakeInstance);
cmSystemTools::GetLineFromStream(fin, buffer);
realbuffer = buffer.c_str();
while(*realbuffer != '0' &&
@@ -267,7 +203,7 @@ bool cmCacheManager::LoadCache(const std::string& path,
// 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.Type != INTERNAL) ||
+ if ( internal || (e.Type != cmState::INTERNAL) ||
(includes.find(entryKey) != includes.end()) )
{
// If we are loading the cache from another project,
@@ -275,7 +211,7 @@ bool cmCacheManager::LoadCache(const std::string& path,
// not visible in the gui
if (!internal)
{
- e.Type = INTERNAL;
+ e.Type = cmState::INTERNAL;
helpString = "DO NOT EDIT, ";
helpString += entryKey;
helpString += " loaded from external file. "
@@ -300,14 +236,16 @@ bool cmCacheManager::LoadCache(const std::string& path,
}
this->CacheMajorVersion = 0;
this->CacheMinorVersion = 0;
- if(const char* cmajor = this->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION"))
+ if(const char* cmajor =
+ this->GetInitializedCacheValue("CMAKE_CACHE_MAJOR_VERSION"))
{
unsigned int v=0;
if(sscanf(cmajor, "%u", &v) == 1)
{
this->CacheMajorVersion = v;
}
- if(const char* cminor = this->GetCacheValue("CMAKE_CACHE_MINOR_VERSION"))
+ if(const char* cminor =
+ this->GetInitializedCacheValue("CMAKE_CACHE_MINOR_VERSION"))
{
if(sscanf(cminor, "%u", &v) == 1)
{
@@ -321,18 +259,19 @@ bool cmCacheManager::LoadCache(const std::string& path,
// Set as version 0.0
this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", "0",
"Minor version of cmake used to create the "
- "current loaded cache", cmCacheManager::INTERNAL);
+ "current loaded cache", cmState::INTERNAL);
this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", "0",
"Major version of cmake used to create the "
- "current loaded cache", cmCacheManager::INTERNAL);
+ "current loaded cache", cmState::INTERNAL);
}
// check to make sure the cache directory has not
// been moved
- if ( internal && this->GetCacheValue("CMAKE_CACHEFILE_DIR") )
+ const char* oldDir = this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR");
+ if (internal && oldDir)
{
std::string currentcwd = path;
- std::string oldcwd = this->GetCacheValue("CMAKE_CACHEFILE_DIR");
+ std::string oldcwd = oldDir;
cmSystemTools::ConvertToUnixSlashes(currentcwd);
currentcwd += "/CMakeCache.txt";
oldcwd += "/CMakeCache.txt";
@@ -341,7 +280,7 @@ bool cmCacheManager::LoadCache(const std::string& path,
std::string message =
std::string("The current CMakeCache.txt directory ") +
currentcwd + std::string(" is different than the directory ") +
- std::string(this->GetCacheValue("CMAKE_CACHEFILE_DIR")) +
+ std::string(this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR")) +
std::string(" where CMakeCache.txt was created. This may result "
"in binaries being created in the wrong place. If you "
"are not sure, reedit the CMakeCache.txt");
@@ -365,7 +304,7 @@ bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey,
CacheEntry& e)
{
// All property entries are internal.
- if(e.Type != cmCacheManager::INTERNAL)
+ if(e.Type != cmState::INTERNAL)
{
return false;
}
@@ -383,8 +322,7 @@ bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey,
{
// Create an entry and store the property.
CacheEntry& ne = this->Cache[key];
- ne.Properties.SetCMakeInstance(this->CMakeInstance);
- ne.Type = cmCacheManager::UNINITIALIZED;
+ ne.Type = cmState::UNINITIALIZED;
ne.SetProperty(*p, e.Value.c_str());
}
else
@@ -422,12 +360,6 @@ void cmCacheManager::WritePropertyEntries(std::ostream& os,
}
}
-bool cmCacheManager::SaveCache(cmMakefile* mf)
-{
- return this->SaveCache(mf->GetHomeOutputDirectory());
-}
-
-
bool cmCacheManager::SaveCache(const std::string& path)
{
std::string cacheFile = path;
@@ -447,15 +379,15 @@ bool cmCacheManager::SaveCache(const std::string& path)
sprintf(temp, "%d", cmVersion::GetMinorVersion());
this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", temp,
"Minor version of cmake used to create the "
- "current loaded cache", cmCacheManager::INTERNAL);
+ "current loaded cache", cmState::INTERNAL);
sprintf(temp, "%d", cmVersion::GetMajorVersion());
this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", temp,
"Major version of cmake used to create the "
- "current loaded cache", cmCacheManager::INTERNAL);
+ "current loaded cache", cmState::INTERNAL);
sprintf(temp, "%d", cmVersion::GetPatchVersion());
this->AddCacheEntry("CMAKE_CACHE_PATCH_VERSION", temp,
"Patch version of cmake used to create the "
- "current loaded cache", cmCacheManager::INTERNAL);
+ "current loaded cache", cmState::INTERNAL);
// Let us store the current working directory so that if somebody
// Copies it, he will not be surprised
@@ -470,17 +402,12 @@ bool cmCacheManager::SaveCache(const std::string& path)
cmSystemTools::ConvertToUnixSlashes(currentcwd);
this->AddCacheEntry("CMAKE_CACHEFILE_DIR", currentcwd.c_str(),
"This is the directory where this CMakeCache.txt"
- " was created", cmCacheManager::INTERNAL);
+ " was created", cmState::INTERNAL);
fout << "# This is the CMakeCache file.\n"
- << "# For build in directory: " << currentcwd << "\n";
- cmCacheManager::CacheEntry* cmakeCacheEntry
- = this->GetCacheEntry("CMAKE_COMMAND");
- if ( cmakeCacheEntry )
- {
- fout << "# It was generated by CMake: " <<
- cmakeCacheEntry->Value << std::endl;
- }
+ << "# For build in directory: " << currentcwd << "\n"
+ << "# It was generated by CMake: "
+ << cmSystemTools::GetCMakeCommand() << std::endl;
fout << "# You can edit this file to change values found and used by cmake."
<< std::endl
@@ -504,7 +431,7 @@ bool cmCacheManager::SaveCache(const std::string& path)
this->Cache.begin(); i != this->Cache.end(); ++i)
{
const CacheEntry& ce = (*i).second;
- CacheEntryType t = ce.Type;
+ cmState::CacheEntryType t = ce.Type;
if(!ce.Initialized)
{
/*
@@ -513,7 +440,7 @@ bool cmCacheManager::SaveCache(const std::string& path)
"\" is uninitialized");
*/
}
- else if(t != INTERNAL)
+ else if(t != cmState::INTERNAL)
{
// Format is key:type=value
if(const char* help = ce.GetProperty("HELPSTRING"))
@@ -525,7 +452,7 @@ bool cmCacheManager::SaveCache(const std::string& path)
cmCacheManager::OutputHelpString(fout, "Missing description");
}
this->OutputKey(fout, i->first);
- fout << ":" << cmCacheManagerTypes[t] << "=";
+ fout << ":" << cmState::CacheEntryTypeToString(t) << "=";
this->OutputValue(fout, ce.Value);
fout << "\n\n";
}
@@ -545,9 +472,9 @@ bool cmCacheManager::SaveCache(const std::string& path)
continue;
}
- CacheEntryType t = i.GetType();
+ cmState::CacheEntryType t = i.GetType();
this->WritePropertyEntries(fout, i);
- if(t == cmCacheManager::INTERNAL)
+ if(t == cmState::INTERNAL)
{
// Format is key:type=value
if(const char* help = i.GetProperty("HELPSTRING"))
@@ -555,7 +482,7 @@ bool cmCacheManager::SaveCache(const std::string& path)
this->OutputHelpString(fout, help);
}
this->OutputKey(fout, i.GetName());
- fout << ":" << cmCacheManagerTypes[t] << "=";
+ fout << ":" << cmState::CacheEntryTypeToString(t) << "=";
this->OutputValue(fout, i.GetValue());
fout << "\n";
}
@@ -677,7 +604,8 @@ cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(
return CacheIterator(*this, key);
}
-const char* cmCacheManager::GetCacheValue(const std::string& key) const
+const char*
+cmCacheManager::GetInitializedCacheValue(const std::string& key) const
{
CacheEntryMap::const_iterator i = this->Cache.find(key);
if(i != this->Cache.end() &&
@@ -696,7 +624,7 @@ void cmCacheManager::PrintCache(std::ostream& out) const
for(std::map<std::string, CacheEntry>::const_iterator i =
this->Cache.begin(); i != this->Cache.end(); ++i)
{
- if((*i).second.Type != INTERNAL)
+ if((*i).second.Type != cmState::INTERNAL)
{
out << (*i).first << " = " << (*i).second.Value
<< std::endl;
@@ -712,10 +640,9 @@ void cmCacheManager::PrintCache(std::ostream& out) const
void cmCacheManager::AddCacheEntry(const std::string& key,
const char* value,
const char* helpString,
- CacheEntryType type)
+ cmState::CacheEntryType type)
{
CacheEntry& e = this->Cache[key];
- e.Properties.SetCMakeInstance(this->CMakeInstance);
if ( value )
{
e.Value = value;
@@ -727,7 +654,7 @@ void cmCacheManager::AddCacheEntry(const std::string& key,
}
e.Type = type;
// make sure we only use unix style paths
- if(type == FILEPATH || type == PATH)
+ if(type == cmState::FILEPATH || type == cmState::PATH)
{
if(e.Value.find(';') != e.Value.npos)
{
@@ -808,15 +735,13 @@ cmCacheManager::CacheEntry::GetProperty(const std::string& prop) const
{
if(prop == "TYPE")
{
- return cmCacheManagerTypes[this->Type];
+ return cmState::CacheEntryTypeToString(this->Type);
}
else if(prop == "VALUE")
{
return this->Value.c_str();
}
- bool c = false;
- return
- this->Properties.GetPropertyValue(prop, cmProperty::CACHE, c);
+ return this->Properties.GetPropertyValue(prop);
}
//----------------------------------------------------------------------------
@@ -825,7 +750,7 @@ void cmCacheManager::CacheEntry::SetProperty(const std::string& prop,
{
if(prop == "TYPE")
{
- this->Type = cmCacheManager::StringToType(value? value : "STRING");
+ this->Type = cmState::StringToCacheEntryType(value? value : "STRING");
}
else if(prop == "VALUE")
{
@@ -833,7 +758,7 @@ void cmCacheManager::CacheEntry::SetProperty(const std::string& prop,
}
else
{
- this->Properties.SetProperty(prop, value, cmProperty::CACHE);
+ this->Properties.SetProperty(prop, value);
}
}
@@ -844,7 +769,7 @@ void cmCacheManager::CacheEntry::AppendProperty(const std::string& prop,
{
if(prop == "TYPE")
{
- this->Type = cmCacheManager::StringToType(value? value : "STRING");
+ this->Type = cmState::StringToCacheEntryType(value? value : "STRING");
}
else if(prop == "VALUE")
{
@@ -859,7 +784,7 @@ void cmCacheManager::CacheEntry::AppendProperty(const std::string& prop,
}
else
{
- this->Properties.AppendProperty(prop, value, cmProperty::CACHE, asString);
+ this->Properties.AppendProperty(prop, value, asString);
}
}
@@ -918,21 +843,3 @@ bool cmCacheManager::CacheIterator::PropertyExists(
{
return this->GetProperty(prop)? true:false;
}
-
-//----------------------------------------------------------------------------
-bool cmCacheManager::NeedCacheCompatibility(int major, int minor)
-{
- // Compatibility is not needed if the cache version is zero because
- // the cache was created or modified by the user.
- if(this->CacheMajorVersion == 0)
- {
- return false;
- }
-
- // Compatibility is needed if the cache version is equal to or lower
- // than the given version.
- cmIML_INT_uint64_t actual_compat =
- CMake_VERSION_ENCODE(this->CacheMajorVersion, this->CacheMinorVersion, 0);
- return (actual_compat &&
- actual_compat <= CMake_VERSION_ENCODE(major, minor, 0));
-}