cmake/Source/cmDefinePropertyCommand.cxx

102 lines
2.9 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmDefinePropertyCommand.h"
2016-07-09 11:21:54 +02:00
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
#include "cmProperty.h"
2015-08-17 11:37:30 +02:00
#include "cmState.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2017-04-14 19:02:05 +02:00
2020-02-01 23:06:01 +01:00
bool cmDefinePropertyCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
2020-02-01 23:06:01 +01:00
status.SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
// Get the scope in which to define the property.
cmProperty::ScopeType scope;
2017-07-20 19:35:53 +02:00
std::string const& scope_arg = args[0];
if (scope_arg == "GLOBAL") {
scope = cmProperty::GLOBAL;
2017-07-20 19:35:53 +02:00
} else if (scope_arg == "DIRECTORY") {
scope = cmProperty::DIRECTORY;
2017-07-20 19:35:53 +02:00
} else if (scope_arg == "TARGET") {
scope = cmProperty::TARGET;
2017-07-20 19:35:53 +02:00
} else if (scope_arg == "SOURCE") {
scope = cmProperty::SOURCE_FILE;
2017-07-20 19:35:53 +02:00
} else if (scope_arg == "TEST") {
scope = cmProperty::TEST;
2017-07-20 19:35:53 +02:00
} else if (scope_arg == "VARIABLE") {
scope = cmProperty::VARIABLE;
2017-07-20 19:35:53 +02:00
} else if (scope_arg == "CACHED_VARIABLE") {
scope = cmProperty::CACHED_VARIABLE;
2016-07-09 11:21:54 +02:00
} else {
2020-02-01 23:06:01 +01:00
status.SetError(cmStrCat("given invalid scope ", scope_arg,
". Valid scopes are GLOBAL, DIRECTORY, TARGET, "
"SOURCE, TEST, VARIABLE, CACHED_VARIABLE."));
return false;
2016-07-09 11:21:54 +02:00
}
// Parse remaining arguments.
bool inherited = false;
2020-02-01 23:06:01 +01:00
std::string PropertyName;
std::string BriefDocs;
std::string FullDocs;
2016-07-09 11:21:54 +02:00
enum Doing
{
DoingNone,
DoingProperty,
DoingBrief,
DoingFull
};
Doing doing = DoingNone;
2016-07-09 11:21:54 +02:00
for (unsigned int i = 1; i < args.size(); ++i) {
if (args[i] == "PROPERTY") {
doing = DoingProperty;
2016-07-09 11:21:54 +02:00
} else if (args[i] == "BRIEF_DOCS") {
doing = DoingBrief;
2016-07-09 11:21:54 +02:00
} else if (args[i] == "FULL_DOCS") {
doing = DoingFull;
2016-07-09 11:21:54 +02:00
} else if (args[i] == "INHERITED") {
doing = DoingNone;
inherited = true;
2016-07-09 11:21:54 +02:00
} else if (doing == DoingProperty) {
doing = DoingNone;
2020-02-01 23:06:01 +01:00
PropertyName = args[i];
2016-07-09 11:21:54 +02:00
} else if (doing == DoingBrief) {
2020-02-01 23:06:01 +01:00
BriefDocs += args[i];
2016-07-09 11:21:54 +02:00
} else if (doing == DoingFull) {
2020-02-01 23:06:01 +01:00
FullDocs += args[i];
2016-07-09 11:21:54 +02:00
} else {
2020-02-01 23:06:01 +01:00
status.SetError(cmStrCat("given invalid argument \"", args[i], "\"."));
return false;
}
2016-07-09 11:21:54 +02:00
}
// Make sure a property name was found.
2020-02-01 23:06:01 +01:00
if (PropertyName.empty()) {
status.SetError("not given a PROPERTY <name> argument.");
return false;
2016-07-09 11:21:54 +02:00
}
// Make sure documentation was given.
2020-02-01 23:06:01 +01:00
if (BriefDocs.empty()) {
status.SetError("not given a BRIEF_DOCS <brief-doc> argument.");
return false;
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
if (FullDocs.empty()) {
status.SetError("not given a FULL_DOCS <full-doc> argument.");
return false;
2016-07-09 11:21:54 +02:00
}
// Actually define the property.
2020-02-01 23:06:01 +01:00
status.GetMakefile().GetState()->DefineProperty(
2020-08-30 11:54:41 +02:00
PropertyName, scope, BriefDocs, FullDocs, inherited);
return true;
}