resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmTargetPropertyComputer.h
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt 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, const std::string& prop,
21                              cmMakefile const& mf)
22   {
23     if (cmValue loc = GetLocation(tgt, prop, mf)) {
24       return loc;
25     }
26     if (cmSystemTools::GetFatalErrorOccurred()) {
27       return nullptr;
28     }
29     if (prop == "SOURCES") {
30       return GetSources(tgt, mf);
31     }
32     return nullptr;
33   }
34
35 private:
36   static bool HandleLocationPropertyPolicy(std::string const& tgtName,
37                                            cmMakefile const& mf);
38
39   template <typename Target>
40   static const std::string& ComputeLocationForBuild(Target const* tgt);
41   template <typename Target>
42   static const std::string& ComputeLocation(Target const* tgt,
43                                             std::string const& config);
44
45   template <typename Target>
46   static cmValue GetLocation(Target const* tgt, std::string const& prop,
47                              cmMakefile const& mf)
48
49   {
50     // Watch for special "computed" properties that are dependent on
51     // other properties or variables.  Always recompute them.
52     if (tgt->GetType() == cmStateEnums::EXECUTABLE ||
53         tgt->GetType() == cmStateEnums::STATIC_LIBRARY ||
54         tgt->GetType() == cmStateEnums::SHARED_LIBRARY ||
55         tgt->GetType() == cmStateEnums::MODULE_LIBRARY ||
56         tgt->GetType() == cmStateEnums::UNKNOWN_LIBRARY) {
57       static const std::string propLOCATION = "LOCATION";
58       if (prop == propLOCATION) {
59         if (!tgt->IsImported() &&
60             !HandleLocationPropertyPolicy(tgt->GetName(), mf)) {
61           return nullptr;
62         }
63         return cmValue(ComputeLocationForBuild(tgt));
64       }
65
66       // Support "LOCATION_<CONFIG>".
67       if (cmHasLiteralPrefix(prop, "LOCATION_")) {
68         if (!tgt->IsImported() &&
69             !HandleLocationPropertyPolicy(tgt->GetName(), mf)) {
70           return nullptr;
71         }
72         std::string configName = prop.substr(9);
73         return cmValue(ComputeLocation(tgt, configName));
74       }
75
76       // Support "<CONFIG>_LOCATION".
77       if (cmHasLiteralSuffix(prop, "_LOCATION") &&
78           !cmHasLiteralPrefix(prop, "XCODE_ATTRIBUTE_")) {
79         std::string configName(prop.c_str(), prop.size() - 9);
80         if (configName != "IMPORTED") {
81           if (!tgt->IsImported() &&
82               !HandleLocationPropertyPolicy(tgt->GetName(), mf)) {
83             return nullptr;
84           }
85           return cmValue(ComputeLocation(tgt, configName));
86         }
87       }
88     }
89     return nullptr;
90   }
91
92   template <typename Target>
93   static cmValue GetSources(Target const* tgt, cmMakefile const& mf);
94 };