Merge topic 'cmake-server-prepare'

3e58b9af cmake: Factor out method to find the CMakeCache.txt file
c73967cb cmake: Introduce ReportCapabilitiesJson
366e3828 Update .gitignore
This commit is contained in:
Brad King 2016-09-13 11:40:50 -04:00 committed by CMake Topic Stage
commit 112f758223
3 changed files with 50 additions and 22 deletions

5
.gitignore vendored
View File

@ -1,2 +1,7 @@
# Exclude MacOS Finder files.
.DS_Store
*.user*
*.pyc
Testing

View File

@ -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;

View File

@ -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*);