TargetTypes: Extract target-related types to dedicated header

Move some target related enumeration types from `cmStateTypes.h` to a
new header, as these really aren't "state" types. Also, make
`TargetType` a strongly-typed enumeration.
This commit is contained in:
Matthew Woehlke
2026-07-01 14:44:11 -04:00
parent 1fde7f4599
commit a5a9ec9113
113 changed files with 1400 additions and 1341 deletions
+83 -84
View File
@@ -612,7 +612,7 @@ cmValue copyProperty(cmTarget const* src, cmTarget* dst,
class cmTargetInternals
{
public:
cmStateEnums::TargetType TargetType;
cm::TargetType TargetType;
cmTarget::Origin Origin = cmTarget::Origin::Unknown;
cmMakefile* Makefile;
cmPolicies::PolicyMap PolicyMap;
@@ -669,7 +669,7 @@ public:
std::unordered_map<cm::string_view, FileSetType> FileSetTypes;
cmTargetInternals(std::string name, cmStateEnums::TargetType type,
cmTargetInternals(std::string name, cm::TargetType type,
cmTarget::Visibility visibility, cmMakefile* mf,
cmTarget::PerConfig perConfig);
@@ -701,8 +701,7 @@ public:
}
};
cmTargetInternals::cmTargetInternals(std::string name,
cmStateEnums::TargetType type,
cmTargetInternals::cmTargetInternals(std::string name, cm::TargetType type,
cmTarget::Visibility visibility,
cmMakefile* mf,
cmTarget::PerConfig perConfig)
@@ -935,8 +934,8 @@ std::pair<bool, cmValue> UsageRequirementProperty::Read(
return { did_read, value };
}
cmTarget::cmTarget(std::string name, cmStateEnums::TargetType type,
Visibility vis, cmMakefile* mf, PerConfig perConfig)
cmTarget::cmTarget(std::string name, cm::TargetType type, Visibility vis,
cmMakefile* mf, PerConfig perConfig)
: impl(cm::make_unique<cmTargetInternals>(std::move(name), type, vis, mf,
perConfig))
{
@@ -978,38 +977,38 @@ cmTarget::cmTarget(std::string name, cmStateEnums::TargetType type,
if (!this->IsImported()) {
metConditions.insert(TargetProperty::InitCondition::NonImportedTarget);
}
if (this->impl->TargetType != cmStateEnums::UTILITY &&
this->impl->TargetType != cmStateEnums::GLOBAL_TARGET) {
if (this->impl->TargetType != cm::TargetType::UTILITY &&
this->impl->TargetType != cm::TargetType::GLOBAL_TARGET) {
metConditions.insert(TargetProperty::InitCondition::NormalTarget);
if (this->IsNormal()) {
metConditions.insert(
TargetProperty::InitCondition::NormalNonImportedTarget);
}
if (this->impl->TargetType != cmStateEnums::INTERFACE_LIBRARY) {
if (this->impl->TargetType != cm::TargetType::INTERFACE_LIBRARY) {
metConditions.insert(TargetProperty::InitCondition::TargetWithArtifact);
if (this->impl->TargetType != cmStateEnums::EXECUTABLE) {
if (this->impl->TargetType != cm::TargetType::EXECUTABLE) {
metConditions.insert(
TargetProperty::InitCondition::NonExecutableWithArtifact);
}
}
if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
this->impl->TargetType == cmStateEnums::STATIC_LIBRARY) {
if (this->impl->TargetType == cm::TargetType::SHARED_LIBRARY ||
this->impl->TargetType == cm::TargetType::STATIC_LIBRARY) {
metConditions.insert(
TargetProperty::InitCondition::LinkableLibraryTarget);
}
if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY) {
if (this->impl->TargetType == cm::TargetType::SHARED_LIBRARY) {
metConditions.insert(TargetProperty::InitCondition::SharedLibraryTarget);
}
}
if (this->impl->TargetType == cmStateEnums::EXECUTABLE) {
if (this->impl->TargetType == cm::TargetType::EXECUTABLE) {
metConditions.insert(TargetProperty::InitCondition::ExecutableTarget);
}
if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
this->impl->TargetType == cmStateEnums::EXECUTABLE) {
if (this->impl->TargetType == cm::TargetType::SHARED_LIBRARY ||
this->impl->TargetType == cm::TargetType::EXECUTABLE) {
metConditions.insert(
TargetProperty::InitCondition::TargetWithSymbolExports);
}
if (this->impl->TargetType <= cmStateEnums::GLOBAL_TARGET) {
if (this->impl->TargetType <= cm::TargetType::GLOBAL_TARGET) {
metConditions.insert(TargetProperty::InitCondition::TargetWithCommands);
}
@@ -1033,7 +1032,7 @@ cmTarget::cmTarget(std::string name, cmStateEnums::TargetType type,
// Replace everything after "CMAKE_"
defKey.replace(
defKey.begin() + 6, defKey.end(),
cmStrCat(this->impl->TargetType == cmStateEnums::EXECUTABLE
cmStrCat(this->impl->TargetType == cm::TargetType::EXECUTABLE
? "EXECUTABLE"
: "SHARED_LIBRARY",
'_', property));
@@ -1041,7 +1040,7 @@ cmTarget::cmTarget(std::string name, cmStateEnums::TargetType type,
this->SetProperty(property, value);
return;
}
if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY) {
if (this->impl->TargetType == cm::TargetType::SHARED_LIBRARY) {
if (default_value) {
this->SetProperty(property, default_value);
}
@@ -1092,8 +1091,8 @@ cmTarget::cmTarget(std::string name, cmStateEnums::TargetType type,
}
// Clean up some property defaults.
if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
this->impl->TargetType == cmStateEnums::MODULE_LIBRARY) {
if (this->impl->TargetType == cm::TargetType::SHARED_LIBRARY ||
this->impl->TargetType == cm::TargetType::MODULE_LIBRARY) {
this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
}
@@ -1139,7 +1138,7 @@ cmTarget::~cmTarget() = default;
cmTarget& cmTarget::operator=(cmTarget&&) noexcept = default;
cmStateEnums::TargetType cmTarget::GetType() const
cm::TargetType cmTarget::GetType() const
{
return this->impl->TargetType;
}
@@ -1262,26 +1261,26 @@ cmFindPackageStack const& cmTarget::GetFindPackageStack() const
bool cmTarget::IsExecutableWithExports() const
{
return (this->GetType() == cmStateEnums::EXECUTABLE &&
return (this->GetType() == cm::TargetType::EXECUTABLE &&
this->GetPropertyAsBool("ENABLE_EXPORTS"));
}
bool cmTarget::IsSharedLibraryWithExports() const
{
return (this->GetType() == cmStateEnums::SHARED_LIBRARY &&
return (this->GetType() == cm::TargetType::SHARED_LIBRARY &&
this->GetPropertyAsBool("ENABLE_EXPORTS"));
}
bool cmTarget::IsFrameworkOnApple() const
{
return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
return ((this->GetType() == cm::TargetType::SHARED_LIBRARY ||
this->GetType() == cm::TargetType::STATIC_LIBRARY) &&
this->IsApple() && this->GetPropertyAsBool("FRAMEWORK"));
}
bool cmTarget::IsArchivedAIXSharedLibrary() const
{
if (this->GetType() == cmStateEnums::SHARED_LIBRARY && this->IsAIX()) {
if (this->GetType() == cm::TargetType::SHARED_LIBRARY && this->IsAIX()) {
cmValue value = this->GetProperty("AIX_SHARED_LIBRARY_ARCHIVE");
if (!value.IsEmpty()) {
return value.IsOn();
@@ -1304,13 +1303,13 @@ bool cmTarget::IsArchivedAIXSharedLibrary() const
bool cmTarget::IsAppBundleOnApple() const
{
return (this->GetType() == cmStateEnums::EXECUTABLE && this->IsApple() &&
return (this->GetType() == cm::TargetType::EXECUTABLE && this->IsApple() &&
this->GetPropertyAsBool("MACOSX_BUNDLE"));
}
bool cmTarget::IsAndroidGuiExecutable() const
{
return (this->GetType() == cmStateEnums::EXECUTABLE &&
return (this->GetType() == cm::TargetType::EXECUTABLE &&
this->impl->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI"));
}
@@ -1601,8 +1600,8 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib,
if (cmGeneratorExpression::Find(lib) != std::string::npos ||
(tgt &&
(tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
tgt->GetType() == cmStateEnums::OBJECT_LIBRARY)) ||
(tgt->GetType() == cm::TargetType::INTERFACE_LIBRARY ||
tgt->GetType() == cm::TargetType::OBJECT_LIBRARY)) ||
(this->impl->Name == lib)) {
return;
}
@@ -1617,8 +1616,8 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib,
// may be purposefully duplicated to handle recursive dependencies,
// and we removing one instance will break the link line. Duplicates
// will be appropriately eliminated at emit time.
if (this->impl->TargetType >= cmStateEnums::STATIC_LIBRARY &&
this->impl->TargetType <= cmStateEnums::MODULE_LIBRARY &&
if (this->impl->TargetType >= cm::TargetType::STATIC_LIBRARY &&
this->impl->TargetType <= cm::TargetType::MODULE_LIBRARY &&
(this->GetPolicyStatusCMP0073() == cmPolicies::OLD ||
this->GetPolicyStatusCMP0073() == cmPolicies::WARN)) {
std::string targetEntry = cmStrCat(this->impl->Name, "_LIB_DEPENDS");
@@ -2222,7 +2221,7 @@ void cmTarget::SetProperty(std::string const& prop, cmValue value)
this->impl->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID");
auto const& compilerVersion =
this->impl->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_VERSION");
if (this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
if (this->GetType() != cm::TargetType::OBJECT_LIBRARY) {
auto e =
cmStrCat(prop, " property can only be applied to OBJECT targets(",
this->impl->Name, ")\n");
@@ -2427,10 +2426,10 @@ cmValue cmTargetInternals::GetFileSetPaths(cmTarget const* self,
void cmTarget::AppendBuildInterfaceIncludes()
{
if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
this->GetType() != cmStateEnums::STATIC_LIBRARY &&
this->GetType() != cmStateEnums::MODULE_LIBRARY &&
this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
if (this->GetType() != cm::TargetType::SHARED_LIBRARY &&
this->GetType() != cm::TargetType::STATIC_LIBRARY &&
this->GetType() != cm::TargetType::MODULE_LIBRARY &&
this->GetType() != cm::TargetType::INTERFACE_LIBRARY &&
!this->IsExecutableWithExports()) {
return;
}
@@ -2487,7 +2486,7 @@ bool CheckLinkLibraryPattern(UsageRequirementProperty const& usage,
void cmTarget::FinalizeTargetConfiguration(cmBTStringRange compileDefinitions)
{
if (this->GetType() == cmStateEnums::GLOBAL_TARGET) {
if (this->GetType() == cm::TargetType::GLOBAL_TARGET) {
return;
}
@@ -2502,7 +2501,7 @@ void cmTarget::FinalizeTargetConfiguration(cmBTStringRange compileDefinitions)
this->AppendBuildInterfaceIncludes();
if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
if (this->GetType() == cm::TargetType::INTERFACE_LIBRARY) {
return;
}
@@ -2958,16 +2957,16 @@ bool cmTarget::IsPerConfig() const
bool cmTarget::IsRuntimeBinary() const
{
switch (this->GetType()) {
case cmStateEnums::EXECUTABLE:
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
case cm::TargetType::EXECUTABLE:
case cm::TargetType::SHARED_LIBRARY:
case cm::TargetType::MODULE_LIBRARY:
return true;
case cmStateEnums::OBJECT_LIBRARY:
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::UTILITY:
case cmStateEnums::INTERFACE_LIBRARY:
case cmStateEnums::GLOBAL_TARGET:
case cmStateEnums::UNKNOWN_LIBRARY:
case cm::TargetType::OBJECT_LIBRARY:
case cm::TargetType::STATIC_LIBRARY:
case cm::TargetType::UTILITY:
case cm::TargetType::INTERFACE_LIBRARY:
case cm::TargetType::GLOBAL_TARGET:
case cm::TargetType::UNKNOWN_LIBRARY:
break;
}
return false;
@@ -2982,16 +2981,16 @@ bool cmTarget::CanCompileSources() const
return true;
}
switch (this->GetType()) {
case cmStateEnums::EXECUTABLE:
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::OBJECT_LIBRARY:
case cm::TargetType::EXECUTABLE:
case cm::TargetType::STATIC_LIBRARY:
case cm::TargetType::SHARED_LIBRARY:
case cm::TargetType::MODULE_LIBRARY:
case cm::TargetType::OBJECT_LIBRARY:
return true;
case cmStateEnums::UTILITY:
case cmStateEnums::INTERFACE_LIBRARY:
case cmStateEnums::GLOBAL_TARGET:
case cmStateEnums::UNKNOWN_LIBRARY:
case cm::TargetType::UTILITY:
case cm::TargetType::INTERFACE_LIBRARY:
case cm::TargetType::GLOBAL_TARGET:
case cm::TargetType::UNKNOWN_LIBRARY:
break;
}
return false;
@@ -3011,9 +3010,9 @@ char const* cmTarget::GetSuffixVariableInternal(
cmStateEnums::ArtifactType artifact) const
{
switch (this->GetType()) {
case cmStateEnums::STATIC_LIBRARY:
case cm::TargetType::STATIC_LIBRARY:
return "CMAKE_STATIC_LIBRARY_SUFFIX";
case cmStateEnums::SHARED_LIBRARY:
case cm::TargetType::SHARED_LIBRARY:
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
return this->IsArchivedAIXSharedLibrary()
@@ -3024,7 +3023,7 @@ char const* cmTarget::GetSuffixVariableInternal(
: "CMAKE_IMPORT_LIBRARY_SUFFIX";
}
break;
case cmStateEnums::MODULE_LIBRARY:
case cm::TargetType::MODULE_LIBRARY:
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
return "CMAKE_SHARED_MODULE_SUFFIX";
@@ -3032,7 +3031,7 @@ char const* cmTarget::GetSuffixVariableInternal(
return "CMAKE_IMPORT_LIBRARY_SUFFIX";
}
break;
case cmStateEnums::EXECUTABLE:
case cm::TargetType::EXECUTABLE:
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
// Android GUI application packages store the native
@@ -3055,9 +3054,9 @@ char const* cmTarget::GetPrefixVariableInternal(
cmStateEnums::ArtifactType artifact) const
{
switch (this->GetType()) {
case cmStateEnums::STATIC_LIBRARY:
case cm::TargetType::STATIC_LIBRARY:
return "CMAKE_STATIC_LIBRARY_PREFIX";
case cmStateEnums::SHARED_LIBRARY:
case cm::TargetType::SHARED_LIBRARY:
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
return "CMAKE_SHARED_LIBRARY_PREFIX";
@@ -3066,7 +3065,7 @@ char const* cmTarget::GetPrefixVariableInternal(
: "CMAKE_IMPORT_LIBRARY_PREFIX";
}
break;
case cmStateEnums::MODULE_LIBRARY:
case cm::TargetType::MODULE_LIBRARY:
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
return "CMAKE_SHARED_MODULE_PREFIX";
@@ -3074,7 +3073,7 @@ char const* cmTarget::GetPrefixVariableInternal(
return "CMAKE_IMPORT_LIBRARY_PREFIX";
}
break;
case cmStateEnums::EXECUTABLE:
case cm::TargetType::EXECUTABLE:
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
// Android GUI application packages store the native
@@ -3112,7 +3111,7 @@ std::string cmTarget::ImportedGetFullPath(
cmValue imp = nullptr;
std::string suffix;
if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
if (this->GetType() != cm::TargetType::INTERFACE_LIBRARY &&
this->GetMappedConfig(desired_config, loc, imp, suffix)) {
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
@@ -3129,7 +3128,7 @@ std::string cmTarget::ImportedGetFullPath(
result = *location;
}
if (result.empty() &&
(this->GetType() == cmStateEnums::SHARED_LIBRARY ||
(this->GetType() == cm::TargetType::SHARED_LIBRARY ||
this->IsExecutableWithExports())) {
impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
if (cmValue config_implib = this->GetProperty(impProp)) {
@@ -3140,9 +3139,9 @@ std::string cmTarget::ImportedGetFullPath(
}
}
if (this->IsApple() &&
(this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
this->impl->TargetType == cmStateEnums::STATIC_LIBRARY ||
this->impl->TargetType == cmStateEnums::UNKNOWN_LIBRARY) &&
(this->impl->TargetType == cm::TargetType::SHARED_LIBRARY ||
this->impl->TargetType == cm::TargetType::STATIC_LIBRARY ||
this->impl->TargetType == cm::TargetType::UNKNOWN_LIBRARY) &&
cmSystemTools::IsPathToXcFramework(result)) {
auto plist = cmParseXcFrameworkPlist(result, *this->impl->Makefile,
this->impl->Backtrace);
@@ -3163,7 +3162,7 @@ std::string cmTarget::ImportedGetFullPath(
case cmStateEnums::ImportLibraryArtifact:
if (imp) {
result = *imp;
} else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
} else if (this->GetType() == cm::TargetType::SHARED_LIBRARY ||
this->IsExecutableWithExports()) {
std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
if (cmValue config_implib = this->GetProperty(impProp)) {
@@ -3177,12 +3176,12 @@ std::string cmTarget::ImportedGetFullPath(
}
if (result.empty() && missingOk != ImportArtifactMissingOk::Yes) {
if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
if (this->GetType() != cm::TargetType::INTERFACE_LIBRARY) {
auto message = [&]() -> std::string {
std::string unset;
std::string configuration;
if (this->GetType() == cmStateEnums::SHARED_LIBRARY &&
if (this->GetType() == cm::TargetType::SHARED_LIBRARY &&
artifact == cmStateEnums::RuntimeBinaryArtifact) {
unset = "IMPORTED_LOCATION or IMPORTED_IMPLIB";
} else if (artifact == cmStateEnums::RuntimeBinaryArtifact) {
@@ -3327,7 +3326,7 @@ bool cmTarget::HasFileSets() const
bool cmTargetInternals::CheckImportedLibName(std::string const& prop,
std::string const& value) const
{
if (this->TargetType != cmStateEnums::INTERFACE_LIBRARY ||
if (this->TargetType != cm::TargetType::INTERFACE_LIBRARY ||
!this->IsImported()) {
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
@@ -3428,9 +3427,9 @@ bool cmTarget::GetMappedConfigOld(std::string const& desired_config,
}
std::string locPropBase;
if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
if (this->GetType() == cm::TargetType::INTERFACE_LIBRARY) {
locPropBase = "IMPORTED_LIBNAME";
} else if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
} else if (this->GetType() == cm::TargetType::OBJECT_LIBRARY) {
locPropBase = "IMPORTED_OBJECTS";
} else {
locPropBase = "IMPORTED_LOCATION";
@@ -3450,7 +3449,7 @@ bool cmTarget::GetMappedConfigOld(std::string const& desired_config,
// If we needed to find one of the mapped configurations but did not
// There may be only IMPORTED_IMPLIB for a shared library or an executable
// with exports.
bool allowImp = (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
bool allowImp = (this->GetType() == cm::TargetType::SHARED_LIBRARY ||
this->IsExecutableWithExports()) ||
(this->IsAIX() && this->IsExecutableWithExports()) ||
(this->GetMakefile()->PlatformSupportsAppleTextStubs() &&
@@ -3493,7 +3492,7 @@ bool cmTarget::GetMappedConfigOld(std::string const& desired_config,
if (!mappedConfigs.empty() && !loc && !imp) {
// Interface libraries are always available because their
// library name is optional so it is okay to leave loc empty.
return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
return this->GetType() == cm::TargetType::INTERFACE_LIBRARY;
}
// If we have not yet found it then there are no mapped
@@ -3543,7 +3542,7 @@ bool cmTarget::GetMappedConfigOld(std::string const& desired_config,
if (!loc && !imp) {
// Interface libraries are always available because their
// library name is optional so it is okay to leave loc empty.
return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
return this->GetType() == cm::TargetType::INTERFACE_LIBRARY;
}
return true;
@@ -3566,7 +3565,7 @@ bool cmTarget::GetLocation(std::string const& config, cmValue& loc,
// There may be only IMPORTED_IMPLIB for a shared library or an executable
// with exports.
bool const allowImp = (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
bool const allowImp = (this->GetType() == cm::TargetType::SHARED_LIBRARY ||
this->IsExecutableWithExports()) ||
(this->IsAIX() && this->IsExecutableWithExports()) ||
(this->GetMakefile()->PlatformSupportsAppleTextStubs() &&
@@ -3577,10 +3576,10 @@ bool cmTarget::GetLocation(std::string const& config, cmValue& loc,
}
switch (this->GetType()) {
case cmStateEnums::INTERFACE_LIBRARY:
case cm::TargetType::INTERFACE_LIBRARY:
loc = this->GetLocation("IMPORTED_LIBNAME", suffix);
break;
case cmStateEnums::OBJECT_LIBRARY:
case cm::TargetType::OBJECT_LIBRARY:
loc = this->GetLocation("IMPORTED_OBJECTS", suffix);
break;
default:
@@ -3588,7 +3587,7 @@ bool cmTarget::GetLocation(std::string const& config, cmValue& loc,
break;
}
return loc || imp || (this->GetType() == cmStateEnums::INTERFACE_LIBRARY);
return loc || imp || (this->GetType() == cm::TargetType::INTERFACE_LIBRARY);
}
bool cmTarget::GetMappedConfigNew(std::string desiredConfig, cmValue& loc,