diff options
-rw-r--r-- | Source/cmCacheManager.cxx | 41 | ||||
-rw-r--r-- | Source/cmCacheManager.h | 10 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 26 | ||||
-rw-r--r-- | Source/cmMakefile.h | 4 |
4 files changed, 57 insertions, 24 deletions
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index b1a7921..3eea333 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -320,10 +320,27 @@ bool cmCacheManager::LoadCache(const char* path, ". Offending entry: ", realbuffer); } } - // if CMAKE version not found in the list file - // add them as version 0.0 - if(!this->GetCacheValue("CMAKE_CACHE_MINOR_VERSION")) + this->CacheMajorVersion = 0; + this->CacheMinorVersion = 0; + if(const char* cmajor = this->GetCacheValue("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(sscanf(cminor, "%u", &v) == 1) + { + this->CacheMinorVersion = v; + } + } + } + else + { + // CMake version not found in the list file. + // 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); @@ -950,3 +967,21 @@ bool cmCacheManager::CacheIterator::PropertyExists(const char* property) const } return true; } + +//---------------------------------------------------------------------------- +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. + unsigned int actual_compat = + CMake_VERSION_ENCODE(this->CacheMajorVersion, this->CacheMinorVersion, 0); + return (actual_compat && + actual_compat <= CMake_VERSION_ENCODE(major, minor, 0)); +} diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index 83178b6..4fa6ed0 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -142,6 +142,11 @@ public: ///! Get a value from the cache given a key const char* GetCacheValue(const char* key) const; + /** Get the version of CMake that wrote the cache. */ + unsigned int GetCacheMajorVersion() { return this->CacheMajorVersion; } + unsigned int GetCacheMinorVersion() { return this->CacheMinorVersion; } + bool NeedCacheCompatibility(int major, int minor); + protected: ///! Add an entry into the cache void AddCacheEntry(const char* key, const char* value, @@ -154,7 +159,10 @@ protected: CacheEntry *GetCacheEntry(const char *key); ///! Clean out the CMakeFiles directory if no CMakeCache.txt void CleanCMakeFiles(const char* path); - + + // Cache version info + unsigned int CacheMajorVersion; + unsigned int CacheMinorVersion; private: typedef std::map<cmStdString, CacheEntry> CacheEntryMap; static void OutputHelpString(std::ofstream& fout, diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 151ad5e..d75e9eb 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -145,32 +145,18 @@ void cmMakefile::Initialize() unsigned int cmMakefile::GetCacheMajorVersion() { - if(const char* vstr = - this->GetCacheManager()->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION")) - { - unsigned int v=0; - if(sscanf(vstr, "%u", &v) == 1) - { - return v; - } - } - return 0; + return this->GetCacheManager()->GetCacheMajorVersion(); } unsigned int cmMakefile::GetCacheMinorVersion() { - if(const char* vstr = - this->GetCacheManager()->GetCacheValue("CMAKE_CACHE_MINOR_VERSION")) - { - unsigned int v=0; - if(sscanf(vstr, "%u", &v) == 1) - { - return v; - } - } - return 0; + return this->GetCacheManager()->GetCacheMinorVersion(); } +bool cmMakefile::NeedCacheCompatibility(int major, int minor) +{ + return this->GetCacheManager()->NeedCacheCompatibility(major, minor); +} cmMakefile::~cmMakefile() { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 6bc8067..e511851 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -58,6 +58,10 @@ public: */ unsigned int GetCacheMajorVersion(); unsigned int GetCacheMinorVersion(); + + /** Return whether compatibility features needed for a version of + the cache or lower should be enabled. */ + bool NeedCacheCompatibility(int major, int minor); /** * Construct an empty makefile. |