1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-23 18:08:31 +08:00

Enhance support functions

* Avoid duplicate definiitions for IsExecutableWithExports, etc...
* Add helper IsApple()
This commit is contained in:
Marc Chevrier
2023-02-17 16:25:29 +01:00
parent 22a491c3ea
commit fcbd723a50
8 changed files with 48 additions and 32 deletions

View File

@@ -248,7 +248,7 @@ std::string cmCommonTargetGenerator::GetManifests(const std::string& config)
std::string cmCommonTargetGenerator::GetAIXExports(std::string const&) std::string cmCommonTargetGenerator::GetAIXExports(std::string const&)
{ {
std::string aixExports; std::string aixExports;
if (this->GeneratorTarget->Target->IsAIX()) { if (this->GeneratorTarget->IsAIX()) {
if (cmValue exportAll = if (cmValue exportAll =
this->GeneratorTarget->GetProperty("AIX_EXPORT_ALL_SYMBOLS")) { this->GeneratorTarget->GetProperty("AIX_EXPORT_ALL_SYMBOLS")) {
if (cmIsOff(*exportAll)) { if (cmIsOff(*exportAll)) {

View File

@@ -1157,7 +1157,7 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry)
// Pass the full path to the target file. // Pass the full path to the target file.
BT<std::string> lib = BT<std::string>( BT<std::string> lib = BT<std::string>(
tgt->GetFullPath(config, artifact, true), item.Backtrace); tgt->GetFullPath(config, artifact, true), item.Backtrace);
if (tgt->Target->IsAIX() && cmHasLiteralSuffix(lib.Value, "-NOTFOUND") && if (tgt->IsAIX() && cmHasLiteralSuffix(lib.Value, "-NOTFOUND") &&
artifact == cmStateEnums::ImportLibraryArtifact) { artifact == cmStateEnums::ImportLibraryArtifact) {
// This is an imported executable on AIX that has ENABLE_EXPORTS // This is an imported executable on AIX that has ENABLE_EXPORTS
// but not IMPORTED_IMPLIB. CMake used to produce and accept such // but not IMPORTED_IMPLIB. CMake used to produce and accept such
@@ -1185,7 +1185,7 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry)
if (cmHasSuffix(entry.Feature, "FRAMEWORK"_s) || if (cmHasSuffix(entry.Feature, "FRAMEWORK"_s) ||
(entry.Feature == DEFAULT && (entry.Feature == DEFAULT &&
cmSystemTools::IsPathToFramework(item.Value) && cmSystemTools::IsPathToFramework(item.Value) &&
this->Makefile->IsOn("APPLE"))) { this->Target->IsApple())) {
// This is a framework. // This is a framework.
this->AddFrameworkItem(entry); this->AddFrameworkItem(entry);
} else if (cmSystemTools::FileIsFullPath(item.Value)) { } else if (cmSystemTools::FileIsFullPath(item.Value)) {

View File

@@ -3074,6 +3074,16 @@ void cmGeneratorTarget::ComputeModuleDefinitionInfo(
} }
} }
bool cmGeneratorTarget::IsAIX() const
{
return this->Target->IsAIX();
}
bool cmGeneratorTarget::IsApple() const
{
return this->Target->IsApple();
}
bool cmGeneratorTarget::IsDLLPlatform() const bool cmGeneratorTarget::IsDLLPlatform() const
{ {
return this->Target->IsDLLPlatform(); return this->Target->IsDLLPlatform();
@@ -3412,7 +3422,7 @@ std::string cmGeneratorTarget::GetCompilePDBDirectory(
void cmGeneratorTarget::GetAppleArchs(const std::string& config, void cmGeneratorTarget::GetAppleArchs(const std::string& config,
std::vector<std::string>& archVec) const std::vector<std::string>& archVec) const
{ {
if (!this->Makefile->IsOn("APPLE")) { if (!this->IsApple()) {
return; return;
} }
cmValue archs = nullptr; cmValue archs = nullptr;
@@ -3910,7 +3920,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES", lang, AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES", lang,
&dagChecker, entries, IncludeRuntimeInterface::Yes); &dagChecker, entries, IncludeRuntimeInterface::Yes);
if (this->Makefile->IsOn("APPLE")) { if (this->IsApple()) {
if (cmLinkImplementationLibraries const* impl = if (cmLinkImplementationLibraries const* impl =
this->GetLinkImplementationLibraries(config, this->GetLinkImplementationLibraries(config,
LinkInterfaceFor::Usage)) { LinkInterfaceFor::Usage)) {
@@ -6757,12 +6767,12 @@ void cmGeneratorTarget::ComputeVersionedName(
std::string& vName, std::string const& prefix, std::string const& base, std::string& vName, std::string const& prefix, std::string const& base,
std::string const& suffix, std::string const& name, cmValue version) const std::string const& suffix, std::string const& name, cmValue version) const
{ {
vName = this->Makefile->IsOn("APPLE") ? (prefix + base) : name; vName = this->IsApple() ? (prefix + base) : name;
if (version) { if (version) {
vName += "."; vName += ".";
vName += *version; vName += *version;
} }
vName += this->Makefile->IsOn("APPLE") ? suffix : std::string(); vName += this->IsApple() ? suffix : std::string();
} }
std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const
@@ -8531,8 +8541,7 @@ bool cmGeneratorTarget::HasContextDependentSources() const
bool cmGeneratorTarget::IsExecutableWithExports() const bool cmGeneratorTarget::IsExecutableWithExports() const
{ {
return (this->GetType() == cmStateEnums::EXECUTABLE && return this->Target->IsExecutableWithExports();
this->GetPropertyAsBool("ENABLE_EXPORTS"));
} }
bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const
@@ -8543,7 +8552,7 @@ bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const
// Assemblies which have only managed code do not have // Assemblies which have only managed code do not have
// import libraries. // import libraries.
this->GetManagedType(config) != ManagedType::Managed) || this->GetManagedType(config) != ManagedType::Managed) ||
(this->Target->IsAIX() && this->IsExecutableWithExports()); (this->IsAIX() && this->IsExecutableWithExports());
} }
bool cmGeneratorTarget::NeedImportLibraryName(std::string const& config) const bool cmGeneratorTarget::NeedImportLibraryName(std::string const& config) const
@@ -8581,17 +8590,12 @@ bool cmGeneratorTarget::IsLinkable() const
bool cmGeneratorTarget::IsFrameworkOnApple() const bool cmGeneratorTarget::IsFrameworkOnApple() const
{ {
return ((this->GetType() == cmStateEnums::SHARED_LIBRARY || return this->Target->IsFrameworkOnApple();
this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
this->Makefile->IsOn("APPLE") &&
this->GetPropertyAsBool("FRAMEWORK"));
} }
bool cmGeneratorTarget::IsAppBundleOnApple() const bool cmGeneratorTarget::IsAppBundleOnApple() const
{ {
return (this->GetType() == cmStateEnums::EXECUTABLE && return this->Target->IsAppBundleOnApple();
this->Makefile->IsOn("APPLE") &&
this->GetPropertyAsBool("MACOSX_BUNDLE"));
} }
bool cmGeneratorTarget::IsXCTestOnApple() const bool cmGeneratorTarget::IsXCTestOnApple() const
@@ -8601,8 +8605,8 @@ bool cmGeneratorTarget::IsXCTestOnApple() const
bool cmGeneratorTarget::IsCFBundleOnApple() const bool cmGeneratorTarget::IsCFBundleOnApple() const
{ {
return (this->GetType() == cmStateEnums::MODULE_LIBRARY && return (this->GetType() == cmStateEnums::MODULE_LIBRARY && this->IsApple() &&
this->Makefile->IsOn("APPLE") && this->GetPropertyAsBool("BUNDLE")); this->GetPropertyAsBool("BUNDLE"));
} }
cmGeneratorTarget::ManagedType cmGeneratorTarget::CheckManagedType( cmGeneratorTarget::ManagedType cmGeneratorTarget::CheckManagedType(

View File

@@ -389,6 +389,11 @@ public:
ModuleDefinitionInfo const* GetModuleDefinitionInfo( ModuleDefinitionInfo const* GetModuleDefinitionInfo(
std::string const& config) const; std::string const& config) const;
/** Return whether or not we are targeting AIX. */
bool IsAIX() const;
/** Return whether or not we are targeting Apple. */
bool IsApple() const;
/** Return whether or not the target is for a DLL platform. */ /** Return whether or not the target is for a DLL platform. */
bool IsDLLPlatform() const; bool IsDLLPlatform() const;

View File

@@ -784,7 +784,7 @@ void cmInstallTargetGenerator::AddStripRule(std::ostream& os, Indent indent,
} }
// Don't handle OSX Bundles. // Don't handle OSX Bundles.
if (this->Target->Target->GetMakefile()->IsOn("APPLE") && if (this->Target->IsApple() &&
this->Target->GetPropertyAsBool("MACOSX_BUNDLE")) { this->Target->GetPropertyAsBool("MACOSX_BUNDLE")) {
return; return;
} }
@@ -796,7 +796,7 @@ void cmInstallTargetGenerator::AddStripRule(std::ostream& os, Indent indent,
std::string stripArgs; std::string stripArgs;
// macOS 'strip' is picky, executables need '-u -r' and dylibs need '-x'. // macOS 'strip' is picky, executables need '-u -r' and dylibs need '-x'.
if (this->Target->Target->GetMakefile()->IsOn("APPLE")) { if (this->Target->IsApple()) {
if (this->Target->GetType() == cmStateEnums::SHARED_LIBRARY || if (this->Target->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->Target->GetType() == cmStateEnums::MODULE_LIBRARY) { this->Target->GetType() == cmStateEnums::MODULE_LIBRARY) {
stripArgs = "-x "; stripArgs = "-x ";
@@ -822,7 +822,7 @@ void cmInstallTargetGenerator::AddRanlibRule(std::ostream& os, Indent indent,
// Perform post-installation processing on the file depending // Perform post-installation processing on the file depending
// on its type. // on its type.
if (!this->Target->Target->GetMakefile()->IsOn("APPLE")) { if (!this->Target->IsApple()) {
return; return;
} }

View File

@@ -1644,7 +1644,7 @@ static std::string GetFrameworkFlags(const std::string& lang,
cmLocalGenerator* lg = target->GetLocalGenerator(); cmLocalGenerator* lg = target->GetLocalGenerator();
cmMakefile* mf = lg->GetMakefile(); cmMakefile* mf = lg->GetMakefile();
if (!mf->IsOn("APPLE")) { if (!target->IsApple()) {
return std::string(); return std::string();
} }
@@ -1818,7 +1818,7 @@ std::string cmLocalGenerator::GetLinkLibsCMP0065(
// OLD behavior is to always add the flags, except on AIX where // OLD behavior is to always add the flags, except on AIX where
// we compute symbol exports if ENABLE_EXPORTS is on. // we compute symbol exports if ENABLE_EXPORTS is on.
add_shlib_flags = add_shlib_flags =
!(tgt.Target->IsAIX() && tgt.GetPropertyAsBool("ENABLE_EXPORTS")); !(tgt.IsAIX() && tgt.GetPropertyAsBool("ENABLE_EXPORTS"));
break; break;
case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::REQUIRED_ALWAYS:
@@ -1830,7 +1830,7 @@ std::string cmLocalGenerator::GetLinkLibsCMP0065(
// NEW behavior is to only add the flags if ENABLE_EXPORTS is on, // NEW behavior is to only add the flags if ENABLE_EXPORTS is on,
// except on AIX where we compute symbol exports. // except on AIX where we compute symbol exports.
add_shlib_flags = add_shlib_flags =
!tgt.Target->IsAIX() && tgt.GetPropertyAsBool("ENABLE_EXPORTS"); !tgt.IsAIX() && tgt.GetPropertyAsBool("ENABLE_EXPORTS");
break; break;
} }
@@ -1864,7 +1864,7 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
const std::string& filterArch) const std::string& filterArch)
{ {
// Only add Apple specific flags on Apple platforms // Only add Apple specific flags on Apple platforms
if (this->Makefile->IsOn("APPLE") && this->EmitUniversalBinaryFlags) { if (target->IsApple() && this->EmitUniversalBinaryFlags) {
std::vector<std::string> archs; std::vector<std::string> archs;
target->GetAppleArchs(config, archs); target->GetAppleArchs(config, archs);
if (!archs.empty() && if (!archs.empty() &&

View File

@@ -611,7 +611,6 @@ TargetProperty const StaticTargetProperties[] = {
#undef COMMON_LANGUAGE_PROPERTIES #undef COMMON_LANGUAGE_PROPERTIES
#undef IC #undef IC
#undef R #undef R
} }
class cmTargetInternals class cmTargetInternals
@@ -628,6 +627,7 @@ public:
bool HaveInstallRule; bool HaveInstallRule;
bool IsDLLPlatform; bool IsDLLPlatform;
bool IsAIX; bool IsAIX;
bool IsApple;
bool IsAndroid; bool IsAndroid;
bool BuildInterfaceIncludesAppended; bool BuildInterfaceIncludesAppended;
bool PerConfig; bool PerConfig;
@@ -914,6 +914,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
this->impl->HaveInstallRule = false; this->impl->HaveInstallRule = false;
this->impl->IsDLLPlatform = false; this->impl->IsDLLPlatform = false;
this->impl->IsAIX = false; this->impl->IsAIX = false;
this->impl->IsApple = false;
this->impl->IsAndroid = false; this->impl->IsAndroid = false;
this->impl->TargetVisibility = vis; this->impl->TargetVisibility = vis;
this->impl->BuildInterfaceIncludesAppended = false; this->impl->BuildInterfaceIncludesAppended = false;
@@ -931,6 +932,9 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
this->impl->IsAIX = (systemName == "AIX" || systemName == "OS400"); this->impl->IsAIX = (systemName == "AIX" || systemName == "OS400");
} }
// Check whether we are targeting Apple.
this->impl->IsApple = this->impl->Makefile->IsOn("APPLE");
// Check whether we are targeting an Android platform. // Check whether we are targeting an Android platform.
this->impl->IsAndroid = (this->impl->Makefile->GetSafeDefinition( this->impl->IsAndroid = (this->impl->Makefile->GetSafeDefinition(
"CMAKE_SYSTEM_NAME") == "Android"); "CMAKE_SYSTEM_NAME") == "Android");
@@ -1205,14 +1209,12 @@ bool cmTarget::IsFrameworkOnApple() const
{ {
return ((this->GetType() == cmStateEnums::SHARED_LIBRARY || return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GetType() == cmStateEnums::STATIC_LIBRARY) && this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
this->impl->Makefile->IsOn("APPLE") && this->IsApple() && this->GetPropertyAsBool("FRAMEWORK"));
this->GetPropertyAsBool("FRAMEWORK"));
} }
bool cmTarget::IsAppBundleOnApple() const bool cmTarget::IsAppBundleOnApple() const
{ {
return (this->GetType() == cmStateEnums::EXECUTABLE && return (this->GetType() == cmStateEnums::EXECUTABLE && this->IsApple() &&
this->impl->Makefile->IsOn("APPLE") &&
this->GetPropertyAsBool("MACOSX_BUNDLE")); this->GetPropertyAsBool("MACOSX_BUNDLE"));
} }
@@ -1774,7 +1776,6 @@ std::string ConvertToString<cmValue>(cmValue value)
{ {
return std::string(*value); return std::string(*value);
} }
} }
template <typename ValueType> template <typename ValueType>
@@ -2553,6 +2554,10 @@ bool cmTarget::IsAIX() const
{ {
return this->impl->IsAIX; return this->impl->IsAIX;
} }
bool cmTarget::IsApple() const
{
return this->impl->IsApple;
}
bool cmTarget::IsNormal() const bool cmTarget::IsNormal() const
{ {

View File

@@ -205,6 +205,8 @@ public:
//! Return whether or not we are targeting AIX. //! Return whether or not we are targeting AIX.
bool IsAIX() const; bool IsAIX() const;
//! Return whether or not we are targeting Apple.
bool IsApple() const;
bool IsNormal() const; bool IsNormal() const;
bool IsSynthetic() const; bool IsSynthetic() const;