summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/cmake.cxx78
-rw-r--r--Source/cmake.h2
-rw-r--r--Source/cmcmd.cxx12
3 files changed, 92 insertions, 0 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index a265ead..4313d83 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -23,11 +23,15 @@
#include "cmState.h"
#include "cmTest.h"
#include "cmUtils.hxx"
+#include "cmVersionMacros.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
#include "cmGraphVizWriter.h"
#include "cmVariableWatch.h"
#include <cmsys/SystemInformation.hxx>
+
+#include "cm_jsoncpp_value.h"
+#include "cm_jsoncpp_writer.h"
#endif
#include <cmsys/FStream.hxx>
@@ -110,6 +114,18 @@
#include <list>
+namespace {
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+#ifdef CMake_HAVE_CXX_UNORDERED_MAP
+typedef std::unordered_map<std::string, Json::Value> JsonValueMapType;
+#else
+typedef cmsys::hash_map<std::string, Json::Value> JsonValueMapType;
+#endif
+#endif
+
+} // namespace
+
static bool cmakeCheckStampFile(const char* stampName);
static bool cmakeCheckStampList(const char* stampName);
@@ -201,6 +217,68 @@ cmake::~cmake()
delete this->FileComparison;
}
+std::string cmake::ReportCapabilities() const
+{
+ std::string result;
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ Json::Value obj = Json::objectValue;
+ // Version information:
+ Json::Value version = Json::objectValue;
+ version["string"] = CMake_VERSION;
+ version["major"] = CMake_VERSION_MAJOR;
+ version["minor"] = CMake_VERSION_MINOR;
+ version["suffix"] = CMake_VERSION_SUFFIX;
+ version["isDirty"] = (CMake_VERSION_IS_DIRTY == 1);
+ version["patch"] = CMake_VERSION_PATCH;
+
+ obj["version"] = version;
+
+ // Generators:
+ std::vector<cmake::GeneratorInfo> generatorInfoList;
+ this->GetRegisteredGenerators(generatorInfoList);
+
+ JsonValueMapType generatorMap;
+ for (std::vector<cmake::GeneratorInfo>::const_iterator i =
+ generatorInfoList.begin();
+ i != generatorInfoList.end(); ++i) {
+ if (i->isAlias) { // skip aliases, they are there for compatibility reasons
+ // only
+ continue;
+ }
+
+ if (i->extraName.empty()) {
+ Json::Value gen = Json::objectValue;
+ gen["name"] = i->name;
+ gen["toolsetSupport"] = i->supportsToolset;
+ gen["platformSupport"] = i->supportsPlatform;
+ gen["extraGenerators"] = Json::arrayValue;
+ generatorMap[i->name] = gen;
+ } else {
+ Json::Value& gen = generatorMap[i->baseName];
+ gen["extraGenerators"].append(i->extraName);
+ }
+ }
+
+ Json::Value generators = Json::arrayValue;
+ for (JsonValueMapType::const_iterator i = generatorMap.begin();
+ i != generatorMap.end(); ++i) {
+ generators.append(i->second);
+ }
+ obj["generators"] = generators;
+
+#if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE
+ obj["serverMode"] = true;
+#else
+ obj["serverMode"] = false;
+#endif
+ Json::FastWriter writer;
+ result = writer.write(obj);
+#else
+ result = "Not supported";
+#endif
+ return result;
+}
+
void cmake::CleanupCommandsAndMacros()
{
this->CurrentSnapshot = this->State->Reset();
diff --git a/Source/cmake.h b/Source/cmake.h
index 5b7c54a..343d371 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -117,6 +117,8 @@ public:
/// Destructor
~cmake();
+ std::string ReportCapabilities() const;
+
static const char* GetCMakeFilesDirectory() { return "/CMakeFiles"; }
static const char* GetCMakeFilesDirectoryPostSlash()
{
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 9d0337a..be023b1 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -60,6 +60,8 @@ void CMakeCommandUsage(const char* program)
errorStream
<< "Usage: " << program << " -E <command> [arguments...]\n"
<< "Available commands: \n"
+ << " capabilities - Report capabilities built into cmake "
+ "in JSON format\n"
<< " chdir dir cmd [args...] - run command in a given directory\n"
<< " compare_files file1 file2 - check if file1 is same as file2\n"
<< " copy <file>... destination - copy files to destination "
@@ -510,6 +512,16 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
}
return 0;
}
+ // capabilities
+ else if (args[1] == "capabilities") {
+ if (args.size() > 2) {
+ std::cerr << "-E capabilities accepts no additional arguments\n";
+ return 1;
+ }
+ cmake cm;
+ std::cout << cm.ReportCapabilities();
+ return 0;
+ }
// Sleep command
else if (args[1] == "sleep" && args.size() > 2) {