1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
9 #include "cmStateTypes.h"
10 #include "cmStringAlgorithms.h"
11 #include "cmSystemTools.h"
16 class cmTargetPropertyComputer
19 template <typename Target>
20 static cmValue GetProperty(Target const* tgt, const std::string& prop,
23 if (cmValue loc = GetLocation(tgt, prop, mf)) {
26 if (cmSystemTools::GetFatalErrorOccurred()) {
29 if (prop == "SOURCES") {
30 return GetSources(tgt, mf);
36 static bool HandleLocationPropertyPolicy(std::string const& tgtName,
37 cmMakefile const& mf);
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);
45 template <typename Target>
46 static cmValue GetLocation(Target const* tgt, std::string const& prop,
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)) {
63 return cmValue(ComputeLocationForBuild(tgt));
66 // Support "LOCATION_<CONFIG>".
67 if (cmHasLiteralPrefix(prop, "LOCATION_")) {
68 if (!tgt->IsImported() &&
69 !HandleLocationPropertyPolicy(tgt->GetName(), mf)) {
72 std::string configName = prop.substr(9);
73 return cmValue(ComputeLocation(tgt, configName));
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)) {
85 return cmValue(ComputeLocation(tgt, configName));
92 template <typename Target>
93 static cmValue GetSources(Target const* tgt, cmMakefile const& mf);