diff options
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | Source/cmake.cxx | 57 | ||||
-rw-r--r-- | Source/cmake.h | 10 |
3 files changed, 50 insertions, 22 deletions
@@ -1,2 +1,7 @@ # Exclude MacOS Finder files. .DS_Store + +*.user* + +*.pyc +Testing diff --git a/Source/cmake.cxx b/Source/cmake.cxx index d6bea3d..0d61a3d 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -35,7 +35,7 @@ #if defined(CMAKE_BUILD_WITH_CMAKE) #include "cmGraphVizWriter.h" #include "cmVariableWatch.h" -#include <cm_jsoncpp_value.h> + #include <cm_jsoncpp_writer.h> #endif @@ -233,10 +233,9 @@ cmake::~cmake() delete this->FileComparison; } -std::string cmake::ReportCapabilities() const -{ - std::string result; #if defined(CMAKE_BUILD_WITH_CMAKE) +Json::Value cmake::ReportCapabilitiesJson() const +{ Json::Value obj = Json::objectValue; // Version information: Json::Value version = Json::objectValue; @@ -287,8 +286,16 @@ std::string cmake::ReportCapabilities() const #else obj["serverMode"] = false; #endif + return obj; +} +#endif + +std::string cmake::ReportCapabilities() const +{ + std::string result; +#if defined(CMAKE_BUILD_WITH_CMAKE) Json::FastWriter writer; - result = writer.write(obj); + result = writer.write(this->ReportCapabilitiesJson()); #else result = "Not supported"; #endif @@ -1039,6 +1046,28 @@ const char* cmake::GetHomeOutputDirectory() const return this->State->GetBinaryDirectory(); } +std::string cmake::FindCacheFile(const std::string& binaryDir) const +{ + std::string cachePath = binaryDir; + cmSystemTools::ConvertToUnixSlashes(cachePath); + std::string cacheFile = cachePath; + cacheFile += "/CMakeCache.txt"; + if (!cmSystemTools::FileExists(cacheFile.c_str())) { + // search in parent directories for cache + std::string cmakeFiles = cachePath; + cmakeFiles += "/CMakeFiles"; + if (cmSystemTools::FileExists(cmakeFiles.c_str())) { + std::string cachePathFound = + cmSystemTools::FileExistsInParentDirectories("CMakeCache.txt", + cachePath.c_str(), "/"); + if (!cachePathFound.empty()) { + cachePath = cmSystemTools::GetFilenamePath(cachePathFound); + } + } + } + return cachePath; +} + void cmake::SetGlobalGenerator(cmGlobalGenerator* gg) { if (!gg) { @@ -2337,24 +2366,8 @@ int cmake::Build(const std::string& dir, const std::string& target, std::cerr << "Error: " << dir << " is not a directory\n"; return 1; } - std::string cachePath = dir; - cmSystemTools::ConvertToUnixSlashes(cachePath); - std::string cacheFile = cachePath; - cacheFile += "/CMakeCache.txt"; - if (!cmSystemTools::FileExists(cacheFile.c_str())) { - // search in parent directories for cache - std::string cmakeFiles = cachePath; - cmakeFiles += "/CMakeFiles"; - if (cmSystemTools::FileExists(cmakeFiles.c_str())) { - std::string cachePathFound = - cmSystemTools::FileExistsInParentDirectories("CMakeCache.txt", - cachePath.c_str(), "/"); - if (!cachePathFound.empty()) { - cachePath = cmSystemTools::GetFilenamePath(cachePathFound); - } - } - } + std::string cachePath = FindCacheFile(dir); if (!this->LoadCache(cachePath)) { std::cerr << "Error: could not load cache\n"; return 1; diff --git a/Source/cmake.h b/Source/cmake.h index 9dc429d..30661d9 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -24,6 +24,10 @@ #include <string> #include <vector> +#if defined(CMAKE_BUILD_WITH_CMAKE) +#include "cm_jsoncpp_value.h" +#endif + class cmExternalMakefileProjectGeneratorFactory; class cmFileTimeComparison; class cmGlobalGenerator; @@ -118,6 +122,9 @@ public: /// Destructor ~cmake(); +#if defined(CMAKE_BUILD_WITH_CMAKE) + Json::Value ReportCapabilitiesJson() const; +#endif std::string ReportCapabilities() const; static const char* GetCMakeFilesDirectory() { return "/CMakeFiles"; } @@ -186,6 +193,9 @@ public: return this->GlobalGenerator; } + ///! Return the full path to where the CMakeCache.txt file should be. + std::string FindCacheFile(const std::string& binaryDir) const; + ///! Return the global generator assigned to this instance of cmake void SetGlobalGenerator(cmGlobalGenerator*); |