diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2016-06-30 13:38:44 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-08-16 17:45:05 (GMT) |
commit | 49ad7f9af84dd46e5527e6fefaa47d8bde748bca (patch) | |
tree | 2b12ae61ca840d2b6581f3ccbf12296cffc5e6b7 /Source/cmake.cxx | |
parent | 1d408dc10f492d060b8b9546c3ed3521d7051fd8 (diff) | |
download | CMake-49ad7f9af84dd46e5527e6fefaa47d8bde748bca.zip CMake-49ad7f9af84dd46e5527e6fefaa47d8bde748bca.tar.gz CMake-49ad7f9af84dd46e5527e6fefaa47d8bde748bca.tar.bz2 |
cmake: Add `cmake -E capabilities` mode
Add `cmake -E capabilities` to report on generators, cmake version and
possibly other static capabilities of cmake.
Closes: #15462
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r-- | Source/cmake.cxx | 78 |
1 files changed, 78 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(); |