From 8cdb87eaa75803d379f3645fa03df046e87e9497 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Thu, 9 Mar 2006 15:47:18 -0500 Subject: [PATCH] ENH: if CMakeCache.txt has been removed, then automatically remove CMakefiles/*.cmake --- Source/cmCacheManager.cxx | 21 +++++++++++++++++++++ Source/cmCacheManager.h | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 055e9f174..6be0c3570 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -19,6 +19,7 @@ #include "cmSystemTools.h" #include "cmCacheManager.h" #include "cmMakefile.h" +#include "cmGlob.h" #include #include @@ -154,6 +155,20 @@ bool cmCacheManager::ParseEntry(const char* entry, return flag; } +void cmCacheManager::CleanCMakeFiles(const char* path) +{ + std::string glob = path; + glob += "/CMakeFiles/*.cmake"; + cmGlob globIt; + globIt.FindFiles(glob); + std::vector files = globIt.GetFiles(); + for(std::vector::iterator i = files.begin(); + i != files.end(); ++i) + { + cmSystemTools::RemoveFile(i->c_str()); + } +} + bool cmCacheManager::LoadCache(const char* path, bool internal, std::set& excludes, @@ -166,6 +181,12 @@ bool cmCacheManager::LoadCache(const char* path, { m_Cache.clear(); } + if(!cmSystemTools::FileExists(cacheFile.c_str())) + { + this->CleanCMakeFiles(path); + return false; + } + std::ifstream fin(cacheFile.c_str()); if(!fin) { diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index 451dcea79..a6773b5f5 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -150,7 +150,9 @@ protected: ///! Get a cache entry object for a key CacheEntry *GetCacheEntry(const char *key); - + ///! Clean out the CMakeFiles directory if no CMakeCache.txt + void CleanCMakeFiles(const char* path); + private: typedef std::map CacheEntryMap; static void OutputHelpString(std::ofstream& fout,