From f2617cf8e6aca6ec0f8c7df6999c1f713c6d7474 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Wed, 19 May 2021 10:29:17 -0400 Subject: Source: Add cmInstallRuntimeDependencySet --- Source/CMakeLists.txt | 2 + Source/cmGlobalGenerator.cxx | 24 +++++ Source/cmGlobalGenerator.h | 11 +++ Source/cmInstallRuntimeDependencySet.cxx | 95 ++++++++++++++++++ Source/cmInstallRuntimeDependencySet.h | 163 +++++++++++++++++++++++++++++++ bootstrap | 1 + 6 files changed, 296 insertions(+) create mode 100644 Source/cmInstallRuntimeDependencySet.cxx create mode 100644 Source/cmInstallRuntimeDependencySet.h 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(); + 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(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 GeneratedFiles; + std::vector> + RuntimeDependencySets; + std::map + 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 +#include +#include + +#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 executable) +{ + this->Executables.push_back(std::move(executable)); +} + +void cmInstallRuntimeDependencySet::AddLibrary(std::unique_ptr library) +{ + this->Libraries.push_back(std::move(library)); +} + +void cmInstallRuntimeDependencySet::AddModule(std::unique_ptr module) +{ + this->Modules.push_back(std::move(module)); +} + +bool cmInstallRuntimeDependencySet::AddBundleExecutable( + std::unique_ptr 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& GetTargetDependsClosure( + std::map>& + 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& 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 +#include +#include +#include + +#include +#include +#include + +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 ""_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& /*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& 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 executable); + void AddLibrary(std::unique_ptr library); + void AddModule(std::unique_ptr module); + bool AddBundleExecutable(std::unique_ptr bundleExecutable); + + void AddExecutable(cmInstallTargetGenerator* executable) + { + this->AddExecutable(cm::make_unique(executable)); + } + + void AddLibrary(cmInstallTargetGenerator* library) + { + this->AddLibrary(cm::make_unique(library)); + } + + void AddModule(cmInstallTargetGenerator* module) + { + this->AddModule(cm::make_unique(module)); + } + + bool AddBundleExecutable(cmInstallTargetGenerator* bundleExecutable) + { + return this->AddBundleExecutable( + cm::make_unique(bundleExecutable)); + } + + void AddExecutable(cmInstallImportedRuntimeArtifactsGenerator* executable) + { + this->AddExecutable(cm::make_unique(executable)); + } + + void AddLibrary(cmInstallImportedRuntimeArtifactsGenerator* library) + { + this->AddLibrary(cm::make_unique(library)); + } + + void AddModule(cmInstallImportedRuntimeArtifactsGenerator* module) + { + this->AddModule(cm::make_unique(module)); + } + + bool AddBundleExecutable( + cmInstallImportedRuntimeArtifactsGenerator* bundleExecutable) + { + return this->AddBundleExecutable( + cm::make_unique(bundleExecutable)); + } + + const std::vector>& GetExecutables() const + { + return this->Executables; + } + + const std::vector>& GetLibraries() const + { + return this->Libraries; + } + + const std::vector>& 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> Executables; + std::vector> Libraries; + std::vector> Modules; + Item* BundleExecutable = nullptr; + + std::map> + TargetDepends; +}; diff --git a/bootstrap b/bootstrap index 911558d..720fa76 100755 --- a/bootstrap +++ b/bootstrap @@ -388,6 +388,7 @@ CMAKE_CXX_SOURCES="\ cmInstallFilesGenerator \ cmInstallGenerator \ cmInstallImportedRuntimeArtifactsGenerator \ + cmInstallRuntimeDependencySet \ cmInstallScriptGenerator \ cmInstallSubdirectoryGenerator \ cmInstallTargetGenerator \ -- cgit v0.12