diff options
author | Brad King <brad.king@kitware.com> | 2023-02-16 16:41:44 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-02-16 16:41:53 (GMT) |
commit | 847c315f07668bcdb61246a8ea2f9f97e28f5f8b (patch) | |
tree | 38e9a3d40951d9f2f28f910546ff186913207952 | |
parent | 4e54067eaa29d2a989df4da4c07a986a5f4c8552 (diff) | |
parent | dadaa2863841fc704b73276630f4260fa7ad5850 (diff) | |
download | CMake-847c315f07668bcdb61246a8ea2f9f97e28f5f8b.zip CMake-847c315f07668bcdb61246a8ea2f9f97e28f5f8b.tar.gz CMake-847c315f07668bcdb61246a8ea2f9f97e28f5f8b.tar.bz2 |
Merge topic 'synthetic-targets'
dadaa28638 cmGeneratorTarget: synthetic targets don't have output either
bde9d4ad01 cmCommonTargetGenerator: also consider synthetic targets
c97de1047f cmMakefile: add support for a "synthesized" target
1d0426f642 cmTarget: make Visibility an `enum class`
5b58695321 cmTarget: store visibility as an `enum` rather than bools
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !8203
-rw-r--r-- | Source/cmCommonTargetGenerator.cxx | 4 | ||||
-rw-r--r-- | Source/cmExportTryCompileFileGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 15 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 2 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 19 | ||||
-rw-r--r-- | Source/cmMakefile.h | 5 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 76 | ||||
-rw-r--r-- | Source/cmTarget.h | 11 |
8 files changed, 109 insertions, 25 deletions
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index a63c162..1705763 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -176,7 +176,9 @@ std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories( // We can ignore the INTERFACE_LIBRARY items because // Target->GetLinkInformation already processed their // link interface and they don't have any output themselves. - && linkee->GetType() != cmStateEnums::INTERFACE_LIBRARY && + && (linkee->GetType() != cmStateEnums::INTERFACE_LIBRARY + // Synthesized targets may have relevant rules. + || linkee->IsSynthetic()) && ((lang == "CXX"_s && linkee->HaveCxx20ModuleSources()) || (lang == "Fortran"_s && linkee->HaveFortranSources(config))) && emitted.insert(linkee).second) { diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx index 33c057d..c6ebad5 100644 --- a/Source/cmExportTryCompileFileGenerator.cxx +++ b/Source/cmExportTryCompileFileGenerator.cxx @@ -85,7 +85,7 @@ std::string cmExportTryCompileFileGenerator::FindTargets( std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*prop); cmTarget dummyHead("try_compile_dummy_exe", cmStateEnums::EXECUTABLE, - cmTarget::VisibilityNormal, tgt->Target->GetMakefile(), + cmTarget::Visibility::Normal, tgt->Target->GetMakefile(), cmTarget::PerConfig::Yes); cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator()); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index f83be26..be6456b 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1237,6 +1237,16 @@ bool cmGeneratorTarget::IsInBuildSystem() const return false; } +bool cmGeneratorTarget::IsNormal() const +{ + return this->Target->IsNormal(); +} + +bool cmGeneratorTarget::IsSynthetic() const +{ + return this->Target->IsSynthetic(); +} + bool cmGeneratorTarget::IsImported() const { return this->Target->IsImported(); @@ -7105,6 +7115,11 @@ cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo( return nullptr; } + // Synthetic targets don't have output. + if (this->IsSynthetic()) { + return nullptr; + } + // Only libraries and executables have well-defined output files. if (!this->HaveWellDefinedOutputFiles()) { std::string msg = cmStrCat("cmGeneratorTarget::GetOutputInfo called for ", diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index afd9da4..e46c719 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -50,6 +50,8 @@ public: cmGlobalGenerator* GetGlobalGenerator() const; bool IsInBuildSystem() const; + bool IsNormal() const; + bool IsSynthetic() const; bool IsImported() const; bool IsImportedGloballyVisible() const; bool CanCompileSources() const; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 0ad0e6e..d963a5a 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2115,12 +2115,21 @@ cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type, return &this->CreateNewTarget(name, type).first; } +cmTarget* cmMakefile::AddSynthesizedTarget(cmStateEnums::TargetType type, + const std::string& name) +{ + return &this + ->CreateNewTarget(name, type, cmTarget::PerConfig::Yes, + cmTarget::Visibility::Generated) + .first; +} + std::pair<cmTarget&, bool> cmMakefile::CreateNewTarget( const std::string& name, cmStateEnums::TargetType type, - cmTarget::PerConfig perConfig) + cmTarget::PerConfig perConfig, cmTarget::Visibility vis) { - auto ib = this->Targets.emplace( - name, cmTarget(name, type, cmTarget::VisibilityNormal, this, perConfig)); + auto ib = + this->Targets.emplace(name, cmTarget(name, type, vis, this, perConfig)); auto it = ib.first; if (!ib.second) { return std::make_pair(std::ref(it->second), false); @@ -4203,8 +4212,8 @@ cmTarget* cmMakefile::AddImportedTarget(const std::string& name, // Create the target. std::unique_ptr<cmTarget> target( new cmTarget(name, type, - global ? cmTarget::VisibilityImportedGlobally - : cmTarget::VisibilityImported, + global ? cmTarget::Visibility::ImportedGlobally + : cmTarget::Visibility::Imported, this, cmTarget::PerConfig::Yes)); // Add to the set of available imported targets. diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 3866aca..7b19c97 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -241,10 +241,13 @@ public: std::pair<cmTarget&, bool> CreateNewTarget( const std::string& name, cmStateEnums::TargetType type, - cmTarget::PerConfig perConfig = cmTarget::PerConfig::Yes); + cmTarget::PerConfig perConfig = cmTarget::PerConfig::Yes, + cmTarget::Visibility vis = cmTarget::Visibility::Normal); cmTarget* AddNewTarget(cmStateEnums::TargetType type, const std::string& name); + cmTarget* AddSynthesizedTarget(cmStateEnums::TargetType type, + const std::string& name); /** Create a target instance for the utility. */ cmTarget* AddNewUtilityTarget(const std::string& utilityName, diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index e8d66cc..91d5de6 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -629,10 +629,9 @@ public: bool IsDLLPlatform; bool IsAIX; bool IsAndroid; - bool IsImportedTarget; - bool ImportedGloballyVisible; bool BuildInterfaceIncludesAppended; bool PerConfig; + cmTarget::Visibility TargetVisibility; std::set<BT<std::pair<std::string, bool>>> Utilities; std::vector<cmCustomCommand> PreBuildCommands; std::vector<cmCustomCommand> PreLinkCommands; @@ -667,6 +666,8 @@ public: cmTargetInternals(); + bool IsImported() const; + bool CheckImportedLibName(std::string const& prop, std::string const& value) const; @@ -914,9 +915,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, this->impl->IsDLLPlatform = false; this->impl->IsAIX = false; this->impl->IsAndroid = false; - this->impl->IsImportedTarget = - (vis == VisibilityImported || vis == VisibilityImportedGlobally); - this->impl->ImportedGloballyVisible = vis == VisibilityImportedGlobally; + this->impl->TargetVisibility = vis; this->impl->BuildInterfaceIncludesAppended = false; this->impl->PerConfig = (perConfig == PerConfig::Yes); @@ -939,7 +938,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, // Save the backtrace of target construction. this->impl->Backtrace = this->impl->Makefile->GetBacktrace(); - if (!this->IsImported()) { + if (this->IsNormal()) { // Initialize the INCLUDE_DIRECTORIES property based on the current value // of the same directory property: this->impl->IncludeDirectories.CopyFromDirectory( @@ -988,7 +987,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, if (this->impl->TargetType != cmStateEnums::UTILITY && this->impl->TargetType != cmStateEnums::GLOBAL_TARGET) { metConditions.insert(TargetProperty::InitCondition::NormalTarget); - if (!this->IsImported()) { + if (this->IsNormal()) { metConditions.insert( TargetProperty::InitCondition::NormalNonImportedTarget); } @@ -1091,7 +1090,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, } } - if (this->IsImported() || mf->GetPropertyAsBool("SYSTEM")) { + if (!this->IsNormal() || mf->GetPropertyAsBool("SYSTEM")) { this->SetProperty("SYSTEM", "ON"); } @@ -1863,8 +1862,8 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) return; } /* no need to change anything if value does not change */ - if (!this->impl->ImportedGloballyVisible) { - this->impl->ImportedGloballyVisible = true; + if (!this->IsImportedGloballyVisible()) { + this->impl->TargetVisibility = Visibility::ImportedGlobally; this->GetGlobalGenerator()->IndexTarget(this); } } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") && @@ -2555,14 +2554,65 @@ bool cmTarget::IsAIX() const return this->impl->IsAIX; } +bool cmTarget::IsNormal() const +{ + switch (this->impl->TargetVisibility) { + case Visibility::Normal: + return true; + case Visibility::Generated: + case Visibility::Imported: + case Visibility::ImportedGlobally: + return false; + } + assert(false && "unknown visibility (IsNormal)"); + return false; +} + +bool cmTarget::IsSynthetic() const +{ + switch (this->impl->TargetVisibility) { + case Visibility::Generated: + return true; + case Visibility::Normal: + case Visibility::Imported: + case Visibility::ImportedGlobally: + return false; + } + assert(false && "unknown visibility (IsSynthetic)"); + return false; +} + +bool cmTargetInternals::IsImported() const +{ + switch (this->TargetVisibility) { + case cmTarget::Visibility::Imported: + case cmTarget::Visibility::ImportedGlobally: + return true; + case cmTarget::Visibility::Normal: + case cmTarget::Visibility::Generated: + return false; + } + assert(false && "unknown visibility (IsImported)"); + return false; +} + bool cmTarget::IsImported() const { - return this->impl->IsImportedTarget; + return this->impl->IsImported(); } bool cmTarget::IsImportedGloballyVisible() const { - return this->impl->ImportedGloballyVisible; + switch (this->impl->TargetVisibility) { + case Visibility::ImportedGlobally: + return true; + case Visibility::Normal: + case Visibility::Generated: + case Visibility::Imported: + return false; + } + assert(false && "unknown visibility (IsImportedGloballyVisible)"); + return false; } bool cmTarget::IsPerConfig() const @@ -2858,7 +2908,7 @@ bool cmTargetInternals::CheckImportedLibName(std::string const& prop, std::string const& value) const { if (this->TargetType != cmStateEnums::INTERFACE_LIBRARY || - !this->IsImportedTarget) { + !this->IsImported()) { this->Makefile->IssueMessage( MessageType::FATAL_ERROR, prop + diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 38bd036..95539fa 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -46,11 +46,12 @@ class BTs; class cmTarget { public: - enum Visibility + enum class Visibility { - VisibilityNormal, - VisibilityImported, - VisibilityImportedGlobally + Normal, + Generated, + Imported, + ImportedGlobally, }; enum class PerConfig @@ -205,6 +206,8 @@ public: //! Return whether or not we are targeting AIX. bool IsAIX() const; + bool IsNormal() const; + bool IsSynthetic() const; bool IsImported() const; bool IsImportedGloballyVisible() const; bool IsPerConfig() const; |