/src/CMake/Source/cmSetTargetPropertiesCommand.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmSetTargetPropertiesCommand.h" |
4 | | |
5 | | #include <algorithm> |
6 | | #include <iterator> |
7 | | |
8 | | #include "cmExecutionStatus.h" |
9 | | #include "cmMakefile.h" |
10 | | #include "cmStringAlgorithms.h" |
11 | | #include "cmTarget.h" |
12 | | |
13 | | bool cmSetTargetPropertiesCommand(std::vector<std::string> const& args, |
14 | | cmExecutionStatus& status) |
15 | 0 | { |
16 | 0 | if (args.size() < 2) { |
17 | 0 | status.SetError("called with incorrect number of arguments"); |
18 | 0 | return false; |
19 | 0 | } |
20 | | |
21 | | // first identify the properties arguments |
22 | 0 | auto propsIter = std::find(args.begin(), args.end(), "PROPERTIES"); |
23 | 0 | if (propsIter == args.end() || propsIter + 1 == args.end()) { |
24 | 0 | status.SetError("called with illegal arguments, maybe missing a " |
25 | 0 | "PROPERTIES specifier?"); |
26 | 0 | return false; |
27 | 0 | } |
28 | | |
29 | 0 | if (std::distance(propsIter, args.end()) % 2 != 1) { |
30 | 0 | status.SetError("called with incorrect number of arguments."); |
31 | 0 | return false; |
32 | 0 | } |
33 | | |
34 | 0 | cmMakefile& mf = status.GetMakefile(); |
35 | | |
36 | | // loop over all the targets |
37 | 0 | for (std::string const& tname : cmStringRange{ args.begin(), propsIter }) { |
38 | 0 | if (mf.IsAlias(tname)) { |
39 | 0 | status.SetError("can not be used on an ALIAS target."); |
40 | 0 | return false; |
41 | 0 | } |
42 | 0 | if (cmTarget* target = mf.FindTargetToUse(tname)) { |
43 | 0 | if (target->IsSymbolic()) { |
44 | 0 | status.SetError("can not be used on a SYMBOLIC target."); |
45 | 0 | return false; |
46 | 0 | } |
47 | | // loop through all the props and set them |
48 | 0 | for (auto k = propsIter + 1; k != args.end(); k += 2) { |
49 | 0 | target->SetProperty(*k, *(k + 1)); |
50 | 0 | target->CheckProperty(*k, &mf); |
51 | 0 | } |
52 | 0 | } else { |
53 | 0 | status.SetError( |
54 | 0 | cmStrCat("Can not find target to add properties to: ", tname)); |
55 | 0 | return false; |
56 | 0 | } |
57 | 0 | } |
58 | 0 | return true; |
59 | 0 | } |