1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmInstallImportedRuntimeArtifactsGenerator.h"
10 #include "cmsys/RegularExpression.hxx"
12 #include "cmGeneratorExpression.h"
13 #include "cmGeneratorTarget.h"
14 #include "cmGlobalGenerator.h"
15 #include "cmInstallType.h"
16 #include "cmListFileCache.h"
17 #include "cmLocalGenerator.h"
18 #include "cmStateTypes.h"
19 #include "cmStringAlgorithms.h"
22 const cmsys::RegularExpression FrameworkRegularExpression(
23 "^(.*/)?([^/]*)\\.framework/(.*)$");
25 const cmsys::RegularExpression BundleRegularExpression(
26 "^(.*/)?([^/]*)\\.app/(.*)$");
28 const cmsys::RegularExpression CFBundleRegularExpression(
29 "^(.*/)?([^/]*)\\.bundle/(.*)$");
32 cmInstallImportedRuntimeArtifactsGenerator::
33 cmInstallImportedRuntimeArtifactsGenerator(
34 std::string targetName, std::string const& dest,
35 std::string file_permissions,
36 std::vector<std::string> const& configurations,
37 std::string const& component, MessageLevel message, bool exclude_from_all,
38 bool optional, cmListFileBacktrace backtrace)
39 : cmInstallGenerator(dest, configurations, component, message,
40 exclude_from_all, false, std::move(backtrace))
41 , TargetName(std::move(targetName))
42 , FilePermissions(std::move(file_permissions))
45 this->ActionsPerConfig = true;
48 bool cmInstallImportedRuntimeArtifactsGenerator::Compute(cmLocalGenerator* lg)
50 // Lookup this target in the current directory.
51 this->Target = lg->FindGeneratorTargetToUse(this->TargetName);
52 if (!this->Target || !this->Target->IsImported()) {
53 // If no local target has been found, find it in the global scope.
55 lg->GetGlobalGenerator()->FindGeneratorTarget(this->TargetName);
61 std::string cmInstallImportedRuntimeArtifactsGenerator::GetDestination(
62 std::string const& config) const
64 return cmGeneratorExpression::Evaluate(
65 this->Destination, this->Target->GetLocalGenerator(), config);
68 void cmInstallImportedRuntimeArtifactsGenerator::GenerateScriptForConfig(
69 std::ostream& os, const std::string& config, Indent indent)
71 auto location = this->Target->GetFullPath(config);
73 switch (this->Target->GetType()) {
74 case cmStateEnums::EXECUTABLE:
75 if (this->Target->IsBundleOnApple()) {
76 cmsys::RegularExpressionMatch match;
77 if (BundleRegularExpression.find(location.c_str(), match)) {
78 auto bundleDir = match.match(1);
79 auto bundleName = match.match(2);
80 auto bundlePath = cmStrCat(bundleDir, bundleName, ".app");
81 this->AddInstallRule(os, this->GetDestination(config),
82 cmInstallType_DIRECTORY, { bundlePath },
83 this->Optional, nullptr,
84 this->FilePermissions.c_str(), nullptr,
85 " USE_SOURCE_PERMISSIONS", indent);
88 this->AddInstallRule(os, this->GetDestination(config),
89 cmInstallType_EXECUTABLE, { location },
90 this->Optional, this->FilePermissions.c_str(),
91 nullptr, nullptr, nullptr, indent);
94 case cmStateEnums::SHARED_LIBRARY:
95 if (this->Target->IsFrameworkOnApple()) {
96 cmsys::RegularExpressionMatch match;
97 if (FrameworkRegularExpression.find(location.c_str(), match)) {
98 auto frameworkDir = match.match(1);
99 auto frameworkName = match.match(2);
101 cmStrCat(frameworkDir, frameworkName, ".framework");
102 this->AddInstallRule(os, this->GetDestination(config),
103 cmInstallType_DIRECTORY, { frameworkPath },
104 this->Optional, nullptr,
105 this->FilePermissions.c_str(), nullptr,
106 " USE_SOURCE_PERMISSIONS", indent);
109 std::vector<std::string> files{ location };
110 auto soName = this->Target->GetSOName(config);
112 cmStrCat(this->Target->GetDirectory(config), '/', soName);
113 if (!soName.empty() && soNameFile != location) {
114 files.push_back(soNameFile);
116 this->AddInstallRule(os, this->GetDestination(config),
117 cmInstallType_SHARED_LIBRARY, files,
118 this->Optional, this->FilePermissions.c_str(),
119 nullptr, nullptr, nullptr, indent);
122 case cmStateEnums::MODULE_LIBRARY:
123 if (this->Target->IsCFBundleOnApple()) {
124 cmsys::RegularExpressionMatch match;
125 if (CFBundleRegularExpression.find(location.c_str(), match)) {
126 auto bundleDir = match.match(1);
127 auto bundleName = match.match(2);
128 auto bundlePath = cmStrCat(bundleDir, bundleName, ".bundle");
129 this->AddInstallRule(os, this->GetDestination(config),
130 cmInstallType_DIRECTORY, { bundlePath },
131 this->Optional, nullptr,
132 this->FilePermissions.c_str(), nullptr,
133 " USE_SOURCE_PERMISSIONS", indent);
136 this->AddInstallRule(os, this->GetDestination(config),
137 cmInstallType_MODULE_LIBRARY, { location },
138 this->Optional, this->FilePermissions.c_str(),
139 nullptr, nullptr, nullptr, indent);
143 assert(false && "This should never happen");