cmake/Source/cmSourceGroupCommand.cxx

77 lines
2.3 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 "cmSourceGroupCommand.h"
// cmSourceGroupCommand
2016-07-09 11:21:54 +02:00
bool cmSourceGroupCommand::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
}
std::string delimiter = "\\";
2016-07-09 11:21:54 +02:00
if (this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER")) {
delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
std::vector<std::string> folders =
cmSystemTools::tokenize(args[0], delimiter);
2013-03-16 19:13:01 +02:00
2016-10-30 18:24:19 +01:00
cmSourceGroup* sg = CM_NULLPTR;
sg = this->Makefile->GetSourceGroup(folders);
2016-07-09 11:21:54 +02:00
if (!sg) {
this->Makefile->AddSourceGroup(folders);
sg = this->Makefile->GetSourceGroup(folders);
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
if (!sg) {
this->SetError("Could not create or find source group");
return false;
2016-07-09 11:21:54 +02:00
}
// If only two arguments are given, the pre-1.8 version of the
// command is being invoked.
2016-07-09 11:21:54 +02:00
if (args.size() == 2 && args[1] != "FILES") {
sg->SetGroupRegex(args[1].c_str());
return true;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
// Process arguments.
bool doingFiles = false;
2016-07-09 11:21:54 +02:00
for (unsigned int i = 1; i < args.size(); ++i) {
if (args[i] == "REGULAR_EXPRESSION") {
// Next argument must specify the regex.
2016-07-09 11:21:54 +02:00
if (i + 1 < args.size()) {
++i;
sg->SetGroupRegex(args[i].c_str());
2016-07-09 11:21:54 +02:00
} else {
this->SetError("REGULAR_EXPRESSION argument given without a regex.");
return false;
}
2016-07-09 11:21:54 +02:00
doingFiles = false;
} else if (args[i] == "FILES") {
// Next arguments will specify files.
doingFiles = true;
2016-07-09 11:21:54 +02:00
} else if (doingFiles) {
// Convert name to full path and add to the group's list.
2015-04-27 22:25:09 +02:00
std::string src = args[i];
2016-07-09 11:21:54 +02:00
if (!cmSystemTools::FileIsFullPath(src.c_str())) {
2015-08-17 11:37:30 +02:00
src = this->Makefile->GetCurrentSourceDirectory();
src += "/";
src += args[i];
2016-07-09 11:21:54 +02:00
}
src = cmSystemTools::CollapseFullPath(src.c_str());
2015-04-27 22:25:09 +02:00
sg->AddGroupFile(src);
2016-07-09 11:21:54 +02:00
} else {
2015-04-27 22:25:09 +02:00
std::ostringstream err;
err << "Unknown argument \"" << args[i] << "\". "
<< "Perhaps the FILES keyword is missing.\n";
2015-04-27 22:25:09 +02:00
this->SetError(err.str());
return false;
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
return true;
}