From 3d8c299f3ea024a309b05e0f21c7f002f43a5742 Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 14:53:24 +0200
Subject: cmake: Use existing cache API wrapper.

---
 Source/cmake.cxx | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index fececfd..431ef0e 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -232,7 +232,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
             }
           }
 
-        this->State->AddCacheEntry(var, value.c_str(),
+        this->AddCacheEntry(var, value.c_str(),
           "No help, variable specified on the command line.", type);
 
         if(this->WarnUnusedCli)
@@ -848,14 +848,14 @@ void cmake::SetDirectoriesFromFile(const char* arg)
 int cmake::AddCMakePaths()
 {
   // Save the value in the cache
-  this->CacheManager->AddCacheEntry
+  this->AddCacheEntry
     ("CMAKE_COMMAND", cmSystemTools::GetCMakeCommand().c_str(),
      "Path to CMake executable.", cmState::INTERNAL);
 #ifdef CMAKE_BUILD_WITH_CMAKE
-  this->CacheManager->AddCacheEntry
+  this->AddCacheEntry
     ("CMAKE_CTEST_COMMAND", cmSystemTools::GetCTestCommand().c_str(),
      "Path to ctest program executable.", cmState::INTERNAL);
-  this->CacheManager->AddCacheEntry
+  this->AddCacheEntry
     ("CMAKE_CPACK_COMMAND", cmSystemTools::GetCPackCommand().c_str(),
      "Path to cpack program executable.", cmState::INTERNAL);
 #endif
@@ -869,7 +869,7 @@ int cmake::AddCMakePaths()
       cmSystemTools::GetCMakeRoot().c_str());
     return 0;
     }
-  this->CacheManager->AddCacheEntry
+  this->AddCacheEntry
     ("CMAKE_ROOT", cmSystemTools::GetCMakeRoot().c_str(),
      "Path to CMake installation.", cmState::INTERNAL);
 
@@ -1186,7 +1186,7 @@ int cmake::Configure()
     {
     if(this->SuppressDevWarnings)
       {
-      this->CacheManager->
+      this->
         AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE",
                       "Suppress Warnings that are meant for"
                       " the author of the CMakeLists.txt files.",
@@ -1194,7 +1194,7 @@ int cmake::Configure()
       }
     else
       {
-      this->CacheManager->
+      this->
         AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE",
                       "Suppress Warnings that are meant for"
                       " the author of the CMakeLists.txt files.",
@@ -1229,7 +1229,7 @@ int cmake::ActualConfigure()
     }
   if ( !res )
     {
-    this->CacheManager->AddCacheEntry
+    this->AddCacheEntry
       ("CMAKE_HOME_DIRECTORY",
        this->GetHomeDirectory(),
        "Source directory with the top level CMakeLists.txt file for this "
@@ -1340,11 +1340,11 @@ int cmake::ActualConfigure()
     }
   if(!this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR"))
     {
-    this->CacheManager->AddCacheEntry("CMAKE_GENERATOR",
+    this->AddCacheEntry("CMAKE_GENERATOR",
                                       this->GlobalGenerator->GetName().c_str(),
                                       "Name of generator.",
                                       cmState::INTERNAL);
-    this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
+    this->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
                         this->GlobalGenerator->GetExtraGeneratorName().c_str(),
                         "Name of external makefile project generator.",
                         cmState::INTERNAL);
@@ -1372,7 +1372,7 @@ int cmake::ActualConfigure()
     }
   else
     {
-    this->CacheManager->AddCacheEntry("CMAKE_GENERATOR_PLATFORM",
+    this->AddCacheEntry("CMAKE_GENERATOR_PLATFORM",
                                       this->GeneratorPlatform.c_str(),
                                       "Name of generator platform.",
                                       cmState::INTERNAL);
@@ -1400,7 +1400,7 @@ int cmake::ActualConfigure()
     }
   else
     {
-    this->CacheManager->AddCacheEntry("CMAKE_GENERATOR_TOOLSET",
+    this->AddCacheEntry("CMAKE_GENERATOR_TOOLSET",
                                       this->GeneratorToolset.c_str(),
                                       "Name of generator toolset.",
                                       cmState::INTERNAL);
@@ -1434,7 +1434,7 @@ int cmake::ActualConfigure()
     {
     if(!this->State->GetInitializedCacheValue("LIBRARY_OUTPUT_PATH"))
       {
-      this->State->AddCacheEntry
+      this->AddCacheEntry
         ("LIBRARY_OUTPUT_PATH", "",
          "Single output directory for building all libraries.",
          cmState::PATH);
@@ -1442,7 +1442,7 @@ int cmake::ActualConfigure()
     if(!this->State
             ->GetInitializedCacheValue("EXECUTABLE_OUTPUT_PATH"))
       {
-      this->State->AddCacheEntry
+      this->AddCacheEntry
         ("EXECUTABLE_OUTPUT_PATH", "",
          "Single output directory for building all executables.",
          cmState::PATH);
-- 
cgit v0.12


From 2afadb0d5ad21fbbcff961562ec441eb4ac001ab Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 14:42:36 +0200
Subject: cmake: Port away from trivial cmCacheManager use.

---
 Source/cmake.cxx | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 431ef0e..8016e41 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -1086,10 +1086,10 @@ int cmake::DoPreConfigureChecks()
     }
 
   // do a sanity check on some values
-  if(this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"))
+  if(this->State->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY"))
     {
     std::string cacheStart =
-      this->CacheManager->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY");
+      this->State->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY");
     cacheStart += "/CMakeLists.txt";
     std::string currentStart = this->GetHomeDirectory();
     currentStart += "/CMakeLists.txt";
@@ -1146,12 +1146,12 @@ int cmake::HandleDeleteCacheVariables(const std::string& var)
     save.value = *i;
     warning << *i << "\n";
     const char* existingValue =
-        this->CacheManager->GetCacheEntryValue(save.key);
+        this->State->GetCacheEntryValue(save.key);
     if(existingValue)
       {
-      save.type = this->CacheManager->GetCacheEntryType(save.key);
+      save.type = this->State->GetCacheEntryType(save.key);
       if(const char* help =
-            this->CacheManager->GetCacheEntryProperty(save.key, "HELPSTRING"))
+            this->State->GetCacheEntryProperty(save.key, "HELPSTRING"))
         {
         save.help = help;
         }
@@ -1160,7 +1160,7 @@ int cmake::HandleDeleteCacheVariables(const std::string& var)
     }
 
   // remove the cache
-  this->CacheManager->DeleteCache(this->GetHomeOutputDirectory());
+  this->DeleteCache(this->GetHomeOutputDirectory());
   // load the empty cache
   this->LoadCache();
   // restore the changed compilers
@@ -1241,9 +1241,9 @@ int cmake::ActualConfigure()
   if(!this->GlobalGenerator)
     {
     const char* genName =
-      this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR");
+      this->State->GetInitializedCacheValue("CMAKE_GENERATOR");
     const char* extraGenName =
-      this->CacheManager->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
+      this->State->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
     if(genName)
       {
       std::string fullName = cmExternalMakefileProjectGenerator::
@@ -1321,7 +1321,7 @@ int cmake::ActualConfigure()
       }
     }
 
-  const char* genName = this->CacheManager
+  const char* genName = this->State
                             ->GetInitializedCacheValue("CMAKE_GENERATOR");
   if(genName)
     {
@@ -1338,7 +1338,7 @@ int cmake::ActualConfigure()
       return -2;
       }
     }
-  if(!this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR"))
+  if(!this->State->GetInitializedCacheValue("CMAKE_GENERATOR"))
     {
     this->AddCacheEntry("CMAKE_GENERATOR",
                                       this->GlobalGenerator->GetName().c_str(),
@@ -1351,7 +1351,7 @@ int cmake::ActualConfigure()
     }
 
   if(const char* platformName =
-     this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM"))
+     this->State->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM"))
     {
     if(this->GeneratorPlatform.empty())
       {
@@ -1379,7 +1379,7 @@ int cmake::ActualConfigure()
     }
 
   if(const char* tsName =
-     this->CacheManager->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET"))
+     this->State->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET"))
     {
     if(this->GeneratorToolset.empty())
       {
@@ -1462,7 +1462,7 @@ int cmake::ActualConfigure()
   // only save the cache if there were no fatal errors
   if ( this->GetWorkingMode() == NORMAL_MODE )
     {
-    this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
+    this->SaveCache(this->GetHomeOutputDirectory());
     }
   if(cmSystemTools::GetErrorOccuredFlag())
     {
@@ -1632,7 +1632,7 @@ int cmake::Generate()
   // for the Visual Studio and Xcode generators.)
   if ( this->GetWorkingMode() == NORMAL_MODE )
     {
-    this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
+    this->SaveCache(this->GetHomeOutputDirectory());
     }
   return 0;
 }
@@ -1641,14 +1641,14 @@ void cmake::AddCacheEntry(const std::string& key, const char* value,
                           const char* helpString,
                           int type)
 {
-  this->CacheManager->AddCacheEntry(key, value,
+  this->State->AddCacheEntry(key, value,
                                     helpString,
                                     cmState::CacheEntryType(type));
 }
 
 const char* cmake::GetCacheDefinition(const std::string& name) const
 {
-  return this->CacheManager->GetInitializedCacheValue(name);
+  return this->State->GetInitializedCacheValue(name);
 }
 
 void cmake::AddDefaultCommands()
@@ -1834,7 +1834,7 @@ void cmake::UpdateConversionPathTable()
 {
   // Update the path conversion table with any specified file:
   const char* tablepath =
-    this->CacheManager
+    this->State
         ->GetInitializedCacheValue("CMAKE_PATH_TRANSLATION_FILE");
 
   if(tablepath)
-- 
cgit v0.12


From e0f740f1b1708ac4ec43a57b8f1cbc549afe5df3 Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 15:03:41 +0200
Subject: Always cache entries through the cmake instance.

---
 Source/cmMakefile.cxx              | 4 ++--
 Source/cmMarkAsAdvancedCommand.cxx | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index c060505..7866c6b 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1908,13 +1908,13 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
         nvalue += files[cc];
         }
 
-      this->GetState()->AddCacheEntry(name, nvalue.c_str(), doc, type);
+      this->GetCMakeInstance()->AddCacheEntry(name, nvalue.c_str(), doc, type);
       val = this->GetState()->GetInitializedCacheValue(name);
       haveVal = true;
       }
 
     }
-  this->GetState()->AddCacheEntry(name, haveVal ? val.c_str() : 0,
+  this->GetCMakeInstance()->AddCacheEntry(name, haveVal ? val.c_str() : 0,
                                           doc, type);
   // if there was a definition then remove it
   this->StateSnapshot.RemoveDefinition(name);
diff --git a/Source/cmMarkAsAdvancedCommand.cxx b/Source/cmMarkAsAdvancedCommand.cxx
index 10d30f3..8d0e2b3 100644
--- a/Source/cmMarkAsAdvancedCommand.cxx
+++ b/Source/cmMarkAsAdvancedCommand.cxx
@@ -39,7 +39,8 @@ bool cmMarkAsAdvancedCommand
     cmState* state = this->Makefile->GetState();
     if (!state->GetCacheEntryValue(variable))
       {
-      state->AddCacheEntry(variable, 0, 0, cmState::UNINITIALIZED);
+      this->Makefile->GetCMakeInstance()->AddCacheEntry(
+              variable, 0, 0, cmState::UNINITIALIZED);
       overwrite = true;
       }
     if (!state->GetCacheEntryValue(variable))
-- 
cgit v0.12


From bec3487fa94093e696be170c4d85567c3c934545 Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 14:23:48 +0200
Subject: cmCacheManager: Remove cmMakefile dependency.

Update comment.
---
 Source/cmCacheManager.cxx | 1 -
 Source/cmCacheManager.h   | 3 +--
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
index 54209c5..a7777d9 100644
--- a/Source/cmCacheManager.cxx
+++ b/Source/cmCacheManager.cxx
@@ -13,7 +13,6 @@
 #include "cmCacheManager.h"
 #include "cmSystemTools.h"
 #include "cmGeneratedFileStream.h"
-#include "cmMakefile.h"
 #include "cmake.h"
 #include "cmVersion.h"
 
diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h
index 8462259..b779ba3 100644
--- a/Source/cmCacheManager.h
+++ b/Source/cmCacheManager.h
@@ -16,7 +16,6 @@
 #include "cmPropertyMap.h"
 #include "cmState.h"
 
-class cmMakefile;
 class cmMarkAsAdvancedCommand;
 class cmake;
 
@@ -241,7 +240,7 @@ private:
   void WritePropertyEntries(std::ostream& os, CacheIterator const& i);
 
   CacheEntryMap Cache;
-  // Only cmake and cmMakefile should be able to add cache values
+  // Only cmake and cmState should be able to add cache values
   // the commands should never use the cmCacheManager directly
   friend class cmState; // allow access to add cache values
   friend class cmake; // allow access to add cache values
-- 
cgit v0.12


From a02e53eb947b61dd25ecd139a213d4062fbc5b62 Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 15:13:08 +0200
Subject: Inline unary LoadCache.

---
 Source/cmCacheManager.cxx | 6 ------
 Source/cmCacheManager.h   | 1 -
 Source/cmake.cxx          | 3 ++-
 3 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
index a7777d9..9dac27b 100644
--- a/Source/cmCacheManager.cxx
+++ b/Source/cmCacheManager.cxx
@@ -28,12 +28,6 @@ cmCacheManager::cmCacheManager(cmake* cm)
   this->CMakeInstance = cm;
 }
 
-bool cmCacheManager::LoadCache(const std::string& path)
-{
-  std::set<std::string> emptySet;
-  return this->LoadCache(path, true, emptySet, emptySet);
-}
-
 static bool ParseEntryWithoutType(const std::string& entry,
                                   std::string& var,
                                   std::string& value)
diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h
index b779ba3..76533b5 100644
--- a/Source/cmCacheManager.h
+++ b/Source/cmCacheManager.h
@@ -99,7 +99,6 @@ public:
     }
 
   ///! Load a cache for given makefile.  Loads from path/CMakeCache.txt.
-  bool LoadCache(const std::string& path);
   bool LoadCache(const std::string& path, bool internal,
                  std::set<std::string>& excludes,
                  std::set<std::string>& includes);
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 8016e41..ad5f6b7 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -1752,7 +1752,8 @@ int cmake::LoadCache()
 
 bool cmake::LoadCache(const std::string& path)
 {
-  return this->CacheManager->LoadCache(path);
+  std::set<std::string> emptySet;
+  return this->LoadCache(path, true, emptySet, emptySet);
 }
 
 bool cmake::LoadCache(const std::string& path, bool internal,
-- 
cgit v0.12


From 062ed22ec43809068526706d2600297095412911 Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 15:21:41 +0200
Subject: cmState: Add cache file manipulation wrappers.

---
 Source/cmState.cxx | 18 ++++++++++++++++++
 Source/cmState.h   |  8 ++++++++
 Source/cmake.cxx   |  6 +++---
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index db7519b..9628265 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -147,6 +147,24 @@ bool cmState::IsCacheEntryType(std::string const& key)
   return false;
 }
 
+bool cmState::LoadCache(const std::string& path, bool internal,
+                        std::set<std::string>& excludes,
+                        std::set<std::string>& includes)
+{
+  return this->CMakeInstance->GetCacheManager()->LoadCache(path, internal,
+                                                    excludes, includes);
+}
+
+bool cmState::SaveCache(const std::string& path)
+{
+  return this->CMakeInstance->GetCacheManager()->SaveCache(path);
+}
+
+bool cmState::DeleteCache(const std::string& path)
+{
+  return this->CMakeInstance->GetCacheManager()->DeleteCache(path);
+}
+
 std::vector<std::string> cmState::GetCacheEntryKeys() const
 {
   std::vector<std::string> definitions;
diff --git a/Source/cmState.h b/Source/cmState.h
index 1ffc4bf..3f0ac77 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -208,6 +208,14 @@ public:
   static const char* CacheEntryTypeToString(CacheEntryType);
   static bool IsCacheEntryType(std::string const& key);
 
+  bool LoadCache(const std::string& path, bool internal,
+                 std::set<std::string>& excludes,
+                 std::set<std::string>& includes);
+
+  bool SaveCache(const std::string& path) ;
+
+  bool DeleteCache(const std::string& path);
+
   std::vector<std::string> GetCacheEntryKeys() const;
   const char* GetCacheEntryValue(std::string const& key) const;
   const char* GetInitializedCacheValue(std::string const& key) const;
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index ad5f6b7..4fc48d5 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -1760,17 +1760,17 @@ bool cmake::LoadCache(const std::string& path, bool internal,
                 std::set<std::string>& excludes,
                 std::set<std::string>& includes)
 {
-  return this->CacheManager->LoadCache(path, internal, excludes, includes);
+  return this->State->LoadCache(path, internal, excludes, includes);
 }
 
 bool cmake::SaveCache(const std::string& path)
 {
-  return this->CacheManager->SaveCache(path);
+  return this->State->SaveCache(path);
 }
 
 bool cmake::DeleteCache(const std::string& path)
 {
-  return this->CacheManager->DeleteCache(path);
+  return this->State->DeleteCache(path);
 }
 
 void cmake::SetProgressCallback(ProgressCallbackType f, void *cd)
-- 
cgit v0.12


From 435a2f3ccb51acf119cfa1671f1c5b344a7d47a0 Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 14:26:56 +0200
Subject: cmCacheManager: Port away from cmake instance.

---
 Source/cmCacheManager.cxx |  4 +---
 Source/cmCacheManager.h   |  3 +--
 Source/cmState.cxx        |  1 +
 Source/cmake.cxx          | 24 +++++++++++++++++++++---
 4 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
index 9dac27b..bfa60b3 100644
--- a/Source/cmCacheManager.cxx
+++ b/Source/cmCacheManager.cxx
@@ -21,11 +21,10 @@
 #include <cmsys/FStream.hxx>
 #include <cmsys/RegularExpression.hxx>
 
-cmCacheManager::cmCacheManager(cmake* cm)
+cmCacheManager::cmCacheManager()
 {
   this->CacheMajorVersion = 0;
   this->CacheMinorVersion = 0;
-  this->CMakeInstance = cm;
 }
 
 static bool ParseEntryWithoutType(const std::string& entry,
@@ -671,7 +670,6 @@ void cmCacheManager::AddCacheEntry(const std::string& key,
     }
   e.SetProperty("HELPSTRING", helpString? helpString :
                 "(This variable does not exist and should not be used)");
-  this->CMakeInstance->UnwatchUnusedCli(key);
 }
 
 bool cmCacheManager::CacheIterator::IsAtEnd() const
diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h
index 76533b5..2440066 100644
--- a/Source/cmCacheManager.h
+++ b/Source/cmCacheManager.h
@@ -17,7 +17,6 @@
 #include "cmState.h"
 
 class cmMarkAsAdvancedCommand;
-class cmake;
 
 /** \class cmCacheManager
  * \brief Control class for cmake's cache
@@ -28,7 +27,7 @@ class cmake;
 class cmCacheManager
 {
 public:
-  cmCacheManager(cmake* cm);
+  cmCacheManager();
   class CacheIterator;
   friend class cmCacheManager::CacheIterator;
 
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 9628265..a42d075 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -252,6 +252,7 @@ void cmState::AddCacheEntry(const std::string& key, const char* value,
 {
   this->CMakeInstance->GetCacheManager()->AddCacheEntry(key, value,
                                                         helpString, type);
+  this->CMakeInstance->UnwatchUnusedCli(key);
 }
 
 void cmState::RemoveCacheEntry(std::string const& key)
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 4fc48d5..69a3f03 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -151,7 +151,7 @@ cmake::cmake()
 #endif
 
   this->Verbose = false;
-  this->CacheManager = new cmCacheManager(this);
+  this->CacheManager = new cmCacheManager;
   this->GlobalGenerator = 0;
   this->ProgressCallback = 0;
   this->ProgressCallbackClientData = 0;
@@ -1760,12 +1760,30 @@ bool cmake::LoadCache(const std::string& path, bool internal,
                 std::set<std::string>& excludes,
                 std::set<std::string>& includes)
 {
-  return this->State->LoadCache(path, internal, excludes, includes);
+  bool result = this->State->LoadCache(path, internal, excludes, includes);
+  static const char* entries[] = {"CMAKE_CACHE_MAJOR_VERSION",
+                                  "CMAKE_CACHE_MINOR_VERSION"};
+  for (const char* const* nameIt = cmArrayBegin(entries);
+       nameIt != cmArrayEnd(entries); ++nameIt)
+    {
+    this->UnwatchUnusedCli(*nameIt);
+    }
+  return result;
 }
 
 bool cmake::SaveCache(const std::string& path)
 {
-  return this->State->SaveCache(path);
+  bool result = this->State->SaveCache(path);
+  static const char* entries[] = {"CMAKE_CACHE_MAJOR_VERSION",
+                                  "CMAKE_CACHE_MINOR_VERSION",
+                                  "CMAKE_CACHE_PATCH_VERSION",
+                                  "CMAKE_CACHEFILE_DIR"};
+  for (const char* const* nameIt = cmArrayBegin(entries);
+       nameIt != cmArrayEnd(entries); ++nameIt)
+    {
+    this->UnwatchUnusedCli(*nameIt);
+    }
+  return result;
 }
 
 bool cmake::DeleteCache(const std::string& path)
-- 
cgit v0.12


From 6f02034e668a307587c2eb1aa0e342fd17ca103e Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 15:05:50 +0200
Subject: cmState: Make AddCacheEntry method private.

---
 Source/cmState.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Source/cmState.h b/Source/cmState.h
index 3f0ac77..e71668f 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -223,8 +223,6 @@ public:
   void SetCacheEntryValue(std::string const& key, std::string const& value);
   void SetCacheValue(std::string const& key, std::string const& value);
 
-  void AddCacheEntry(const std::string& key, const char* value,
-                     const char* helpString, CacheEntryType type);
   void RemoveCacheEntry(std::string const& key);
 
   void SetCacheEntryProperty(std::string const& key,
@@ -305,6 +303,10 @@ public:
   bool UseMSYSShell() const;
 
 private:
+  friend class cmake;
+  void AddCacheEntry(const std::string& key, const char* value,
+                     const char* helpString, CacheEntryType type);
+
   std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions;
   std::vector<std::string> EnabledLanguages;
   std::map<std::string, cmCommand*> Commands;
-- 
cgit v0.12


From 95b0d761a75fd2da041eacc9ee22b89043ae301f Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 14:31:06 +0200
Subject: cmState: Externalize logic to caller.

---
 Source/cmState.cxx | 1 -
 Source/cmake.cxx   | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index a42d075..9628265 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -252,7 +252,6 @@ void cmState::AddCacheEntry(const std::string& key, const char* value,
 {
   this->CMakeInstance->GetCacheManager()->AddCacheEntry(key, value,
                                                         helpString, type);
-  this->CMakeInstance->UnwatchUnusedCli(key);
 }
 
 void cmState::RemoveCacheEntry(std::string const& key)
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 69a3f03..b90ac69 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -1644,6 +1644,7 @@ void cmake::AddCacheEntry(const std::string& key, const char* value,
   this->State->AddCacheEntry(key, value,
                                     helpString,
                                     cmState::CacheEntryType(type));
+  this->UnwatchUnusedCli(key);
 }
 
 const char* cmake::GetCacheDefinition(const std::string& name) const
-- 
cgit v0.12


From b5212c68def0395642fc51dcfd499557eb9481d9 Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 14:34:26 +0200
Subject: cmState: Add API for cache version.

---
 Source/cmCPluginAPI.cxx           |  8 ++++----
 Source/cmState.cxx                | 10 ++++++++++
 Source/cmState.h                  |  3 +++
 Source/cmUtilitySourceCommand.cxx | 10 ++++------
 4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx
index 7da334e..6fa4ebb 100644
--- a/Source/cmCPluginAPI.cxx
+++ b/Source/cmCPluginAPI.cxx
@@ -51,14 +51,14 @@ void CCONV cmSetError(void *info, const char *err)
 unsigned int CCONV  cmGetCacheMajorVersion(void *arg)
 {
   cmMakefile *mf = static_cast<cmMakefile *>(arg);
-  cmCacheManager *manager = mf->GetCMakeInstance()->GetCacheManager();
-  return manager->GetCacheMajorVersion();
+  cmState *state = mf->GetState();
+  return state->GetCacheMajorVersion();
 }
 unsigned int CCONV cmGetCacheMinorVersion(void *arg)
 {
   cmMakefile *mf = static_cast<cmMakefile *>(arg);
-  cmCacheManager *manager = mf->GetCMakeInstance()->GetCacheManager();
-  return manager->GetCacheMinorVersion();
+  cmState *state = mf->GetState();
+  return state->GetCacheMinorVersion();
 }
 
 unsigned int CCONV cmGetMajorVersion(void *)
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 9628265..3aad7f5 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -677,6 +677,16 @@ bool cmState::UseMSYSShell() const
   return this->MSYSShell;
 }
 
+unsigned int cmState::GetCacheMajorVersion() const
+{
+  return this->CMakeInstance->GetCacheManager()->GetCacheMajorVersion();
+}
+
+unsigned int cmState::GetCacheMinorVersion() const
+{
+  return this->CMakeInstance->GetCacheManager()->GetCacheMinorVersion();
+}
+
 const char* cmState::GetBinaryDirectory() const
 {
   return this->BinaryDirectory.c_str();
diff --git a/Source/cmState.h b/Source/cmState.h
index e71668f..4c32831 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -302,6 +302,9 @@ public:
   void SetMSYSShell(bool mSYSShell);
   bool UseMSYSShell() const;
 
+  unsigned int GetCacheMajorVersion() const;
+  unsigned int GetCacheMinorVersion() const;
+
 private:
   friend class cmake;
   void AddCacheEntry(const std::string& key, const char* value,
diff --git a/Source/cmUtilitySourceCommand.cxx b/Source/cmUtilitySourceCommand.cxx
index 486328f..3f1e333 100644
--- a/Source/cmUtilitySourceCommand.cxx
+++ b/Source/cmUtilitySourceCommand.cxx
@@ -11,8 +11,6 @@
 ============================================================================*/
 #include "cmUtilitySourceCommand.h"
 
-#include "cmCacheManager.h"
-
 // cmUtilitySourceCommand
 bool cmUtilitySourceCommand
 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
@@ -54,13 +52,13 @@ bool cmUtilitySourceCommand
     }
   else
     {
-    cmCacheManager *manager =
-        this->Makefile->GetCMakeInstance()->GetCacheManager();
+    cmState *state =
+        this->Makefile->GetState();
     haveCacheValue = (cacheValue &&
      (strstr(cacheValue, "(IntDir)") == 0 ||
       (intDir && strcmp(intDir, "$(IntDir)") == 0)) &&
-     (manager->GetCacheMajorVersion() != 0 &&
-      manager->GetCacheMinorVersion() != 0 ));
+     (state->GetCacheMajorVersion() != 0 &&
+      state->GetCacheMinorVersion() != 0 ));
     }
 
   if(haveCacheValue)
-- 
cgit v0.12


From e2eecae20517daa2bb292f85e161d5cebbc1f216 Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 15:08:15 +0200
Subject: cmState: Move ParseCacheEntry from cmCacheManager.

---
 Source/cmCacheManager.cxx | 86 +----------------------------------------------
 Source/cmCacheManager.h   |  6 ----
 Source/cmState.cxx        | 84 +++++++++++++++++++++++++++++++++++++++++++++
 Source/cmState.h          |  6 ++++
 Source/cmake.cxx          |  4 +--
 5 files changed, 93 insertions(+), 93 deletions(-)

diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
index bfa60b3..ce8af55 100644
--- a/Source/cmCacheManager.cxx
+++ b/Source/cmCacheManager.cxx
@@ -27,90 +27,6 @@ cmCacheManager::cmCacheManager()
   this->CacheMinorVersion = 0;
 }
 
-static bool ParseEntryWithoutType(const std::string& entry,
-                                  std::string& var,
-                                  std::string& value)
-{
-  // input line is:         key=value
-  static cmsys::RegularExpression reg(
-    "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
-  // input line is:         "key"=value
-  static cmsys::RegularExpression regQuoted(
-    "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
-  bool flag = false;
-  if(regQuoted.find(entry))
-    {
-    var = regQuoted.match(1);
-    value = regQuoted.match(2);
-    flag = true;
-    }
-  else if (reg.find(entry))
-    {
-    var = reg.match(1);
-    value = reg.match(2);
-    flag = true;
-    }
-
-  // if value is enclosed in single quotes ('foo') then remove them
-  // it is used to enclose trailing space or tab
-  if (flag &&
-      value.size() >= 2 &&
-      value[0] == '\'' &&
-      value[value.size() - 1] == '\'')
-    {
-    value = value.substr(1,
-                         value.size() - 2);
-    }
-
-  return flag;
-}
-
-bool cmCacheManager::ParseEntry(const std::string& entry,
-                                std::string& var,
-                                std::string& value,
-                                cmState::CacheEntryType& type)
-{
-  // input line is:         key:type=value
-  static cmsys::RegularExpression reg(
-    "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
-  // input line is:         "key":type=value
-  static cmsys::RegularExpression regQuoted(
-    "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
-  bool flag = false;
-  if(regQuoted.find(entry))
-    {
-    var = regQuoted.match(1);
-    type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str());
-    value = regQuoted.match(3);
-    flag = true;
-    }
-  else if (reg.find(entry))
-    {
-    var = reg.match(1);
-    type = cmState::StringToCacheEntryType(reg.match(2).c_str());
-    value = reg.match(3);
-    flag = true;
-    }
-
-  // if value is enclosed in single quotes ('foo') then remove them
-  // it is used to enclose trailing space or tab
-  if (flag &&
-      value.size() >= 2 &&
-      value[0] == '\'' &&
-      value[value.size() - 1] == '\'')
-    {
-    value = value.substr(1,
-                         value.size() - 2);
-    }
-
-  if (!flag)
-    {
-    return ParseEntryWithoutType(entry, var, value);
-    }
-
-  return flag;
-}
-
 void cmCacheManager::CleanCMakeFiles(const std::string& path)
 {
   std::string glob = path;
@@ -187,7 +103,7 @@ bool cmCacheManager::LoadCache(const std::string& path,
         }
       }
     e.SetProperty("HELPSTRING", helpString.c_str());
-    if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.Value, e.Type))
+    if(cmState::ParseCacheEntry(realbuffer, entryKey, e.Value, e.Type))
       {
       if ( excludes.find(entryKey) == excludes.end() )
         {
diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h
index 2440066..6f063eb 100644
--- a/Source/cmCacheManager.h
+++ b/Source/cmCacheManager.h
@@ -121,12 +121,6 @@ public:
   int GetSize() {
     return static_cast<int>(this->Cache.size()); }
 
-  ///! Break up a line like VAR:type="value" into var, type and value
-  static bool ParseEntry(const std::string& entry,
-                         std::string& var,
-                         std::string& value,
-                         cmState::CacheEntryType& type);
-
   ///! Get a value from the cache given a key
   const char* GetInitializedCacheValue(const std::string& key) const;
 
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 3aad7f5..c5bbf42 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -1769,3 +1769,87 @@ bool operator!=(const cmState::Snapshot& lhs, const cmState::Snapshot& rhs)
 {
   return lhs.Position != rhs.Position;
 }
+
+static bool ParseEntryWithoutType(const std::string& entry,
+                                  std::string& var,
+                                  std::string& value)
+{
+  // input line is:         key=value
+  static cmsys::RegularExpression reg(
+    "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
+  // input line is:         "key"=value
+  static cmsys::RegularExpression regQuoted(
+    "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
+  bool flag = false;
+  if(regQuoted.find(entry))
+    {
+    var = regQuoted.match(1);
+    value = regQuoted.match(2);
+    flag = true;
+    }
+  else if (reg.find(entry))
+    {
+    var = reg.match(1);
+    value = reg.match(2);
+    flag = true;
+    }
+
+  // if value is enclosed in single quotes ('foo') then remove them
+  // it is used to enclose trailing space or tab
+  if (flag &&
+      value.size() >= 2 &&
+      value[0] == '\'' &&
+      value[value.size() - 1] == '\'')
+    {
+    value = value.substr(1,
+                         value.size() - 2);
+    }
+
+  return flag;
+}
+
+bool cmState::ParseCacheEntry(const std::string& entry,
+                                std::string& var,
+                                std::string& value,
+                                CacheEntryType& type)
+{
+  // input line is:         key:type=value
+  static cmsys::RegularExpression reg(
+    "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
+  // input line is:         "key":type=value
+  static cmsys::RegularExpression regQuoted(
+    "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
+  bool flag = false;
+  if(regQuoted.find(entry))
+    {
+    var = regQuoted.match(1);
+    type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str());
+    value = regQuoted.match(3);
+    flag = true;
+    }
+  else if (reg.find(entry))
+    {
+    var = reg.match(1);
+    type = cmState::StringToCacheEntryType(reg.match(2).c_str());
+    value = reg.match(3);
+    flag = true;
+    }
+
+  // if value is enclosed in single quotes ('foo') then remove them
+  // it is used to enclose trailing space or tab
+  if (flag &&
+      value.size() >= 2 &&
+      value[0] == '\'' &&
+      value[value.size() - 1] == '\'')
+    {
+    value = value.substr(1,
+                         value.size() - 2);
+    }
+
+  if (!flag)
+    {
+    return ParseEntryWithoutType(entry, var, value);
+    }
+
+  return flag;
+}
diff --git a/Source/cmState.h b/Source/cmState.h
index 4c32831..fbc9275 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -242,6 +242,12 @@ public:
   void RemoveCacheEntryProperty(std::string const& key,
                                 std::string const& propertyName);
 
+  ///! Break up a line like VAR:type="value" into var, type and value
+  static bool ParseCacheEntry(const std::string& entry,
+                              std::string& var,
+                              std::string& value,
+                              CacheEntryType& type);
+
   Snapshot Reset();
   // Define a property
   void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index b90ac69..b1c2709 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -216,7 +216,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
         }
       std::string var, value;
       cmState::CacheEntryType type = cmState::UNINITIALIZED;
-      if(cmCacheManager::ParseEntry(entry, var, value, type))
+      if(cmState::ParseCacheEntry(entry, var, value, type))
         {
         // The value is transformed if it is a filepath for example, so
         // we can't compare whether the value is already in the cache until
@@ -1722,7 +1722,7 @@ bool cmake::ParseCacheEntry(const std::string& entry,
                             std::string& value,
                             cmState::CacheEntryType& type)
 {
-  return cmCacheManager::ParseEntry(entry, var, value, type);
+  return cmState::ParseCacheEntry(entry, var, value, type);
 }
 
 int cmake::LoadCache()
-- 
cgit v0.12


From 79a309d786abefef1a4f354c2973a14cba882850 Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sat, 10 Oct 2015 15:42:02 +0200
Subject: cmState: Port away from cmake instance.

---
 Source/cmState.cxx | 47 ++++++++++++++++++++++++-----------------------
 Source/cmState.h   |  5 +++--
 Source/cmake.cxx   |  5 +----
 3 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index c5bbf42..72c7330 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -82,9 +82,8 @@ struct cmState::BuildsystemDirectoryStateType
   std::vector<cmState::Snapshot> Children;
 };
 
-cmState::cmState(cmake* cm)
-  : CMakeInstance(cm),
-    IsInTryCompile(false),
+cmState::cmState()
+  : IsInTryCompile(false),
     WindowsShell(false),
     WindowsVSIDE(false),
     WatcomWMake(false),
@@ -92,10 +91,12 @@ cmState::cmState(cmake* cm)
     NMake(false),
     MSYSShell(false)
 {
+  this->CacheManager = new cmCacheManager;
 }
 
 cmState::~cmState()
 {
+  delete this->CacheManager;
   cmDeleteAll(this->Commands);
 }
 
@@ -151,26 +152,26 @@ bool cmState::LoadCache(const std::string& path, bool internal,
                         std::set<std::string>& excludes,
                         std::set<std::string>& includes)
 {
-  return this->CMakeInstance->GetCacheManager()->LoadCache(path, internal,
-                                                    excludes, includes);
+  return this->CacheManager->LoadCache(path, internal,
+                                       excludes, includes);
 }
 
 bool cmState::SaveCache(const std::string& path)
 {
-  return this->CMakeInstance->GetCacheManager()->SaveCache(path);
+  return this->CacheManager->SaveCache(path);
 }
 
 bool cmState::DeleteCache(const std::string& path)
 {
-  return this->CMakeInstance->GetCacheManager()->DeleteCache(path);
+  return this->CacheManager->DeleteCache(path);
 }
 
 std::vector<std::string> cmState::GetCacheEntryKeys() const
 {
   std::vector<std::string> definitions;
-  definitions.reserve(this->CMakeInstance->GetCacheManager()->GetSize());
+  definitions.reserve(this->CacheManager->GetSize());
   cmCacheManager::CacheIterator cit =
-    this->CMakeInstance->GetCacheManager()->GetCacheIterator();
+    this->CacheManager->GetCacheIterator();
   for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
     {
     definitions.push_back(cit.GetName());
@@ -180,7 +181,7 @@ std::vector<std::string> cmState::GetCacheEntryKeys() const
 
 const char* cmState::GetCacheEntryValue(std::string const& key) const
 {
-  cmCacheManager::CacheEntry* e = this->CMakeInstance->GetCacheManager()
+  cmCacheManager::CacheEntry* e = this->CacheManager
              ->GetCacheEntry(key);
   if (!e)
     {
@@ -192,21 +193,21 @@ const char* cmState::GetCacheEntryValue(std::string const& key) const
 const char*
 cmState::GetInitializedCacheValue(std::string const& key) const
 {
-  return this->CMakeInstance->GetCacheManager()->GetInitializedCacheValue(key);
+  return this->CacheManager->GetInitializedCacheValue(key);
 }
 
 cmState::CacheEntryType
 cmState::GetCacheEntryType(std::string const& key) const
 {
   cmCacheManager::CacheIterator it =
-      this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
+      this->CacheManager->GetCacheIterator(key.c_str());
   return it.GetType();
 }
 
 void cmState::SetCacheEntryValue(std::string const& key,
                                          std::string const& value)
 {
-  this->CMakeInstance->GetCacheManager()->SetCacheEntryValue(key, value);
+  this->CacheManager->SetCacheEntryValue(key, value);
 }
 
 void cmState::SetCacheEntryProperty(std::string const& key,
@@ -214,7 +215,7 @@ void cmState::SetCacheEntryProperty(std::string const& key,
                             std::string const& value)
 {
   cmCacheManager::CacheIterator it =
-      this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
+      this->CacheManager->GetCacheIterator(key.c_str());
   it.SetProperty(propertyName, value.c_str());
 }
 
@@ -223,14 +224,14 @@ void cmState::SetCacheEntryBoolProperty(std::string const& key,
                             bool value)
 {
   cmCacheManager::CacheIterator it =
-      this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
+      this->CacheManager->GetCacheIterator(key.c_str());
   it.SetProperty(propertyName, value);
 }
 
 const char* cmState::GetCacheEntryProperty(std::string const& key,
                                               std::string const& propertyName)
 {
-  cmCacheManager::CacheIterator it = this->CMakeInstance->GetCacheManager()
+  cmCacheManager::CacheIterator it = this->CacheManager
              ->GetCacheIterator(key.c_str());
   if (!it.PropertyExists(propertyName))
     {
@@ -242,7 +243,7 @@ const char* cmState::GetCacheEntryProperty(std::string const& key,
 bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
                                               std::string const& propertyName)
 {
-  return this->CMakeInstance->GetCacheManager()
+  return this->CacheManager
              ->GetCacheIterator(key.c_str()).GetPropertyAsBool(propertyName);
 }
 
@@ -250,13 +251,13 @@ void cmState::AddCacheEntry(const std::string& key, const char* value,
                                     const char* helpString,
                                     cmState::CacheEntryType type)
 {
-  this->CMakeInstance->GetCacheManager()->AddCacheEntry(key, value,
+  this->CacheManager->AddCacheEntry(key, value,
                                                         helpString, type);
 }
 
 void cmState::RemoveCacheEntry(std::string const& key)
 {
-  this->CMakeInstance->GetCacheManager()->RemoveCacheEntry(key);
+  this->CacheManager->RemoveCacheEntry(key);
 }
 
 void cmState::AppendCacheEntryProperty(const std::string& key,
@@ -264,7 +265,7 @@ void cmState::AppendCacheEntryProperty(const std::string& key,
                                                const std::string& value,
                                                bool asString)
 {
-  this->CMakeInstance->GetCacheManager()
+  this->CacheManager
        ->GetCacheIterator(key.c_str()).AppendProperty(property,
                                                        value.c_str(),
                                                        asString);
@@ -273,7 +274,7 @@ void cmState::AppendCacheEntryProperty(const std::string& key,
 void cmState::RemoveCacheEntryProperty(std::string const& key,
                                               std::string const& propertyName)
 {
-  this->CMakeInstance->GetCacheManager()
+  this->CacheManager
        ->GetCacheIterator(key.c_str()).SetProperty(propertyName, (void*)0);
 }
 
@@ -679,12 +680,12 @@ bool cmState::UseMSYSShell() const
 
 unsigned int cmState::GetCacheMajorVersion() const
 {
-  return this->CMakeInstance->GetCacheManager()->GetCacheMajorVersion();
+  return this->CacheManager->GetCacheMajorVersion();
 }
 
 unsigned int cmState::GetCacheMinorVersion() const
 {
-  return this->CMakeInstance->GetCacheManager()->GetCacheMinorVersion();
+  return this->CacheManager->GetCacheMinorVersion();
 }
 
 const char* cmState::GetBinaryDirectory() const
diff --git a/Source/cmState.h b/Source/cmState.h
index fbc9275..2f66f7f 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -23,6 +23,7 @@ class cmake;
 class cmCommand;
 class cmDefinitions;
 class cmListFileBacktrace;
+class cmCacheManager;
 
 class cmState
 {
@@ -32,7 +33,7 @@ class cmState
   typedef cmLinkedTree<SnapshotDataType>::iterator PositionType;
   friend class Snapshot;
 public:
-  cmState(cmake* cm);
+  cmState();
   ~cmState();
 
   enum SnapshotType
@@ -320,7 +321,7 @@ private:
   std::vector<std::string> EnabledLanguages;
   std::map<std::string, cmCommand*> Commands;
   cmPropertyMap GlobalProperties;
-  cmake* CMakeInstance;
+  cmCacheManager* CacheManager;
 
   cmLinkedTree<BuildsystemDirectoryStateType> BuildsystemDirectory;
 
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index b1c2709..6846f1b 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -10,7 +10,6 @@
   See the License for more information.
 ============================================================================*/
 #include "cmake.h"
-#include "cmCacheManager.h"
 #include "cmMakefile.h"
 #include "cmLocalGenerator.h"
 #include "cmExternalMakefileProjectGenerator.h"
@@ -135,7 +134,7 @@ cmake::cmake()
   this->ClearBuildSystem = false;
   this->FileComparison = new cmFileTimeComparison;
 
-  this->State = new cmState(this);
+  this->State = new cmState;
   this->CurrentSnapshot = this->State->CreateBaseSnapshot();
 
 #ifdef __APPLE__
@@ -151,7 +150,6 @@ cmake::cmake()
 #endif
 
   this->Verbose = false;
-  this->CacheManager = new cmCacheManager;
   this->GlobalGenerator = 0;
   this->ProgressCallback = 0;
   this->ProgressCallbackClientData = 0;
@@ -171,7 +169,6 @@ cmake::cmake()
 
 cmake::~cmake()
 {
-  delete this->CacheManager;
   delete this->State;
   if (this->GlobalGenerator)
     {
-- 
cgit v0.12