|
|
@@ -2,18 +2,17 @@
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
|
|
#include "cmSetSourceFilesPropertiesCommand.h"
|
|
|
|
|
|
+#include <algorithm>
|
|
|
+#include <iterator>
|
|
|
+
|
|
|
+#include <cm/string_view>
|
|
|
+#include <cmext/algorithm>
|
|
|
+
|
|
|
#include "cmExecutionStatus.h"
|
|
|
#include "cmMakefile.h"
|
|
|
#include "cmSourceFile.h"
|
|
|
#include "cmStringAlgorithms.h"
|
|
|
|
|
|
-static bool 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);
|
|
|
-
|
|
|
bool cmSetSourceFilesPropertiesCommand(std::vector<std::string> const& args,
|
|
|
cmExecutionStatus& status)
|
|
|
{
|
|
|
@@ -23,108 +22,64 @@ bool cmSetSourceFilesPropertiesCommand(std::vector<std::string> const& args,
|
|
|
}
|
|
|
|
|
|
// 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
|
|
|
- while (j != args.end() && *j != "ABSTRACT" && *j != "WRAP_EXCLUDE" &&
|
|
|
- *j != "GENERATED" && *j != "COMPILE_FLAGS" &&
|
|
|
- *j != "OBJECT_DEPENDS" && *j != "PROPERTIES") {
|
|
|
- numFiles++;
|
|
|
- ++j;
|
|
|
- }
|
|
|
+ static const cm::string_view propNames[] = {
|
|
|
+ "ABSTRACT", "GENERATED", "WRAP_EXCLUDE",
|
|
|
+ "COMPILE_FLAGS", "OBJECT_DEPENDS", "PROPERTIES"
|
|
|
+ };
|
|
|
+ auto propsBegin = std::find_first_of(
|
|
|
+ args.begin(), args.end(), std::begin(propNames), std::end(propNames));
|
|
|
|
|
|
- cmMakefile& mf = status.GetMakefile();
|
|
|
-
|
|
|
- // now call the worker function
|
|
|
- std::string errors;
|
|
|
- bool ret = RunCommand(&mf, args.begin(), args.begin() + numFiles,
|
|
|
- args.begin() + numFiles, args.end(), errors);
|
|
|
- if (!ret) {
|
|
|
- status.SetError(errors);
|
|
|
- }
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-static bool 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
|
|
|
- for (j = propbeg; j != propend; ++j) {
|
|
|
- // old style allows for specifier before PROPERTIES keyword
|
|
|
- if (*j == "ABSTRACT") {
|
|
|
- propertyPairs.emplace_back("ABSTRACT");
|
|
|
- propertyPairs.emplace_back("1");
|
|
|
- } else if (*j == "WRAP_EXCLUDE") {
|
|
|
- propertyPairs.emplace_back("WRAP_EXCLUDE");
|
|
|
- propertyPairs.emplace_back("1");
|
|
|
- } else if (*j == "GENERATED") {
|
|
|
- generated = true;
|
|
|
- propertyPairs.emplace_back("GENERATED");
|
|
|
+ for (auto j = propsBegin; j != args.end(); ++j) {
|
|
|
+ // consume old style options
|
|
|
+ if (*j == "ABSTRACT" || *j == "GENERATED" || *j == "WRAP_EXCLUDE") {
|
|
|
+ propertyPairs.emplace_back(*j);
|
|
|
propertyPairs.emplace_back("1");
|
|
|
} else if (*j == "COMPILE_FLAGS") {
|
|
|
propertyPairs.emplace_back("COMPILE_FLAGS");
|
|
|
++j;
|
|
|
- if (j == propend) {
|
|
|
- errors = "called with incorrect number of arguments "
|
|
|
- "COMPILE_FLAGS with no flags";
|
|
|
+ if (j == args.end()) {
|
|
|
+ status.SetError("called with incorrect number of arguments "
|
|
|
+ "COMPILE_FLAGS with no flags");
|
|
|
return false;
|
|
|
}
|
|
|
propertyPairs.push_back(*j);
|
|
|
} else if (*j == "OBJECT_DEPENDS") {
|
|
|
propertyPairs.emplace_back("OBJECT_DEPENDS");
|
|
|
++j;
|
|
|
- if (j == propend) {
|
|
|
- errors = "called with incorrect number of arguments "
|
|
|
- "OBJECT_DEPENDS with no dependencies";
|
|
|
+ if (j == args.end()) {
|
|
|
+ status.SetError("called with incorrect number of arguments "
|
|
|
+ "OBJECT_DEPENDS with no dependencies");
|
|
|
return false;
|
|
|
}
|
|
|
propertyPairs.push_back(*j);
|
|
|
} else if (*j == "PROPERTIES") {
|
|
|
- // now loop through the rest of the arguments, new style
|
|
|
- ++j;
|
|
|
- while (j != propend) {
|
|
|
- propertyPairs.push_back(*j);
|
|
|
- if (*j == "GENERATED") {
|
|
|
- ++j;
|
|
|
- if (j != propend && cmIsOn(*j)) {
|
|
|
- generated = true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- ++j;
|
|
|
- }
|
|
|
- if (j == propend) {
|
|
|
- errors = "called with incorrect number of arguments.";
|
|
|
- return false;
|
|
|
- }
|
|
|
- propertyPairs.push_back(*j);
|
|
|
- ++j;
|
|
|
+ // PROPERTIES is followed by new style prop value pairs
|
|
|
+ cmStringRange newStyleProps{ j + 1, args.end() };
|
|
|
+ if (newStyleProps.size() % 2 != 0) {
|
|
|
+ status.SetError("called with incorrect number of arguments.");
|
|
|
+ return false;
|
|
|
}
|
|
|
- // break out of the loop because j is already == end
|
|
|
+ // set newStyleProps as is.
|
|
|
+ cm::append(propertyPairs, newStyleProps);
|
|
|
+ // break out of the loop.
|
|
|
break;
|
|
|
} else {
|
|
|
- errors = "called with illegal arguments, maybe missing a "
|
|
|
- "PROPERTIES specifier?";
|
|
|
+ status.SetError("called with illegal arguments, maybe missing a "
|
|
|
+ "PROPERTIES specifier?");
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // now loop over all the files
|
|
|
- for (j = filebeg; j != fileend; ++j) {
|
|
|
+ // loop over all the files
|
|
|
+ for (const std::string& sfname : cmStringRange{ args.begin(), propsBegin }) {
|
|
|
// get the source file
|
|
|
- cmSourceFile* sf = mf->GetOrCreateSource(*j, generated);
|
|
|
- if (sf) {
|
|
|
- // now loop through all the props and set them
|
|
|
- unsigned int k;
|
|
|
- for (k = 0; k < propertyPairs.size(); k = k + 2) {
|
|
|
- sf->SetProperty(propertyPairs[k], propertyPairs[k + 1].c_str());
|
|
|
+ if (cmSourceFile* sf = status.GetMakefile().GetOrCreateSource(sfname)) {
|
|
|
+ // loop through the props and set them
|
|
|
+ for (auto k = propertyPairs.begin(); k != propertyPairs.end(); k += 2) {
|
|
|
+ sf->SetProperty(*k, (k + 1)->c_str());
|
|
|
}
|
|
|
}
|
|
|
}
|