mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
TargetTypes: Improve use of imported target scope type
Move `ImportedTargetScope` to `cmTargetTypes.h`, enabling it to be used without dragging in all of `cmMakefile.h`. Use this in more places instead of `bool global`.
This commit is contained in:
@@ -140,7 +140,9 @@ bool cmAddExecutableCommand(std::vector<std::string> const& args,
|
||||
}
|
||||
|
||||
// Create the imported target.
|
||||
mf.AddImportedTarget(exename, cm::TargetType::EXECUTABLE, importGlobal);
|
||||
mf.AddImportedTarget(exename, cm::TargetType::EXECUTABLE,
|
||||
importGlobal ? cm::ImportedTargetScope::Global
|
||||
: cm::ImportedTargetScope::Local);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -287,7 +287,10 @@ bool cmAddLibraryCommand(std::vector<std::string> const& args,
|
||||
}
|
||||
|
||||
// Create the imported target.
|
||||
cmTarget* target = mf.AddImportedTarget(libName, type, importGlobal);
|
||||
cmTarget* target =
|
||||
mf.AddImportedTarget(libName, type,
|
||||
importGlobal ? cm::ImportedTargetScope::Global
|
||||
: cm::ImportedTargetScope::Local);
|
||||
target->SetSymbolic(symbolicTarget);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1033,7 +1033,8 @@ bool HandleImportCommand(std::vector<std::string> const& args,
|
||||
|
||||
mf.AddDefinition(found_var, "TRUE");
|
||||
auto* tgt =
|
||||
mf.AddImportedTarget(local_name, cm::TargetType::INTERFACE_LIBRARY, false);
|
||||
mf.AddImportedTarget(local_name, cm::TargetType::INTERFACE_LIBRARY,
|
||||
cm::ImportedTargetScope::Local);
|
||||
tgt->AppendProperty("INTERFACE_LINK_LIBRARIES", foreign_name);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2079,7 +2079,7 @@ bool cmFindPackageCommand::ReadListFile(std::string const& f,
|
||||
ps = cm::PolicyScope::None;
|
||||
}
|
||||
|
||||
using ITScope = cmMakefile::ImportedTargetScope;
|
||||
using ITScope = cm::ImportedTargetScope;
|
||||
ITScope scope = this->GlobalScope ? ITScope::Global : ITScope::Local;
|
||||
cmMakefile::SetGlobalTargetImportScope globScope(this->Makefile, scope);
|
||||
|
||||
@@ -2242,7 +2242,10 @@ bool cmFindPackageCommand::ImportPackageTargets(cmPackageState& packageState,
|
||||
}
|
||||
|
||||
// Import base file.
|
||||
if (!reader.ImportTargets(this->Makefile, this->Status, this->GlobalScope)) {
|
||||
if (!reader.ImportTargets(this->Makefile, this->Status,
|
||||
this->GlobalScope
|
||||
? cm::ImportedTargetScope::Global
|
||||
: cm::ImportedTargetScope::Local)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -658,7 +658,7 @@ bool cmMakefile::ExecuteCommand(cmListFileFunction const& lff,
|
||||
|
||||
bool cmMakefile::IsImportedTargetGlobalScope() const
|
||||
{
|
||||
return this->CurrentImportedTargetScope == ImportedTargetScope::Global;
|
||||
return this->CurrentImportedTargetScope == cm::ImportedTargetScope::Global;
|
||||
}
|
||||
|
||||
class cmMakefile::IncludeScope : public FileScopeBase
|
||||
@@ -3986,13 +3986,12 @@ void cmMakefile::RaiseScope(std::vector<std::string> const& variables)
|
||||
}
|
||||
|
||||
cmTarget* cmMakefile::AddImportedTarget(std::string const& name,
|
||||
cm::TargetType type, bool global)
|
||||
cm::TargetType type,
|
||||
cm::ImportedTargetScope scope)
|
||||
{
|
||||
// Create the target.
|
||||
auto target =
|
||||
cm::make_unique<cmTarget>(name, type,
|
||||
global ? cmTarget::Visibility::ImportedGlobally
|
||||
: cmTarget::Visibility::Imported,
|
||||
cm::make_unique<cmTarget>(name, type, cmTarget::ImportedVisibility(scope),
|
||||
this, cmTarget::PerConfig::Yes);
|
||||
|
||||
// Add to the set of available imported targets.
|
||||
|
||||
+7
-11
@@ -272,7 +272,7 @@ public:
|
||||
|
||||
/** Create a new imported target with the name and type given. */
|
||||
cmTarget* AddImportedTarget(std::string const& name, cm::TargetType type,
|
||||
bool global);
|
||||
cm::ImportedTargetScope scope);
|
||||
|
||||
cmTarget* AddForeignTarget(std::string const& origin,
|
||||
std::string const& name);
|
||||
@@ -979,22 +979,17 @@ public:
|
||||
|
||||
bool IsImportedTargetGlobalScope() const;
|
||||
|
||||
enum class ImportedTargetScope
|
||||
{
|
||||
Local,
|
||||
Global,
|
||||
};
|
||||
|
||||
/** Helper class to manage whether imported packages
|
||||
* should be globally scoped based off the find package command
|
||||
*/
|
||||
class SetGlobalTargetImportScope
|
||||
{
|
||||
public:
|
||||
SetGlobalTargetImportScope(cmMakefile* mk, ImportedTargetScope const scope)
|
||||
SetGlobalTargetImportScope(cmMakefile* mk,
|
||||
cm::ImportedTargetScope const scope)
|
||||
: Makefile(mk)
|
||||
{
|
||||
if (scope == ImportedTargetScope::Global &&
|
||||
if (scope == cm::ImportedTargetScope::Global &&
|
||||
!this->Makefile->IsImportedTargetGlobalScope()) {
|
||||
this->Makefile->CurrentImportedTargetScope = scope;
|
||||
this->Set = true;
|
||||
@@ -1006,7 +1001,7 @@ public:
|
||||
{
|
||||
if (this->Set) {
|
||||
this->Makefile->CurrentImportedTargetScope =
|
||||
ImportedTargetScope::Local;
|
||||
cm::ImportedTargetScope::Local;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1371,5 +1366,6 @@ private:
|
||||
std::set<std::string> WarnedCMP0144;
|
||||
std::set<std::string> WarnedCMP0219;
|
||||
bool IsSourceFileTryCompile;
|
||||
ImportedTargetScope CurrentImportedTargetScope = ImportedTargetScope::Local;
|
||||
cm::ImportedTargetScope CurrentImportedTargetScope =
|
||||
cm::ImportedTargetScope::Local;
|
||||
};
|
||||
|
||||
@@ -855,10 +855,11 @@ void cmPackageInfoReader::ReadCxxModulesMetadata(
|
||||
|
||||
cmTarget* cmPackageInfoReader::AddLibraryComponent(
|
||||
cmMakefile* makefile, cm::TargetType type, std::string const& name,
|
||||
Json::Value const& data, std::string const& package, bool global) const
|
||||
Json::Value const& data, std::string const& package,
|
||||
cm::ImportedTargetScope scope) const
|
||||
{
|
||||
// Create the imported target.
|
||||
cmTarget* const target = makefile->AddImportedTarget(name, type, global);
|
||||
cmTarget* const target = makefile->AddImportedTarget(name, type, scope);
|
||||
target->SetOrigin(cmTarget::Origin::Cps);
|
||||
|
||||
// Set target properties.
|
||||
@@ -872,7 +873,8 @@ cmTarget* cmPackageInfoReader::AddLibraryComponent(
|
||||
}
|
||||
|
||||
bool cmPackageInfoReader::ImportTargets(cmMakefile* makefile,
|
||||
cmExecutionStatus& status, bool global)
|
||||
cmExecutionStatus& status,
|
||||
cm::ImportedTargetScope scope)
|
||||
{
|
||||
std::string const& package = this->GetName();
|
||||
|
||||
@@ -896,7 +898,7 @@ bool cmPackageInfoReader::ImportTargets(cmMakefile* makefile,
|
||||
|
||||
auto createTarget = [&](cm::TargetType typeEnum) {
|
||||
return this->AddLibraryComponent(makefile, typeEnum, fullName, *ci,
|
||||
package, global);
|
||||
package, scope);
|
||||
};
|
||||
|
||||
cmTarget* target = nullptr;
|
||||
@@ -934,7 +936,7 @@ bool cmPackageInfoReader::ImportTargets(cmMakefile* makefile,
|
||||
}
|
||||
|
||||
cmTarget* const target = makefile->AddImportedTarget(
|
||||
package, cm::TargetType::INTERFACE_LIBRARY, global);
|
||||
package, cm::TargetType::INTERFACE_LIBRARY, scope);
|
||||
for (std::string const& name : defaultComponents) {
|
||||
std::string const& fullName = cmStrCat(package, "::"_s, name);
|
||||
AppendProperty(makefile, target, "LINK_LIBRARIES"_s, {}, fullName);
|
||||
|
||||
@@ -19,6 +19,7 @@ class cmMakefile;
|
||||
class cmTarget;
|
||||
|
||||
namespace cm {
|
||||
enum class ImportedTargetScope;
|
||||
enum class TargetType;
|
||||
} // namespace cm
|
||||
|
||||
@@ -80,7 +81,7 @@ public:
|
||||
|
||||
/// Create targets for components specified in the CPS file.
|
||||
bool ImportTargets(cmMakefile* makefile, cmExecutionStatus& status,
|
||||
bool global);
|
||||
cm::ImportedTargetScope scope);
|
||||
|
||||
/// Add configuration-specific properties for targets.
|
||||
bool ImportTargetConfigurations(cmMakefile* makefile,
|
||||
@@ -92,7 +93,8 @@ private:
|
||||
cmTarget* AddLibraryComponent(cmMakefile* makefile, cm::TargetType type,
|
||||
std::string const& name,
|
||||
Json::Value const& data,
|
||||
std::string const& package, bool global) const;
|
||||
std::string const& package,
|
||||
cm::ImportedTargetScope scope) const;
|
||||
|
||||
void AddTargetConfiguration(cmTarget* target,
|
||||
cm::string_view configuration) const;
|
||||
|
||||
@@ -71,6 +71,13 @@ public:
|
||||
No
|
||||
};
|
||||
|
||||
static Visibility ImportedVisibility(cm::ImportedTargetScope scope)
|
||||
{
|
||||
return (scope == cm::ImportedTargetScope::Global
|
||||
? Visibility::ImportedGlobally
|
||||
: Visibility::Imported);
|
||||
}
|
||||
|
||||
cmTarget(std::string name, cm::TargetType type, Visibility vis,
|
||||
cmMakefile* mf, PerConfig perConfig);
|
||||
|
||||
|
||||
@@ -40,4 +40,10 @@ using TargetDomainSet = cm::enum_set<TargetDomain>;
|
||||
static TargetDomainSet const AllTargetDomains{ TargetDomain::NATIVE,
|
||||
TargetDomain::ALIAS,
|
||||
TargetDomain::FOREIGN };
|
||||
|
||||
enum class ImportedTargetScope
|
||||
{
|
||||
Local,
|
||||
Global,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user