/src/CMake/Source/cmTargetPropertyComputer.h
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 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <string> |
8 | | |
9 | | #include "cmStateTypes.h" |
10 | | #include "cmStringAlgorithms.h" |
11 | | #include "cmSystemTools.h" |
12 | | #include "cmValue.h" |
13 | | |
14 | | class cmMakefile; |
15 | | |
16 | | class cmTargetPropertyComputer |
17 | | { |
18 | | public: |
19 | | template <typename Target> |
20 | | static cmValue GetProperty(Target const* tgt, std::string const& prop, |
21 | | cmMakefile const& mf) |
22 | 0 | { |
23 | 0 | if (cmValue loc = GetLocation(tgt, prop, mf)) { |
24 | 0 | return loc; |
25 | 0 | } |
26 | 0 | if (cmSystemTools::GetFatalErrorOccurred()) { |
27 | 0 | return nullptr; |
28 | 0 | } |
29 | 0 | if (prop == "SOURCES") { |
30 | 0 | return GetSources(tgt); |
31 | 0 | } |
32 | 0 | return nullptr; |
33 | 0 | } Unexecuted instantiation: cmValue cmTargetPropertyComputer::GetProperty<cmGeneratorTarget>(cmGeneratorTarget const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmMakefile const&) Unexecuted instantiation: cmValue cmTargetPropertyComputer::GetProperty<cmTarget>(cmTarget const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmMakefile const&) |
34 | | |
35 | | private: |
36 | | static void IssueLocationPropertyError(std::string const& tgtName, |
37 | | cmMakefile const& mf); |
38 | | |
39 | | template <typename Target> |
40 | | static std::string const& ImportedLocation(Target const* tgt, |
41 | | std::string const& config); |
42 | | |
43 | | template <typename Target> |
44 | | static cmValue GetLocation(Target const* tgt, std::string const& prop, |
45 | | cmMakefile const& mf) |
46 | | |
47 | 0 | { |
48 | | // Watch for special "computed" properties that are dependent on |
49 | | // other properties or variables. Always recompute them. |
50 | 0 | if (tgt->GetType() == cmStateEnums::EXECUTABLE || |
51 | 0 | tgt->GetType() == cmStateEnums::STATIC_LIBRARY || |
52 | 0 | tgt->GetType() == cmStateEnums::SHARED_LIBRARY || |
53 | 0 | tgt->GetType() == cmStateEnums::MODULE_LIBRARY || |
54 | 0 | tgt->GetType() == cmStateEnums::UNKNOWN_LIBRARY) { |
55 | 0 | static std::string const propLOCATION = "LOCATION"; |
56 | 0 | if (prop == propLOCATION) { |
57 | 0 | if (!tgt->IsImported()) { |
58 | 0 | IssueLocationPropertyError(tgt->GetName(), mf); |
59 | 0 | return nullptr; |
60 | 0 | } |
61 | 0 | return cmValue(ImportedLocation(tgt, std::string())); |
62 | 0 | } |
63 | | |
64 | | // Support "LOCATION_<CONFIG>". |
65 | 0 | if (cmHasLiteralPrefix(prop, "LOCATION_")) { |
66 | 0 | if (!tgt->IsImported()) { |
67 | 0 | IssueLocationPropertyError(tgt->GetName(), mf); |
68 | 0 | return nullptr; |
69 | 0 | } |
70 | 0 | std::string configName = prop.substr(9); |
71 | 0 | return cmValue(ImportedLocation(tgt, configName)); |
72 | 0 | } |
73 | | |
74 | | // Support "<CONFIG>_LOCATION". |
75 | 0 | if (cmHasLiteralSuffix(prop, "_LOCATION") && |
76 | 0 | !cmHasLiteralPrefix(prop, "XCODE_ATTRIBUTE_")) { |
77 | 0 | std::string configName(prop.c_str(), prop.size() - 9); |
78 | 0 | if (configName != "IMPORTED") { |
79 | 0 | if (!tgt->IsImported()) { |
80 | 0 | IssueLocationPropertyError(tgt->GetName(), mf); |
81 | 0 | return nullptr; |
82 | 0 | } |
83 | 0 | return cmValue(ImportedLocation(tgt, configName)); |
84 | 0 | } |
85 | 0 | } |
86 | 0 | } |
87 | 0 | return nullptr; |
88 | 0 | } Unexecuted instantiation: cmValue cmTargetPropertyComputer::GetLocation<cmGeneratorTarget>(cmGeneratorTarget const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmMakefile const&) Unexecuted instantiation: cmValue cmTargetPropertyComputer::GetLocation<cmTarget>(cmTarget const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmMakefile const&) |
89 | | |
90 | | template <typename Target> |
91 | | static cmValue GetSources(Target const* tgt); |
92 | | }; |