cmake/Source/cmSetSourceFilesPropertiesCommand.cxx

126 lines
3.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 "cmSetSourceFilesPropertiesCommand.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
#include "cmSourceFile.h"
2017-04-14 19:02:05 +02:00
#include "cmSystemTools.h"
class cmExecutionStatus;
// cmSetSourceFilesPropertiesCommand
2016-07-09 11:21:54 +02:00
bool cmSetSourceFilesPropertiesCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 2) {
this->SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
// break the arguments into source file names and properties
int numFiles = 0;
std::vector<std::string>::const_iterator j;
j = args.begin();
// old style allows for specifier before PROPERTIES keyword
2016-07-09 11:21:54 +02:00
while (j != args.end() && *j != "ABSTRACT" && *j != "WRAP_EXCLUDE" &&
*j != "GENERATED" && *j != "COMPILE_FLAGS" &&
*j != "OBJECT_DEPENDS" && *j != "PROPERTIES") {
numFiles++;
++j;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
// now call the worker function
std::string errors;
2016-07-09 11:21:54 +02:00
bool ret = cmSetSourceFilesPropertiesCommand::RunCommand(
this->Makefile, args.begin(), args.begin() + numFiles,
args.begin() + numFiles, args.end(), errors);
if (!ret) {
2015-04-27 22:25:09 +02:00
this->SetError(errors);
2016-07-09 11:21:54 +02:00
}
return ret;
}
2016-07-09 11:21:54 +02:00
bool cmSetSourceFilesPropertiesCommand::RunCommand(
cmMakefile* mf, std::vector<std::string>::const_iterator filebeg,
std::vector<std::string>::const_iterator fileend,
std::vector<std::string>::const_iterator propbeg,
std::vector<std::string>::const_iterator propend, std::string& errors)
{
std::vector<std::string> propertyPairs;
bool generated = false;
std::vector<std::string>::const_iterator j;
// build the property pairs
2016-07-09 11:21:54 +02:00
for (j = propbeg; j != propend; ++j) {
// old style allows for specifier before PROPERTIES keyword
2016-07-09 11:21:54 +02:00
if (*j == "ABSTRACT") {
propertyPairs.push_back("ABSTRACT");
propertyPairs.push_back("1");
2016-07-09 11:21:54 +02:00
} else if (*j == "WRAP_EXCLUDE") {
propertyPairs.push_back("WRAP_EXCLUDE");
propertyPairs.push_back("1");
2016-07-09 11:21:54 +02:00
} else if (*j == "GENERATED") {
generated = true;
propertyPairs.push_back("GENERATED");
propertyPairs.push_back("1");
2016-07-09 11:21:54 +02:00
} else if (*j == "COMPILE_FLAGS") {
propertyPairs.push_back("COMPILE_FLAGS");
++j;
2016-07-09 11:21:54 +02:00
if (j == propend) {
errors = "called with incorrect number of arguments "
2016-07-09 11:21:54 +02:00
"COMPILE_FLAGS with no flags";
return false;
}
2016-07-09 11:21:54 +02:00
propertyPairs.push_back(*j);
} else if (*j == "OBJECT_DEPENDS") {
propertyPairs.push_back("OBJECT_DEPENDS");
++j;
2016-07-09 11:21:54 +02:00
if (j == propend) {
errors = "called with incorrect number of arguments "
2016-07-09 11:21:54 +02:00
"OBJECT_DEPENDS with no dependencies";
return false;
}
2016-07-09 11:21:54 +02:00
propertyPairs.push_back(*j);
} else if (*j == "PROPERTIES") {
// now loop through the rest of the arguments, new style
++j;
2016-07-09 11:21:54 +02:00
while (j != propend) {
propertyPairs.push_back(*j);
2016-07-09 11:21:54 +02:00
if (*j == "GENERATED") {
++j;
2016-07-09 11:21:54 +02:00
if (j != propend && cmSystemTools::IsOn(j->c_str())) {
generated = true;
}
2016-07-09 11:21:54 +02:00
} else {
++j;
2016-07-09 11:21:54 +02:00
}
if (j == propend) {
errors = "called with incorrect number of arguments.";
return false;
2016-07-09 11:21:54 +02:00
}
propertyPairs.push_back(*j);
++j;
2016-07-09 11:21:54 +02:00
}
// break out of the loop because j is already == end
break;
2016-07-09 11:21:54 +02:00
} else {
errors = "called with illegal arguments, maybe missing a "
2016-07-09 11:21:54 +02:00
"PROPERTIES specifier?";
return false;
}
2016-07-09 11:21:54 +02:00
}
// now loop over all the files
2016-07-09 11:21:54 +02:00
for (j = filebeg; j != fileend; ++j) {
// get the source file
2016-07-09 11:21:54 +02:00
cmSourceFile* sf = mf->GetOrCreateSource(*j, generated);
if (sf) {
// now loop through all the props and set them
unsigned int k;
2016-07-09 11:21:54 +02:00
for (k = 0; k < propertyPairs.size(); k = k + 2) {
sf->SetProperty(propertyPairs[k], propertyPairs[k + 1].c_str());
}
}
2016-07-09 11:21:54 +02:00
}
return true;
}