summaryrefslogtreecommitdiff
path: root/Source/cmSetSourceFilesPropertiesCommand.cxx
diff options
context:
space:
mode:
authorTushar Maheshwari <tushar27192@gmail.com>2020-05-09 17:57:16 +0530
committerBrad King <brad.king@kitware.com>2020-05-12 06:59:00 -0400
commit300bf4e94f9c994188e775ec1e2430f6ba200b78 (patch)
tree4c690d88e04d10d30b28f68c78e25b24c47b4c1a /Source/cmSetSourceFilesPropertiesCommand.cxx
parent8afac758e6e793a0f004ce2693b0096362391cd9 (diff)
downloadcmake-300bf4e94f9c994188e775ec1e2430f6ba200b78.tar.gz
set_*_properties: simplify and shorten implementations
Optimize argument copies and range traversal. Inline the single use file static functions.
Diffstat (limited to 'Source/cmSetSourceFilesPropertiesCommand.cxx')
-rw-r--r--Source/cmSetSourceFilesPropertiesCommand.cxx121
1 files changed, 38 insertions, 83 deletions
diff --git a/Source/cmSetSourceFilesPropertiesCommand.cxx b/Source/cmSetSourceFilesPropertiesCommand.cxx
index 7ff604be0f..7a53a1dc04 100644
--- a/Source/cmSetSourceFilesPropertiesCommand.cxx
+++ b/Source/cmSetSourceFilesPropertiesCommand.cxx
@@ -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());
}
}
}