mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-24 07:08:38 -05:00
install(EXPORT): Export find_dependency() calls
Issue: #20511 Co-Authored-by: Brad King <brad.king@kitware.com> Co-Authored-by: Robert Maynard <rmaynard@nvidia.com>
This commit is contained in:
@@ -558,6 +558,8 @@ add_library(
|
||||
cmFindLibraryCommand.h
|
||||
cmFindPackageCommand.cxx
|
||||
cmFindPackageCommand.h
|
||||
cmFindPackageStack.cxx
|
||||
cmFindPackageStack.h
|
||||
cmFindPathCommand.cxx
|
||||
cmFindPathCommand.h
|
||||
cmFindProgramCommand.cxx
|
||||
|
||||
@@ -55,6 +55,7 @@ protected:
|
||||
cmGeneratorTarget const* target,
|
||||
ImportPropertyMap const& properties) override;
|
||||
void GenerateMissingTargetsCheckCode(std::ostream& os) override;
|
||||
void GenerateFindDependencyCalls(std::ostream&) override {}
|
||||
void GenerateInterfaceProperties(
|
||||
cmGeneratorTarget const* target, std::ostream& os,
|
||||
const ImportPropertyMap& properties) override;
|
||||
|
||||
@@ -90,6 +90,7 @@ protected:
|
||||
cmTargetExport* te) override;
|
||||
std::string GetFileSetFiles(cmGeneratorTarget* gte, cmFileSet* fileSet,
|
||||
cmTargetExport* te) override;
|
||||
cmExportSet* GetExportSet() const override { return this->ExportSet; }
|
||||
|
||||
std::string GetCxxModulesDirectory() const override;
|
||||
void GenerateCxxModuleConfigInformation(std::ostream&) const override;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <cm/memory>
|
||||
#include <cm/optional>
|
||||
#include <cmext/algorithm>
|
||||
#include <cmext/string_view>
|
||||
|
||||
#include "cmsys/RegularExpression.hxx"
|
||||
@@ -24,10 +25,12 @@
|
||||
#include "cmMakefile.h"
|
||||
#include "cmMessageType.h"
|
||||
#include "cmPolicies.h"
|
||||
#include "cmRange.h"
|
||||
#include "cmStateTypes.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmTarget.h"
|
||||
#include "cmValue.h"
|
||||
|
||||
#if defined(__HAIKU__)
|
||||
# include <FindDirectory.h>
|
||||
@@ -66,6 +69,9 @@ bool cmExportCommand(std::vector<std::string> const& args,
|
||||
std::string CxxModulesDirectory;
|
||||
bool Append = false;
|
||||
bool ExportOld = false;
|
||||
|
||||
std::vector<std::vector<std::string>> PackageDependencyArgs;
|
||||
bool ExportPackageDependencies = false;
|
||||
};
|
||||
|
||||
auto parser =
|
||||
@@ -75,7 +81,12 @@ bool cmExportCommand(std::vector<std::string> const& args,
|
||||
.Bind("CXX_MODULES_DIRECTORY"_s, &Arguments::CxxModulesDirectory);
|
||||
|
||||
if (args[0] == "EXPORT") {
|
||||
parser.Bind("EXPORT"_s, &Arguments::ExportSetName);
|
||||
parser.Bind("EXPORT"_s, &Arguments::ExportSetName)
|
||||
.Bind("EXPORT_PACKAGE_DEPENDENCIES"_s,
|
||||
&Arguments::ExportPackageDependencies);
|
||||
} else if (args[0] == "SETUP") {
|
||||
parser.Bind("SETUP"_s, &Arguments::ExportSetName);
|
||||
parser.Bind("PACKAGE_DEPENDENCY"_s, &Arguments::PackageDependencyArgs);
|
||||
} else {
|
||||
parser.Bind("TARGETS"_s, &Arguments::Targets);
|
||||
parser.Bind("ANDROID_MK"_s, &Arguments::AndroidMKFile);
|
||||
@@ -91,6 +102,66 @@ bool cmExportCommand(std::vector<std::string> const& args,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0] == "SETUP") {
|
||||
cmMakefile& mf = status.GetMakefile();
|
||||
cmGlobalGenerator* gg = mf.GetGlobalGenerator();
|
||||
|
||||
cmExportSetMap& setMap = gg->GetExportSets();
|
||||
auto& exportSet = setMap[arguments.ExportSetName];
|
||||
|
||||
struct PackageDependencyArguments
|
||||
{
|
||||
std::string Enabled;
|
||||
ArgumentParser::MaybeEmpty<std::vector<std::string>> ExtraArgs;
|
||||
};
|
||||
|
||||
auto packageDependencyParser =
|
||||
cmArgumentParser<PackageDependencyArguments>{}
|
||||
.Bind("ENABLED"_s, &PackageDependencyArguments::Enabled)
|
||||
.Bind("EXTRA_ARGS"_s, &PackageDependencyArguments::ExtraArgs);
|
||||
|
||||
for (auto const& packageDependencyArgs : arguments.PackageDependencyArgs) {
|
||||
if (packageDependencyArgs.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PackageDependencyArguments const packageDependencyArguments =
|
||||
packageDependencyParser.Parse(
|
||||
cmMakeRange(packageDependencyArgs).advance(1), &unknownArgs);
|
||||
|
||||
if (!unknownArgs.empty()) {
|
||||
status.SetError("Unknown argument: \"" + unknownArgs.front() + "\".");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& packageDependency =
|
||||
exportSet.GetPackageDependencyForSetup(packageDependencyArgs.front());
|
||||
|
||||
if (!packageDependencyArguments.Enabled.empty()) {
|
||||
if (packageDependencyArguments.Enabled == "AUTO") {
|
||||
packageDependency.Enabled =
|
||||
cmExportSet::PackageDependencyExportEnabled::Auto;
|
||||
} else if (cmIsOff(packageDependencyArguments.Enabled)) {
|
||||
packageDependency.Enabled =
|
||||
cmExportSet::PackageDependencyExportEnabled::Off;
|
||||
} else if (cmIsOn(packageDependencyArguments.Enabled)) {
|
||||
packageDependency.Enabled =
|
||||
cmExportSet::PackageDependencyExportEnabled::On;
|
||||
} else {
|
||||
status.SetError(
|
||||
cmStrCat("Invalid enable setting for package dependency: \"",
|
||||
packageDependencyArguments.Enabled, "\""));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cm::append(packageDependency.ExtraArguments,
|
||||
packageDependencyArguments.ExtraArgs);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string fname;
|
||||
bool android = false;
|
||||
if (!arguments.AndroidMKFile.empty()) {
|
||||
@@ -224,6 +295,7 @@ bool cmExportCommand(std::vector<std::string> const& args,
|
||||
ebfg->SetTargets(targets);
|
||||
}
|
||||
ebfg->SetExportOld(arguments.ExportOld);
|
||||
ebfg->SetExportPackageDependencies(arguments.ExportPackageDependencies);
|
||||
|
||||
// Compute the set of configurations exported.
|
||||
std::vector<std::string> configurationTypes =
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#include "cmExportFileGenerator.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
@@ -9,12 +10,15 @@
|
||||
#include <utility>
|
||||
|
||||
#include <cm/memory>
|
||||
#include <cm/optional>
|
||||
#include <cmext/string_view>
|
||||
|
||||
#include "cmsys/FStream.hxx"
|
||||
|
||||
#include "cmComputeLinkInformation.h"
|
||||
#include "cmExportSet.h"
|
||||
#include "cmFileSet.h"
|
||||
#include "cmFindPackageStack.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmLinkItem.h"
|
||||
@@ -100,7 +104,20 @@ bool cmExportFileGenerator::GenerateImportFile()
|
||||
this->GenerateImportHeaderCode(mainFileWithHeadersAndFootersBuffer);
|
||||
|
||||
// Create all the imported targets.
|
||||
bool result = this->GenerateMainFile(mainFileWithHeadersAndFootersBuffer);
|
||||
std::stringstream mainFileBuffer;
|
||||
bool result = this->GenerateMainFile(mainFileBuffer);
|
||||
|
||||
// Export find_dependency() calls. Must be done after GenerateMainFile(),
|
||||
// because that's when target dependencies are gathered, which we need for
|
||||
// the find_dependency() calls.
|
||||
if (!this->AppendMode && this->GetExportSet() &&
|
||||
this->ExportPackageDependencies) {
|
||||
this->SetRequiredCMakeVersion(3, 9, 0);
|
||||
this->GenerateFindDependencyCalls(mainFileWithHeadersAndFootersBuffer);
|
||||
}
|
||||
|
||||
// Write cached import code.
|
||||
mainFileWithHeadersAndFootersBuffer << mainFileBuffer.rdbuf();
|
||||
|
||||
// End with the import file footer.
|
||||
this->GenerateImportFooterCode(mainFileWithHeadersAndFootersBuffer);
|
||||
@@ -615,6 +632,12 @@ bool cmExportFileGenerator::AddTargetNamespace(std::string& input,
|
||||
return false;
|
||||
}
|
||||
|
||||
cmFindPackageStack const& pkgStack = tgt->Target->GetFindPackageStack();
|
||||
if (!pkgStack.Empty() ||
|
||||
tgt->Target->GetProperty("EXPORT_FIND_PACKAGE_NAME")) {
|
||||
this->ExternalTargets.emplace(tgt);
|
||||
}
|
||||
|
||||
if (tgt->IsImported()) {
|
||||
input = tgt->GetName();
|
||||
return true;
|
||||
@@ -862,12 +885,14 @@ void cmExportFileGenerator::SetImportDetailProperties(
|
||||
// Export IMPORTED_LINK_DEPENDENT_LIBRARIES to help consuming linkers
|
||||
// find private dependencies of shared libraries.
|
||||
std::size_t oldMissingTargetsSize = this->MissingTargets.size();
|
||||
auto oldExternalTargets = this->ExternalTargets;
|
||||
this->SetImportLinkProperty(
|
||||
suffix, target, "IMPORTED_LINK_DEPENDENT_LIBRARIES", iface->SharedDeps,
|
||||
properties, ImportLinkPropertyTargetNames::Yes);
|
||||
// Avoid enforcing shared library private dependencies as public package
|
||||
// dependencies by ignoring missing targets added for them.
|
||||
this->MissingTargets.resize(oldMissingTargetsSize);
|
||||
this->ExternalTargets = std::move(oldExternalTargets);
|
||||
|
||||
if (iface->Multiplicity > 0) {
|
||||
std::string prop =
|
||||
@@ -1157,6 +1182,73 @@ void cmExportFileGenerator::GenerateImportPropertyCode(
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
void cmExportFileGenerator::GenerateFindDependencyCalls(std::ostream& os)
|
||||
{
|
||||
os << "include(CMakeFindDependencyMacro)\n";
|
||||
std::map<std::string, cmExportSet::PackageDependency> packageDependencies;
|
||||
auto* exportSet = this->GetExportSet();
|
||||
if (exportSet) {
|
||||
packageDependencies = exportSet->GetPackageDependencies();
|
||||
}
|
||||
|
||||
for (cmGeneratorTarget const* gt : this->ExternalTargets) {
|
||||
std::string findPackageName;
|
||||
auto exportFindPackageName = gt->GetProperty("EXPORT_FIND_PACKAGE_NAME");
|
||||
cmFindPackageStack pkgStack = gt->Target->GetFindPackageStack();
|
||||
if (!exportFindPackageName.IsEmpty()) {
|
||||
findPackageName = *exportFindPackageName;
|
||||
} else {
|
||||
if (!pkgStack.Empty()) {
|
||||
cmFindPackageCall const& fpc = pkgStack.Top();
|
||||
findPackageName = fpc.Name;
|
||||
}
|
||||
}
|
||||
if (!findPackageName.empty()) {
|
||||
auto& dep = packageDependencies[findPackageName];
|
||||
if (!pkgStack.Empty()) {
|
||||
dep.FindPackageIndex = pkgStack.Top().Index;
|
||||
}
|
||||
if (dep.Enabled == cmExportSet::PackageDependencyExportEnabled::Auto) {
|
||||
dep.Enabled = cmExportSet::PackageDependencyExportEnabled::On;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, cmExportSet::PackageDependency>>
|
||||
packageDependenciesSorted(packageDependencies.begin(),
|
||||
packageDependencies.end());
|
||||
std::sort(
|
||||
packageDependenciesSorted.begin(), packageDependenciesSorted.end(),
|
||||
[](const std::pair<std::string, cmExportSet::PackageDependency>& lhs,
|
||||
const std::pair<std::string, cmExportSet::PackageDependency>& rhs)
|
||||
-> bool {
|
||||
if (lhs.second.SpecifiedIndex) {
|
||||
if (rhs.second.SpecifiedIndex) {
|
||||
return lhs.second.SpecifiedIndex < rhs.second.SpecifiedIndex;
|
||||
}
|
||||
assert(rhs.second.FindPackageIndex);
|
||||
return true;
|
||||
}
|
||||
assert(lhs.second.FindPackageIndex);
|
||||
if (rhs.second.SpecifiedIndex) {
|
||||
return false;
|
||||
}
|
||||
assert(rhs.second.FindPackageIndex);
|
||||
return lhs.second.FindPackageIndex < rhs.second.FindPackageIndex;
|
||||
});
|
||||
|
||||
for (auto const& it : packageDependenciesSorted) {
|
||||
if (it.second.Enabled == cmExportSet::PackageDependencyExportEnabled::On) {
|
||||
os << "find_dependency(" << it.first << " REQUIRED";
|
||||
for (auto const& arg : it.second.ExtraArguments) {
|
||||
os << " " << cmOutputConverter::EscapeForCMake(arg);
|
||||
}
|
||||
os << ")\n";
|
||||
}
|
||||
}
|
||||
os << "\n\n";
|
||||
}
|
||||
|
||||
void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os)
|
||||
{
|
||||
if (this->MissingTargets.empty()) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "cmVersion.h"
|
||||
#include "cmVersionConfig.h"
|
||||
|
||||
class cmExportSet;
|
||||
class cmFileSet;
|
||||
class cmGeneratorTarget;
|
||||
class cmLocalGenerator;
|
||||
@@ -61,6 +62,11 @@ public:
|
||||
error. */
|
||||
bool GenerateImportFile();
|
||||
|
||||
void SetExportPackageDependencies(bool exportPackageDependencies)
|
||||
{
|
||||
this->ExportPackageDependencies = exportPackageDependencies;
|
||||
}
|
||||
|
||||
protected:
|
||||
using ImportPropertyMap = std::map<std::string, std::string>;
|
||||
|
||||
@@ -88,6 +94,7 @@ protected:
|
||||
const std::set<std::string>& importedLocations);
|
||||
virtual void GenerateImportedFileCheckLoop(std::ostream& os);
|
||||
virtual void GenerateMissingTargetsCheckCode(std::ostream& os);
|
||||
virtual void GenerateFindDependencyCalls(std::ostream& os);
|
||||
|
||||
virtual void GenerateExpectedTargetsCode(std::ostream& os,
|
||||
const std::string& expectedTargets);
|
||||
@@ -193,6 +200,8 @@ protected:
|
||||
cmFileSet* fileSet,
|
||||
cmTargetExport* te) = 0;
|
||||
|
||||
virtual cmExportSet* GetExportSet() const { return nullptr; }
|
||||
|
||||
void SetRequiredCMakeVersion(unsigned int major, unsigned int minor,
|
||||
unsigned int patch);
|
||||
|
||||
@@ -216,10 +225,14 @@ protected:
|
||||
|
||||
std::vector<std::string> MissingTargets;
|
||||
|
||||
std::set<cmGeneratorTarget const*> ExternalTargets;
|
||||
|
||||
unsigned int RequiredCMakeVersionMajor = 2;
|
||||
unsigned int RequiredCMakeVersionMinor = 8;
|
||||
unsigned int RequiredCMakeVersionPatch = 3;
|
||||
|
||||
bool ExportPackageDependencies = false;
|
||||
|
||||
private:
|
||||
void PopulateInterfaceProperty(const std::string&, const std::string&,
|
||||
cmGeneratorTarget const* target,
|
||||
|
||||
@@ -49,6 +49,7 @@ protected:
|
||||
cmGeneratorTarget const* target,
|
||||
ImportPropertyMap const& properties) override;
|
||||
void GenerateMissingTargetsCheckCode(std::ostream& os) override;
|
||||
void GenerateFindDependencyCalls(std::ostream&) override {}
|
||||
void GenerateInterfaceProperties(
|
||||
cmGeneratorTarget const* target, std::ostream& os,
|
||||
const ImportPropertyMap& properties) override;
|
||||
|
||||
@@ -12,12 +12,13 @@
|
||||
#include <vector>
|
||||
|
||||
#include "cmExportFileGenerator.h"
|
||||
#include "cmInstallExportGenerator.h"
|
||||
#include "cmStateTypes.h"
|
||||
|
||||
class cmExportSet;
|
||||
class cmFileSet;
|
||||
class cmGeneratorTarget;
|
||||
class cmGlobalGenerator;
|
||||
class cmInstallExportGenerator;
|
||||
class cmInstallTargetGenerator;
|
||||
class cmTargetExport;
|
||||
|
||||
@@ -121,6 +122,11 @@ protected:
|
||||
void GenerateCxxModuleConfigInformation(std::ostream&) const override;
|
||||
bool GenerateImportCxxModuleConfigTargetInclusion(std::string const&);
|
||||
|
||||
cmExportSet* GetExportSet() const override
|
||||
{
|
||||
return this->IEGen->GetExportSet();
|
||||
}
|
||||
|
||||
cmInstallExportGenerator* IEGen;
|
||||
|
||||
// The import file generated for each configuration.
|
||||
|
||||
@@ -20,6 +20,17 @@ cmExportSet::cmExportSet(std::string name)
|
||||
|
||||
cmExportSet::~cmExportSet() = default;
|
||||
|
||||
cmExportSet::PackageDependency& cmExportSet::GetPackageDependencyForSetup(
|
||||
const std::string& name)
|
||||
{
|
||||
auto& dep = this->PackageDependencies[name];
|
||||
if (!dep.SpecifiedIndex) {
|
||||
dep.SpecifiedIndex = this->NextPackageDependencyIndex;
|
||||
this->NextPackageDependencyIndex++;
|
||||
}
|
||||
return dep;
|
||||
}
|
||||
|
||||
bool cmExportSet::Compute(cmLocalGenerator* lg)
|
||||
{
|
||||
for (std::unique_ptr<cmTargetExport>& tgtExport : this->TargetExports) {
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/optional>
|
||||
|
||||
class cmInstallExportGenerator;
|
||||
class cmLocalGenerator;
|
||||
class cmTargetExport;
|
||||
@@ -43,10 +45,36 @@ public:
|
||||
return &this->Installations;
|
||||
}
|
||||
|
||||
enum class PackageDependencyExportEnabled
|
||||
{
|
||||
Auto,
|
||||
Off,
|
||||
On,
|
||||
};
|
||||
|
||||
struct PackageDependency
|
||||
{
|
||||
PackageDependencyExportEnabled Enabled =
|
||||
PackageDependencyExportEnabled::Auto;
|
||||
std::vector<std::string> ExtraArguments;
|
||||
cm::optional<unsigned int> SpecifiedIndex;
|
||||
cm::optional<unsigned int> FindPackageIndex;
|
||||
};
|
||||
|
||||
PackageDependency& GetPackageDependencyForSetup(const std::string& name);
|
||||
|
||||
const std::map<std::string, PackageDependency>& GetPackageDependencies()
|
||||
const
|
||||
{
|
||||
return this->PackageDependencies;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<cmTargetExport>> TargetExports;
|
||||
std::string Name;
|
||||
std::vector<cmInstallExportGenerator const*> Installations;
|
||||
std::map<std::string, PackageDependency> PackageDependencies;
|
||||
unsigned int NextPackageDependencyIndex = 0;
|
||||
};
|
||||
|
||||
/// A name -> cmExportSet map with overloaded operator[].
|
||||
|
||||
@@ -1044,6 +1044,8 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
|
||||
PushPopRootPathStack pushPopRootPathStack(*this);
|
||||
SetRestoreFindDefinitions setRestoreFindDefinitions(*this, components,
|
||||
componentVarDefs);
|
||||
cmMakefile::FindPackageStackRAII findPackageStackRAII(this->Makefile,
|
||||
this->Name);
|
||||
|
||||
// See if we have been told to delegate to FetchContent or some other
|
||||
// redirected config package first. We have to check all names that
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#define cmFindPackageStack_cxx
|
||||
#include "cmFindPackageStack.h"
|
||||
|
||||
#include "cmConstStack.tcc" // IWYU pragma: keep
|
||||
template class cmConstStack<cmFindPackageCall, cmFindPackageStack>;
|
||||
@@ -0,0 +1,33 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#pragma once
|
||||
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "cmConstStack.h"
|
||||
|
||||
/**
|
||||
* Represents one call to find_package.
|
||||
*/
|
||||
class cmFindPackageCall
|
||||
{
|
||||
public:
|
||||
std::string Name;
|
||||
unsigned int Index;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a stack of find_package calls with efficient value semantics.
|
||||
*/
|
||||
class cmFindPackageStack
|
||||
: public cmConstStack<cmFindPackageCall, cmFindPackageStack>
|
||||
{
|
||||
using cmConstStack::cmConstStack;
|
||||
friend class cmConstStack<cmFindPackageCall, cmFindPackageStack>;
|
||||
};
|
||||
#ifndef cmFindPackageStack_cxx
|
||||
extern template class cmConstStack<cmFindPackageCall, cmFindPackageStack>;
|
||||
#endif
|
||||
@@ -2030,7 +2030,7 @@ bool HandleExportAndroidMKMode(std::vector<std::string> const& args,
|
||||
cm::make_unique<cmInstallExportGenerator>(
|
||||
&exportSet, ica.GetDestination(), ica.GetPermissions(),
|
||||
ica.GetConfigurations(), ica.GetComponent(), message,
|
||||
ica.GetExcludeFromAll(), fname, name_space, "", exportOld, true,
|
||||
ica.GetExcludeFromAll(), fname, name_space, "", exportOld, true, false,
|
||||
helper.Makefile->GetBacktrace()));
|
||||
|
||||
return true;
|
||||
@@ -2054,12 +2054,14 @@ bool HandleExportMode(std::vector<std::string> const& args,
|
||||
bool exportOld = false;
|
||||
std::string filename;
|
||||
std::string cxx_modules_directory;
|
||||
bool exportPackageDependencies = false;
|
||||
|
||||
ica.Bind("EXPORT"_s, exp);
|
||||
ica.Bind("NAMESPACE"_s, name_space);
|
||||
ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld);
|
||||
ica.Bind("FILE"_s, filename);
|
||||
ica.Bind("CXX_MODULES_DIRECTORY"_s, cxx_modules_directory);
|
||||
ica.Bind("EXPORT_PACKAGE_DEPENDENCIES"_s, exportPackageDependencies);
|
||||
|
||||
std::vector<std::string> unknownArgs;
|
||||
ica.Parse(args, &unknownArgs);
|
||||
@@ -2147,7 +2149,8 @@ bool HandleExportMode(std::vector<std::string> const& args,
|
||||
&exportSet, ica.GetDestination(), ica.GetPermissions(),
|
||||
ica.GetConfigurations(), ica.GetComponent(), message,
|
||||
ica.GetExcludeFromAll(), fname, name_space, cxx_modules_directory,
|
||||
exportOld, false, helper.Makefile->GetBacktrace()));
|
||||
exportOld, false, exportPackageDependencies,
|
||||
helper.Makefile->GetBacktrace()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ cmInstallExportGenerator::cmInstallExportGenerator(
|
||||
std::string const& component, MessageLevel message, bool exclude_from_all,
|
||||
std::string filename, std::string name_space,
|
||||
std::string cxx_modules_directory, bool exportOld, bool android,
|
||||
cmListFileBacktrace backtrace)
|
||||
bool exportPackageDependencies, cmListFileBacktrace backtrace)
|
||||
: cmInstallGenerator(destination, configurations, component, message,
|
||||
exclude_from_all, false, std::move(backtrace))
|
||||
, ExportSet(exportSet)
|
||||
@@ -36,6 +36,7 @@ cmInstallExportGenerator::cmInstallExportGenerator(
|
||||
, Namespace(std::move(name_space))
|
||||
, CxxModulesDirectory(std::move(cxx_modules_directory))
|
||||
, ExportOld(exportOld)
|
||||
, ExportPackageDependencies(exportPackageDependencies)
|
||||
{
|
||||
if (android) {
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
@@ -119,6 +120,7 @@ void cmInstallExportGenerator::GenerateScript(std::ostream& os)
|
||||
this->EFGen->AddConfiguration(c);
|
||||
}
|
||||
}
|
||||
this->EFGen->SetExportPackageDependencies(this->ExportPackageDependencies);
|
||||
this->EFGen->GenerateImportFile();
|
||||
|
||||
// Perform the main install script generation.
|
||||
|
||||
@@ -29,7 +29,8 @@ public:
|
||||
bool exclude_from_all, std::string filename,
|
||||
std::string name_space,
|
||||
std::string cxx_modules_directory, bool exportOld,
|
||||
bool android, cmListFileBacktrace backtrace);
|
||||
bool android, bool exportPackageDependencies,
|
||||
cmListFileBacktrace backtrace);
|
||||
cmInstallExportGenerator(const cmInstallExportGenerator&) = delete;
|
||||
~cmInstallExportGenerator() override;
|
||||
|
||||
@@ -70,6 +71,7 @@ protected:
|
||||
std::string const Namespace;
|
||||
std::string const CxxModulesDirectory;
|
||||
bool const ExportOld;
|
||||
bool const ExportPackageDependencies;
|
||||
cmLocalGenerator* LocalGenerator = nullptr;
|
||||
|
||||
std::string TempDir;
|
||||
|
||||
@@ -302,6 +302,11 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const
|
||||
return this->Backtrace;
|
||||
}
|
||||
|
||||
cmFindPackageStack cmMakefile::GetFindPackageStack() const
|
||||
{
|
||||
return this->FindPackageStack;
|
||||
}
|
||||
|
||||
void cmMakefile::PrintCommandTrace(cmListFileFunction const& lff,
|
||||
cmListFileBacktrace const& bt,
|
||||
CommandMissingFromStack missing) const
|
||||
@@ -4771,6 +4776,36 @@ cmMakefile::MacroPushPop::~MacroPushPop()
|
||||
this->Makefile->PopMacroScope(this->ReportError);
|
||||
}
|
||||
|
||||
cmMakefile::FindPackageStackRAII::FindPackageStackRAII(cmMakefile* mf,
|
||||
std::string const& name)
|
||||
: Makefile(mf)
|
||||
{
|
||||
this->Makefile->FindPackageStack =
|
||||
this->Makefile->FindPackageStack.Push(cmFindPackageCall{
|
||||
name,
|
||||
this->Makefile->FindPackageStackNextIndex,
|
||||
});
|
||||
this->Makefile->FindPackageStackNextIndex++;
|
||||
}
|
||||
|
||||
cmMakefile::FindPackageStackRAII::~FindPackageStackRAII()
|
||||
{
|
||||
this->Makefile->FindPackageStackNextIndex =
|
||||
this->Makefile->FindPackageStack.Top().Index + 1;
|
||||
this->Makefile->FindPackageStack = this->Makefile->FindPackageStack.Pop();
|
||||
|
||||
if (!this->Makefile->FindPackageStack.Empty()) {
|
||||
auto top = this->Makefile->FindPackageStack.Top();
|
||||
this->Makefile->FindPackageStack = this->Makefile->FindPackageStack.Pop();
|
||||
|
||||
top.Index = this->Makefile->FindPackageStackNextIndex;
|
||||
this->Makefile->FindPackageStackNextIndex++;
|
||||
|
||||
this->Makefile->FindPackageStack =
|
||||
this->Makefile->FindPackageStack.Push(top);
|
||||
}
|
||||
}
|
||||
|
||||
cmMakefile::DebugFindPkgRAII::DebugFindPkgRAII(cmMakefile* mf,
|
||||
std::string const& pkg)
|
||||
: Makefile(mf)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmCustomCommand.h"
|
||||
#include "cmFindPackageStack.h"
|
||||
#include "cmFunctionBlocker.h"
|
||||
#include "cmListFileCache.h"
|
||||
#include "cmMessageType.h" // IWYU pragma: keep
|
||||
@@ -659,6 +660,11 @@ public:
|
||||
*/
|
||||
cmListFileBacktrace GetBacktrace() const;
|
||||
|
||||
/**
|
||||
* Get the current stack of find_package calls.
|
||||
*/
|
||||
cmFindPackageStack GetFindPackageStack() const;
|
||||
|
||||
/**
|
||||
* Get the vector of files created by this makefile
|
||||
*/
|
||||
@@ -1020,6 +1026,15 @@ public:
|
||||
// searches
|
||||
std::deque<std::vector<std::string>> FindPackageRootPathStack;
|
||||
|
||||
class FindPackageStackRAII
|
||||
{
|
||||
cmMakefile* Makefile;
|
||||
|
||||
public:
|
||||
FindPackageStackRAII(cmMakefile* mf, std::string const& pkg);
|
||||
~FindPackageStackRAII();
|
||||
};
|
||||
|
||||
class DebugFindPkgRAII
|
||||
{
|
||||
cmMakefile* Makefile;
|
||||
@@ -1210,6 +1225,9 @@ private:
|
||||
std::vector<BT<GeneratorAction>> GeneratorActions;
|
||||
bool GeneratorActionsInvoked = false;
|
||||
|
||||
cmFindPackageStack FindPackageStack;
|
||||
unsigned int FindPackageStackNextIndex = 0;
|
||||
|
||||
bool DebugFindPkg = false;
|
||||
|
||||
bool CheckSystemVars;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmCustomCommand.h"
|
||||
#include "cmFileSet.h"
|
||||
#include "cmFindPackageStack.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalGenerator.h"
|
||||
@@ -585,6 +586,7 @@ TargetProperty const StaticTargetProperties[] = {
|
||||
// Usage requirement properties
|
||||
{ "LINK_INTERFACE_LIBRARIES"_s, IC::CanCompileSources },
|
||||
{ "MAP_IMPORTED_CONFIG_"_s, IC::NormalTarget, R::PerConfig },
|
||||
{ "EXPORT_FIND_PACKAGE_NAME"_s, IC::NormalTarget },
|
||||
|
||||
// Metadata
|
||||
{ "CROSSCOMPILING_EMULATOR"_s, IC::ExecutableTarget },
|
||||
@@ -661,6 +663,7 @@ public:
|
||||
TLLCommands;
|
||||
std::map<std::string, cmFileSet> FileSets;
|
||||
cmListFileBacktrace Backtrace;
|
||||
cmFindPackageStack FindPackageStack;
|
||||
|
||||
UsageRequirementProperty IncludeDirectories;
|
||||
UsageRequirementProperty CompileOptions;
|
||||
@@ -961,6 +964,9 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
|
||||
|
||||
// Save the backtrace of target construction.
|
||||
this->impl->Backtrace = this->impl->Makefile->GetBacktrace();
|
||||
if (this->impl->IsImported()) {
|
||||
this->impl->FindPackageStack = this->impl->Makefile->GetFindPackageStack();
|
||||
}
|
||||
|
||||
if (this->IsNormal()) {
|
||||
// Initialize the INCLUDE_DIRECTORIES property based on the current value
|
||||
@@ -1248,6 +1254,11 @@ cmListFileBacktrace const& cmTarget::GetBacktrace() const
|
||||
return this->impl->Backtrace;
|
||||
}
|
||||
|
||||
cmFindPackageStack const& cmTarget::GetFindPackageStack() const
|
||||
{
|
||||
return this->impl->FindPackageStack;
|
||||
}
|
||||
|
||||
bool cmTarget::IsExecutableWithExports() const
|
||||
{
|
||||
return (this->GetType() == cmStateEnums::EXECUTABLE &&
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
class cmCustomCommand;
|
||||
class cmFileSet;
|
||||
class cmFindPackageStack;
|
||||
class cmGlobalGenerator;
|
||||
class cmInstallTargetGenerator;
|
||||
class cmMakefile;
|
||||
@@ -239,6 +240,9 @@ public:
|
||||
//! Get a backtrace from the creation of the target.
|
||||
cmListFileBacktrace const& GetBacktrace() const;
|
||||
|
||||
//! Get a find_package call stack from the creation of the target.
|
||||
cmFindPackageStack const& GetFindPackageStack() const;
|
||||
|
||||
void InsertInclude(BT<std::string> const& entry, bool before = false);
|
||||
void InsertCompileOption(BT<std::string> const& entry, bool before = false);
|
||||
void InsertCompileDefinition(BT<std::string> const& entry);
|
||||
|
||||
Reference in New Issue
Block a user