/src/CMake/Source/cmInstallImportedRuntimeArtifactsGenerator.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 "cmInstallImportedRuntimeArtifactsGenerator.h" |
4 | | |
5 | | #include <cassert> |
6 | | #include <string> |
7 | | #include <utility> |
8 | | #include <vector> |
9 | | |
10 | | #include "cmsys/RegularExpression.hxx" |
11 | | |
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" |
20 | | |
21 | | namespace { |
22 | | cmsys::RegularExpression const FrameworkRegularExpression( |
23 | | "^(.*/)?([^/]*)\\.framework/(.*)$"); |
24 | | |
25 | | cmsys::RegularExpression const BundleRegularExpression( |
26 | | "^(.*/)?([^/]*)\\.app/(.*)$"); |
27 | | |
28 | | cmsys::RegularExpression const CFBundleRegularExpression( |
29 | | "^(.*/)?([^/]*)\\.bundle/(.*)$"); |
30 | | } |
31 | | |
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 | 0 | : cmInstallGenerator(dest, configurations, component, message, |
40 | 0 | exclude_from_all, false, std::move(backtrace)) |
41 | 0 | , TargetName(std::move(targetName)) |
42 | 0 | , FilePermissions(std::move(file_permissions)) |
43 | 0 | , Optional(optional) |
44 | 0 | { |
45 | 0 | this->ActionsPerConfig = true; |
46 | 0 | } |
47 | | |
48 | | bool cmInstallImportedRuntimeArtifactsGenerator::Compute(cmLocalGenerator* lg) |
49 | 0 | { |
50 | | // Lookup this target in the current directory. |
51 | 0 | this->Target = lg->FindGeneratorTargetToUse(this->TargetName); |
52 | 0 | if (!this->Target || !this->Target->IsImported()) { |
53 | | // If no local target has been found, find it in the global scope. |
54 | 0 | this->Target = |
55 | 0 | lg->GetGlobalGenerator()->FindGeneratorTarget(this->TargetName); |
56 | 0 | } |
57 | |
|
58 | 0 | return true; |
59 | 0 | } |
60 | | |
61 | | std::string cmInstallImportedRuntimeArtifactsGenerator::GetDestination( |
62 | | std::string const& config) const |
63 | 0 | { |
64 | 0 | return cmGeneratorExpression::Evaluate( |
65 | 0 | this->Destination, this->Target->GetLocalGenerator(), config); |
66 | 0 | } |
67 | | |
68 | | void cmInstallImportedRuntimeArtifactsGenerator::GenerateScriptForConfig( |
69 | | std::ostream& os, std::string const& config, Indent indent) |
70 | 0 | { |
71 | 0 | auto location = this->Target->GetFullPath(config); |
72 | |
|
73 | 0 | switch (this->Target->GetType()) { |
74 | 0 | case cmStateEnums::EXECUTABLE: |
75 | 0 | if (this->Target->IsBundleOnApple()) { |
76 | 0 | cmsys::RegularExpressionMatch match; |
77 | 0 | if (BundleRegularExpression.find(location.c_str(), match)) { |
78 | 0 | auto bundleDir = match.match(1); |
79 | 0 | auto bundleName = match.match(2); |
80 | 0 | auto bundlePath = cmStrCat(bundleDir, bundleName, ".app"); |
81 | 0 | this->AddInstallRule(os, this->GetDestination(config), |
82 | 0 | cmInstallType_DIRECTORY, { bundlePath }, |
83 | 0 | this->Optional, nullptr, |
84 | 0 | this->FilePermissions.c_str(), nullptr, |
85 | 0 | " USE_SOURCE_PERMISSIONS", indent); |
86 | 0 | } |
87 | 0 | } else { |
88 | 0 | this->AddInstallRule(os, this->GetDestination(config), |
89 | 0 | cmInstallType_EXECUTABLE, { location }, |
90 | 0 | this->Optional, this->FilePermissions.c_str(), |
91 | 0 | nullptr, nullptr, nullptr, indent); |
92 | 0 | } |
93 | 0 | break; |
94 | 0 | case cmStateEnums::SHARED_LIBRARY: |
95 | 0 | if (this->Target->IsFrameworkOnApple()) { |
96 | 0 | cmsys::RegularExpressionMatch match; |
97 | 0 | if (FrameworkRegularExpression.find(location.c_str(), match)) { |
98 | 0 | auto frameworkDir = match.match(1); |
99 | 0 | auto frameworkName = match.match(2); |
100 | 0 | auto frameworkPath = |
101 | 0 | cmStrCat(frameworkDir, frameworkName, ".framework"); |
102 | 0 | this->AddInstallRule(os, this->GetDestination(config), |
103 | 0 | cmInstallType_DIRECTORY, { frameworkPath }, |
104 | 0 | this->Optional, nullptr, |
105 | 0 | this->FilePermissions.c_str(), nullptr, |
106 | 0 | " USE_SOURCE_PERMISSIONS", indent); |
107 | 0 | } |
108 | 0 | } else { |
109 | 0 | std::vector<std::string> files{ location }; |
110 | 0 | if (!this->Target->IsArchivedAIXSharedLibrary()) { |
111 | 0 | auto soName = this->Target->GetSOName(config); |
112 | 0 | auto soNameFile = |
113 | 0 | cmStrCat(this->Target->GetDirectory(config), '/', soName); |
114 | 0 | if (!soName.empty() && soNameFile != location) { |
115 | 0 | files.push_back(soNameFile); |
116 | 0 | } |
117 | 0 | } |
118 | 0 | this->AddInstallRule(os, this->GetDestination(config), |
119 | 0 | cmInstallType_SHARED_LIBRARY, files, |
120 | 0 | this->Optional, this->FilePermissions.c_str(), |
121 | 0 | nullptr, nullptr, nullptr, indent); |
122 | 0 | } |
123 | 0 | break; |
124 | 0 | case cmStateEnums::MODULE_LIBRARY: |
125 | 0 | if (this->Target->IsCFBundleOnApple()) { |
126 | 0 | cmsys::RegularExpressionMatch match; |
127 | 0 | if (CFBundleRegularExpression.find(location.c_str(), match)) { |
128 | 0 | auto bundleDir = match.match(1); |
129 | 0 | auto bundleName = match.match(2); |
130 | 0 | auto bundlePath = cmStrCat(bundleDir, bundleName, ".bundle"); |
131 | 0 | this->AddInstallRule(os, this->GetDestination(config), |
132 | 0 | cmInstallType_DIRECTORY, { bundlePath }, |
133 | 0 | this->Optional, nullptr, |
134 | 0 | this->FilePermissions.c_str(), nullptr, |
135 | 0 | " USE_SOURCE_PERMISSIONS", indent); |
136 | 0 | } |
137 | 0 | } else { |
138 | 0 | this->AddInstallRule(os, this->GetDestination(config), |
139 | 0 | cmInstallType_MODULE_LIBRARY, { location }, |
140 | 0 | this->Optional, this->FilePermissions.c_str(), |
141 | 0 | nullptr, nullptr, nullptr, indent); |
142 | 0 | } |
143 | 0 | break; |
144 | 0 | default: |
145 | | assert(false && "This should never happen"); |
146 | 0 | break; |
147 | 0 | } |
148 | 0 | } |