cmake/Source/cmSetTargetPropertiesCommand.cxx

56 lines
1.7 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 "cmSetTargetPropertiesCommand.h"
2016-07-09 11:21:54 +02:00
2020-08-30 11:54:41 +02:00
#include <algorithm>
2017-04-14 19:02:05 +02:00
#include <iterator>
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2017-04-14 19:02:05 +02:00
#include "cmTarget.h"
2020-02-01 23:06:01 +01:00
bool cmSetTargetPropertiesCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 2) {
2020-02-01 23:06:01 +01:00
status.SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
// first identify the properties arguments
auto propsIter = std::find(args.begin(), args.end(), "PROPERTIES");
if (propsIter == args.end() || propsIter + 1 == args.end()) {
status.SetError("called with illegal arguments, maybe missing a "
"PROPERTIES specifier?");
return false;
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
if (std::distance(propsIter, args.end()) % 2 != 1) {
status.SetError("called with incorrect number of arguments.");
2016-07-09 11:21:54 +02:00
return false;
}
2013-03-16 19:13:01 +02:00
2020-02-01 23:06:01 +01:00
cmMakefile& mf = status.GetMakefile();
2020-08-30 11:54:41 +02:00
// loop over all the targets
for (const std::string& tname : cmStringRange{ args.begin(), propsIter }) {
if (mf.IsAlias(tname)) {
2020-02-01 23:06:01 +01:00
status.SetError("can not be used on an ALIAS target.");
2013-11-03 12:27:13 +02:00
return false;
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
if (cmTarget* target = mf.FindTargetToUse(tname)) {
// loop through all the props and set them
for (auto k = propsIter + 1; k != args.end(); k += 2) {
target->SetProperty(*k, *(k + 1));
target->CheckProperty(*k, &mf);
}
} else {
2020-02-01 23:06:01 +01:00
status.SetError(
2020-08-30 11:54:41 +02:00
cmStrCat("Can not find target to add properties to: ", tname));
return false;
}
2016-07-09 11:21:54 +02:00
}
return true;
}