ENH: add ability to get documentaiton of a property from a script
This commit is contained in:
parent
c2f0aac146
commit
f72d666a7b
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "cmake.h"
|
#include "cmake.h"
|
||||||
#include "cmTest.h"
|
#include "cmTest.h"
|
||||||
|
#include "cmPropertyDefinition.h"
|
||||||
|
|
||||||
// cmGetPropertyCommand
|
// cmGetPropertyCommand
|
||||||
bool cmGetPropertyCommand::InitialPass(
|
bool cmGetPropertyCommand::InitialPass(
|
||||||
|
@ -31,33 +32,51 @@ bool cmGetPropertyCommand::InitialPass(
|
||||||
|
|
||||||
// the last argument in the property to get
|
// the last argument in the property to get
|
||||||
const char *property = args[args.size()-1].c_str();
|
const char *property = args[args.size()-1].c_str();
|
||||||
|
bool get_brief = false;
|
||||||
|
if (!strcmp(property,"BRIEF_DOCS"))
|
||||||
|
{
|
||||||
|
get_brief = true;
|
||||||
|
property = args[args.size()-2].c_str();
|
||||||
|
}
|
||||||
|
bool get_full = false;
|
||||||
|
if (!strcmp(property,"FULL_DOCS"))
|
||||||
|
{
|
||||||
|
get_full = true;
|
||||||
|
property = args[args.size()-2].c_str();
|
||||||
|
}
|
||||||
|
|
||||||
std::string output = "NOTFOUND";
|
std::string output = "NOTFOUND";
|
||||||
|
|
||||||
cmProperty::ScopeType scope;
|
cmProperty::ScopeType scope;
|
||||||
const char *scopeName = 0;
|
const char *scopeName = 0;
|
||||||
if (args[1] == "GLOBAL" && args.size() == 3)
|
if (args[1] == "GLOBAL")
|
||||||
{
|
{
|
||||||
scope = cmProperty::GLOBAL;
|
scope = cmProperty::GLOBAL;
|
||||||
}
|
}
|
||||||
|
else if (args[1] == "VARIABLE")
|
||||||
|
{
|
||||||
|
scope = cmProperty::VARIABLE;
|
||||||
|
}
|
||||||
else if (args[1] == "DIRECTORY" && args.size() >= 3)
|
else if (args[1] == "DIRECTORY" && args.size() >= 3)
|
||||||
{
|
{
|
||||||
scope = cmProperty::DIRECTORY;
|
scope = cmProperty::DIRECTORY;
|
||||||
if (args.size() >= 4)
|
if ((args.size() == 4 && !get_brief && !get_full) ||
|
||||||
|
(args.size() == 5 && (get_brief || get_full)))
|
||||||
{
|
{
|
||||||
scopeName = args[2].c_str();
|
scopeName = args[2].c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (args[1] == "TARGET" && args.size() == 4)
|
else if (args[1] == "TARGET" && args.size() >= 4)
|
||||||
{
|
{
|
||||||
scope = cmProperty::TARGET;
|
scope = cmProperty::TARGET;
|
||||||
scopeName = args[2].c_str();
|
scopeName = args[2].c_str();
|
||||||
}
|
}
|
||||||
else if (args[1] == "TEST" && args.size() == 4)
|
else if (args[1] == "TEST" && args.size() >= 4)
|
||||||
{
|
{
|
||||||
scope = cmProperty::TEST;
|
scope = cmProperty::TEST;
|
||||||
scopeName = args[2].c_str();
|
scopeName = args[2].c_str();
|
||||||
}
|
}
|
||||||
else if (args[1] == "SOURCE_FILE" && args.size() == 4)
|
else if (args[1] == "SOURCE_FILE" && args.size() >= 4)
|
||||||
{
|
{
|
||||||
scope = cmProperty::SOURCE_FILE;
|
scope = cmProperty::SOURCE_FILE;
|
||||||
scopeName = args[2].c_str();
|
scopeName = args[2].c_str();
|
||||||
|
@ -68,8 +87,37 @@ bool cmGetPropertyCommand::InitialPass(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (scope)
|
if (get_brief)
|
||||||
{
|
{
|
||||||
|
cmPropertyDefinition *def =
|
||||||
|
this->Makefile->GetCMakeInstance()->
|
||||||
|
GetPropertyDefinition(property,scope);
|
||||||
|
if (def)
|
||||||
|
{
|
||||||
|
output = def->GetShortDescription();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (get_full)
|
||||||
|
{
|
||||||
|
cmPropertyDefinition *def =
|
||||||
|
this->Makefile->GetCMakeInstance()->
|
||||||
|
GetPropertyDefinition(property,scope);
|
||||||
|
if (def)
|
||||||
|
{
|
||||||
|
output = def->GetFullDescription();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else switch (scope)
|
||||||
|
{
|
||||||
|
case cmProperty::VARIABLE:
|
||||||
|
{
|
||||||
|
if (this->Makefile->GetDefinition(property))
|
||||||
|
{
|
||||||
|
output = this->Makefile->GetDefinition(property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case cmProperty::TARGET:
|
case cmProperty::TARGET:
|
||||||
{
|
{
|
||||||
cmTarget *tgt = this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
|
cmTarget *tgt = this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
|
||||||
|
@ -152,7 +200,6 @@ bool cmGetPropertyCommand::InitialPass(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case cmProperty::VARIABLE:
|
|
||||||
case cmProperty::CACHED_VARIABLE:
|
case cmProperty::CACHED_VARIABLE:
|
||||||
// not handled by GetProperty
|
// not handled by GetProperty
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -58,11 +58,17 @@ public:
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
" get_property(VAR scope_value property)\n"
|
" get_property(VAR scope_value property)\n"
|
||||||
|
" get_property(VAR scope_value property \n"
|
||||||
|
" BRIEF_DOCS)\n"
|
||||||
|
" get_property(VAR scope_value property \n"
|
||||||
|
" FULL_DOCS)\n"
|
||||||
"Get a property from cmake. The scope_value is either GLOBAL, "
|
"Get a property from cmake. The scope_value is either GLOBAL, "
|
||||||
"DIRECTORY dir_name, TARGET tgt_name, SOURCE_FILE src_name, "
|
"DIRECTORY dir_name, TARGET tgt_name, SOURCE_FILE src_name, "
|
||||||
"or TEST test_name. The resulting value is "
|
"TEST test_name or VARIABLE var_name. The resulting value is "
|
||||||
"stored in the variable VAR. If the property is not found, "
|
"stored in the variable VAR. If the property is not found, "
|
||||||
"CMake will report an error.";
|
"CMake will report an error. The second and third signatures "
|
||||||
|
"return the documentation for a property or variable instead of "
|
||||||
|
"its value.";
|
||||||
}
|
}
|
||||||
|
|
||||||
cmTypeMacro(cmGetPropertyCommand, cmCommand);
|
cmTypeMacro(cmGetPropertyCommand, cmCommand);
|
||||||
|
|
|
@ -46,6 +46,12 @@ public:
|
||||||
cmProperty::ScopeType GetScope() const {
|
cmProperty::ScopeType GetScope() const {
|
||||||
return this->Scope; };
|
return this->Scope; };
|
||||||
|
|
||||||
|
// get the docs
|
||||||
|
const std::string &GetShortDescription() const {
|
||||||
|
return this->ShortDescription; };
|
||||||
|
const std::string &GetFullDescription() const {
|
||||||
|
return this->FullDescription; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string Name;
|
std::string Name;
|
||||||
std::string ShortDescription;
|
std::string ShortDescription;
|
||||||
|
|
|
@ -3093,6 +3093,17 @@ void cmake::DefineProperty(const char *name, cmProperty::ScopeType scope,
|
||||||
chained);
|
chained);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmPropertyDefinition *cmake
|
||||||
|
::GetPropertyDefinition(const char *name,
|
||||||
|
cmProperty::ScopeType scope)
|
||||||
|
{
|
||||||
|
if (this->IsPropertyDefined(name,scope))
|
||||||
|
{
|
||||||
|
return &(this->PropertyDefinitions[scope][name]);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool cmake::IsPropertyDefined(const char *name, cmProperty::ScopeType scope)
|
bool cmake::IsPropertyDefined(const char *name, cmProperty::ScopeType scope)
|
||||||
{
|
{
|
||||||
return this->PropertyDefinitions[scope].IsPropertyDefined(name);
|
return this->PropertyDefinitions[scope].IsPropertyDefined(name);
|
||||||
|
|
|
@ -312,6 +312,10 @@ class cmake
|
||||||
bool chain = false,
|
bool chain = false,
|
||||||
const char *variableGroup = 0);
|
const char *variableGroup = 0);
|
||||||
|
|
||||||
|
// get property definition
|
||||||
|
cmPropertyDefinition *GetPropertyDefinition
|
||||||
|
(const char *name, cmProperty::ScopeType scope);
|
||||||
|
|
||||||
// Is a property defined?
|
// Is a property defined?
|
||||||
bool IsPropertyDefined(const char *name, cmProperty::ScopeType scope);
|
bool IsPropertyDefined(const char *name, cmProperty::ScopeType scope);
|
||||||
bool IsPropertyChained(const char *name, cmProperty::ScopeType scope);
|
bool IsPropertyChained(const char *name, cmProperty::ScopeType scope);
|
||||||
|
|
Loading…
Reference in New Issue