cmake/Source/cmDefinePropertyCommand.cxx

107 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
2017-04-14 19:02:05 +02:00
#include <sstream>
#include "cmMakefile.h"
#include "cmProperty.h"
2015-08-17 11:37:30 +02:00
#include "cmState.h"
2017-04-14 19:02:05 +02:00
class cmExecutionStatus;
2016-07-09 11:21:54 +02:00
bool cmDefinePropertyCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
this->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 {
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2017-07-20 19:35:53 +02:00
e << "given invalid scope " << scope_arg << ". "
<< "Valid scopes are "
<< "GLOBAL, DIRECTORY, TARGET, SOURCE, "
<< "TEST, VARIABLE, CACHED_VARIABLE.";
2015-04-27 22:25:09 +02:00
this->SetError(e.str());
return false;
2016-07-09 11:21:54 +02:00
}
// Parse remaining arguments.
bool inherited = false;
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;
this->PropertyName = args[i];
2016-07-09 11:21:54 +02:00
} else if (doing == DoingBrief) {
2009-10-04 10:30:41 +03:00
this->BriefDocs += args[i];
2016-07-09 11:21:54 +02:00
} else if (doing == DoingFull) {
2009-10-04 10:30:41 +03:00
this->FullDocs += args[i];
2016-07-09 11:21:54 +02:00
} else {
2015-04-27 22:25:09 +02:00
std::ostringstream e;
e << "given invalid argument \"" << args[i] << "\".";
2015-04-27 22:25:09 +02:00
this->SetError(e.str());
return false;
}
2016-07-09 11:21:54 +02:00
}
// Make sure a property name was found.
2016-07-09 11:21:54 +02:00
if (this->PropertyName.empty()) {
this->SetError("not given a PROPERTY <name> argument.");
return false;
2016-07-09 11:21:54 +02:00
}
// Make sure documentation was given.
2016-07-09 11:21:54 +02:00
if (this->BriefDocs.empty()) {
this->SetError("not given a BRIEF_DOCS <brief-doc> argument.");
return false;
2016-07-09 11:21:54 +02:00
}
if (this->FullDocs.empty()) {
this->SetError("not given a FULL_DOCS <full-doc> argument.");
return false;
2016-07-09 11:21:54 +02:00
}
// Actually define the property.
2016-07-09 11:21:54 +02:00
this->Makefile->GetState()->DefineProperty(
this->PropertyName, scope, this->BriefDocs.c_str(), this->FullDocs.c_str(),
inherited);
return true;
}