diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2021-05-19 14:29:17 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2021-06-04 12:52:01 (GMT) |
commit | f2617cf8e6aca6ec0f8c7df6999c1f713c6d7474 (patch) | |
tree | a6474fcf1e26db8e014161e15d1680b4a421a656 | |
parent | 9f6cfe716918d7c28ddc906c49b75b922e36a8cf (diff) | |
download | CMake-f2617cf8e6aca6ec0f8c7df6999c1f713c6d7474.zip CMake-f2617cf8e6aca6ec0f8c7df6999c1f713c6d7474.tar.gz CMake-f2617cf8e6aca6ec0f8c7df6999c1f713c6d7474.tar.bz2 |
Source: Add cmInstallRuntimeDependencySet
-rw-r--r-- | Source/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 24 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 11 | ||||
-rw-r--r-- | Source/cmInstallRuntimeDependencySet.cxx | 95 | ||||
-rw-r--r-- | Source/cmInstallRuntimeDependencySet.h | 163 | ||||
-rwxr-xr-x | bootstrap | 1 |
6 files changed, 296 insertions, 0 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 844a2ee..5bcf223 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -352,6 +352,8 @@ set(SRCS cmInstallFilesGenerator.cxx cmInstallImportedRuntimeArtifactsGenerator.h cmInstallImportedRuntimeArtifactsGenerator.cxx + cmInstallRuntimeDependencySet.h + cmInstallRuntimeDependencySet.cxx cmInstallScriptGenerator.h cmInstallScriptGenerator.cxx cmInstallSubdirectoryGenerator.h diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index d7da0d3..9193778 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -36,6 +36,7 @@ #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmInstallGenerator.h" +#include "cmInstallRuntimeDependencySet.h" #include "cmLinkLineComputer.h" #include "cmListFileCache.h" #include "cmLocalGenerator.h" @@ -3332,3 +3333,26 @@ bool cmGlobalGenerator::GenerateCPackPropertiesFile() return true; } + +cmInstallRuntimeDependencySet* +cmGlobalGenerator::CreateAnonymousRuntimeDependencySet() +{ + auto set = cm::make_unique<cmInstallRuntimeDependencySet>(); + auto* retval = set.get(); + this->RuntimeDependencySets.push_back(std::move(set)); + return retval; +} + +cmInstallRuntimeDependencySet* cmGlobalGenerator::GetNamedRuntimeDependencySet( + const std::string& name) +{ + auto it = this->RuntimeDependencySetsByName.find(name); + if (it == this->RuntimeDependencySetsByName.end()) { + auto set = cm::make_unique<cmInstallRuntimeDependencySet>(name); + it = + this->RuntimeDependencySetsByName.insert(std::make_pair(name, set.get())) + .first; + this->RuntimeDependencySets.push_back(std::move(set)); + } + return it->second; +} diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index fee0359..147146e 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -42,6 +42,7 @@ class cmDirectoryId; class cmExportBuildFileGenerator; class cmExternalMakefileProjectGenerator; class cmGeneratorTarget; +class cmInstallRuntimeDependencySet; class cmLinkLineComputer; class cmLocalGenerator; class cmMakefile; @@ -528,6 +529,11 @@ public: std::string NewDeferId(); + cmInstallRuntimeDependencySet* CreateAnonymousRuntimeDependencySet(); + + cmInstallRuntimeDependencySet* GetNamedRuntimeDependencySet( + const std::string& name); + protected: // for a project collect all its targets by following depend // information, and also collect all the targets @@ -747,6 +753,11 @@ private: std::unordered_set<std::string> GeneratedFiles; + std::vector<std::unique_ptr<cmInstallRuntimeDependencySet>> + RuntimeDependencySets; + std::map<std::string, cmInstallRuntimeDependencySet*> + RuntimeDependencySetsByName; + #if !defined(CMAKE_BOOTSTRAP) // Pool of file locks cmFileLockPool FileLockPool; diff --git a/Source/cmInstallRuntimeDependencySet.cxx b/Source/cmInstallRuntimeDependencySet.cxx new file mode 100644 index 0000000..0cef49a --- /dev/null +++ b/Source/cmInstallRuntimeDependencySet.cxx @@ -0,0 +1,95 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmInstallRuntimeDependencySet.h" + +#include <set> +#include <string> +#include <utility> + +#include "cmGeneratorTarget.h" +#include "cmGlobalGenerator.h" +#include "cmInstallImportedRuntimeArtifactsGenerator.h" +#include "cmInstallTargetGenerator.h" +#include "cmStateTypes.h" +#include "cmTargetDepend.h" + +cmInstallRuntimeDependencySet::cmInstallRuntimeDependencySet(std::string name) + : Name(std::move(name)) +{ +} + +void cmInstallRuntimeDependencySet::AddExecutable( + std::unique_ptr<Item> executable) +{ + this->Executables.push_back(std::move(executable)); +} + +void cmInstallRuntimeDependencySet::AddLibrary(std::unique_ptr<Item> library) +{ + this->Libraries.push_back(std::move(library)); +} + +void cmInstallRuntimeDependencySet::AddModule(std::unique_ptr<Item> module) +{ + this->Modules.push_back(std::move(module)); +} + +bool cmInstallRuntimeDependencySet::AddBundleExecutable( + std::unique_ptr<Item> bundleExecutable) +{ + if (this->BundleExecutable) { + return false; + } + this->BundleExecutable = bundleExecutable.get(); + this->AddExecutable(std::move(bundleExecutable)); + return true; +} + +std::string cmInstallRuntimeDependencySet::TargetItem::GetItemPath( + const std::string& config) const +{ + return this->Target->GetTarget()->GetFullPath(config); +} + +namespace { +const std::set<const cmGeneratorTarget*>& GetTargetDependsClosure( + std::map<const cmGeneratorTarget*, std::set<const cmGeneratorTarget*>>& + targetDepends, + const cmGeneratorTarget* tgt) +{ + auto it = targetDepends.insert({ tgt, {} }); + auto& retval = it.first->second; + if (it.second) { + auto const& deps = tgt->GetGlobalGenerator()->GetTargetDirectDepends(tgt); + for (auto const& dep : deps) { + if (!dep.IsCross() && dep.IsLink()) { + auto type = dep->GetType(); + if (type == cmStateEnums::EXECUTABLE || + type == cmStateEnums::SHARED_LIBRARY || + type == cmStateEnums::MODULE_LIBRARY) { + retval.insert(dep); + } + auto const& depDeps = GetTargetDependsClosure(targetDepends, dep); + retval.insert(depDeps.begin(), depDeps.end()); + } + } + } + return retval; +} +} + +void cmInstallRuntimeDependencySet::TargetItem::AddPostExcludeFiles( + const std::string& config, std::set<std::string>& files, + cmInstallRuntimeDependencySet* set) const +{ + for (auto const* dep : GetTargetDependsClosure(set->TargetDepends, + this->Target->GetTarget())) { + files.insert(dep->GetFullPath(config)); + } +} + +std::string cmInstallRuntimeDependencySet::ImportedTargetItem::GetItemPath( + const std::string& config) const +{ + return this->Target->GetTarget()->GetFullPath(config); +} diff --git a/Source/cmInstallRuntimeDependencySet.h b/Source/cmInstallRuntimeDependencySet.h new file mode 100644 index 0000000..7f51624 --- /dev/null +++ b/Source/cmInstallRuntimeDependencySet.h @@ -0,0 +1,163 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include <map> +#include <set> +#include <string> +#include <vector> + +#include <cm/memory> +#include <cm/string_view> +#include <cmext/string_view> + +class cmGeneratorTarget; +class cmInstallImportedRuntimeArtifactsGenerator; +class cmInstallTargetGenerator; + +class cmInstallRuntimeDependencySet +{ +public: + cmInstallRuntimeDependencySet(std::string name = ""); + + cmInstallRuntimeDependencySet(const cmInstallRuntimeDependencySet&) = delete; + cmInstallRuntimeDependencySet& operator=( + const cmInstallRuntimeDependencySet&) = delete; + + cm::string_view GetName() const { return this->Name; } + + cm::string_view GetDisplayName() const + { + if (this->Name.empty()) { + return "<anonymous>"_s; + } + return this->Name; + } + + class Item + { + public: + virtual ~Item() = default; + + virtual std::string GetItemPath(const std::string& config) const = 0; + + virtual void AddPostExcludeFiles( + const std::string& /*config*/, std::set<std::string>& /*files*/, + cmInstallRuntimeDependencySet* /*set*/) const + { + } + }; + + class TargetItem : public Item + { + public: + TargetItem(cmInstallTargetGenerator* target) + : Target(target) + { + } + + std::string GetItemPath(const std::string& config) const override; + + void AddPostExcludeFiles( + const std::string& config, std::set<std::string>& files, + cmInstallRuntimeDependencySet* set) const override; + + private: + cmInstallTargetGenerator* Target; + }; + + class ImportedTargetItem : public Item + { + public: + ImportedTargetItem(cmInstallImportedRuntimeArtifactsGenerator* target) + : Target(target) + { + } + + std::string GetItemPath(const std::string& config) const override; + + private: + cmInstallImportedRuntimeArtifactsGenerator* Target; + }; + + void AddExecutable(std::unique_ptr<Item> executable); + void AddLibrary(std::unique_ptr<Item> library); + void AddModule(std::unique_ptr<Item> module); + bool AddBundleExecutable(std::unique_ptr<Item> bundleExecutable); + + void AddExecutable(cmInstallTargetGenerator* executable) + { + this->AddExecutable(cm::make_unique<TargetItem>(executable)); + } + + void AddLibrary(cmInstallTargetGenerator* library) + { + this->AddLibrary(cm::make_unique<TargetItem>(library)); + } + + void AddModule(cmInstallTargetGenerator* module) + { + this->AddModule(cm::make_unique<TargetItem>(module)); + } + + bool AddBundleExecutable(cmInstallTargetGenerator* bundleExecutable) + { + return this->AddBundleExecutable( + cm::make_unique<TargetItem>(bundleExecutable)); + } + + void AddExecutable(cmInstallImportedRuntimeArtifactsGenerator* executable) + { + this->AddExecutable(cm::make_unique<ImportedTargetItem>(executable)); + } + + void AddLibrary(cmInstallImportedRuntimeArtifactsGenerator* library) + { + this->AddLibrary(cm::make_unique<ImportedTargetItem>(library)); + } + + void AddModule(cmInstallImportedRuntimeArtifactsGenerator* module) + { + this->AddModule(cm::make_unique<ImportedTargetItem>(module)); + } + + bool AddBundleExecutable( + cmInstallImportedRuntimeArtifactsGenerator* bundleExecutable) + { + return this->AddBundleExecutable( + cm::make_unique<ImportedTargetItem>(bundleExecutable)); + } + + const std::vector<std::unique_ptr<Item>>& GetExecutables() const + { + return this->Executables; + } + + const std::vector<std::unique_ptr<Item>>& GetLibraries() const + { + return this->Libraries; + } + + const std::vector<std::unique_ptr<Item>>& GetModules() const + { + return this->Modules; + } + + Item* GetBundleExecutable() const { return this->BundleExecutable; } + + bool Empty() const + { + return this->Executables.empty() && this->Libraries.empty() && + this->Modules.empty(); + } + +private: + std::string Name; + std::vector<std::unique_ptr<Item>> Executables; + std::vector<std::unique_ptr<Item>> Libraries; + std::vector<std::unique_ptr<Item>> Modules; + Item* BundleExecutable = nullptr; + + std::map<const cmGeneratorTarget*, std::set<const cmGeneratorTarget*>> + TargetDepends; +}; @@ -388,6 +388,7 @@ CMAKE_CXX_SOURCES="\ cmInstallFilesGenerator \ cmInstallGenerator \ cmInstallImportedRuntimeArtifactsGenerator \ + cmInstallRuntimeDependencySet \ cmInstallScriptGenerator \ cmInstallSubdirectoryGenerator \ cmInstallTargetGenerator \ |