From 9f8edd6ac3d04bc79981af3143d4bde6758dd91d Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 15 Jul 2020 09:09:13 -0400 Subject: cmLocalUnixMakefileGenerator3: Skip object file listing for custom targets --- Source/cmLocalUnixMakefileGenerator3.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index df4bf6a..88754a8 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -137,7 +137,8 @@ void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles( std::map& localObjectFiles) { for (const auto& gt : this->GetGeneratorTargets()) { - if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY || + gt->GetType() == cmStateEnums::UTILITY) { continue; } std::vector objectSources; -- cgit v0.12 From 159a4d6b11f0feb0be7cfa692ee4738acddfef8d Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 20 Jul 2020 12:02:04 -0400 Subject: cmGlobalNinjaGenerator: Replace switch default with all cases --- Source/cmGlobalNinjaGenerator.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 786cde7..80eae82 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -1105,8 +1105,9 @@ void cmGlobalNinjaGenerator::AppendTargetOutputs( break; } - default: - return; + case cmStateEnums::INTERFACE_LIBRARY: + case cmStateEnums::UNKNOWN_LIBRARY: + break; } } -- cgit v0.12 From 2f44a6a4990497c45eb882e625b2204a372ffaf0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 21 Jul 2020 09:50:22 -0400 Subject: cmTarget: De-duplicate conditions for property initialization --- Source/cmTarget.cxx | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index aec9afa..0f0e35b 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -343,10 +343,12 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, initProp("C_STANDARD"); initProp("C_STANDARD_REQUIRED"); initProp("C_EXTENSIONS"); + initProp("C_VISIBILITY_PRESET"); initProp("OBJC_COMPILER_LAUNCHER"); initProp("OBJC_STANDARD"); initProp("OBJC_STANDARD_REQUIRED"); initProp("OBJC_EXTENSIONS"); + initProp("OBJC_VISIBILITY_PRESET"); initProp("CXX_CLANG_TIDY"); initProp("CXX_COMPILER_LAUNCHER"); initProp("CXX_CPPLINT"); @@ -355,10 +357,12 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, initProp("CXX_STANDARD"); initProp("CXX_STANDARD_REQUIRED"); initProp("CXX_EXTENSIONS"); + initProp("CXX_VISIBILITY_PRESET"); initProp("OBJCXX_COMPILER_LAUNCHER"); initProp("OBJCXX_STANDARD"); initProp("OBJCXX_STANDARD_REQUIRED"); initProp("OBJCXX_EXTENSIONS"); + initProp("OBJCXX_VISIBILITY_PRESET"); initProp("CUDA_STANDARD"); initProp("CUDA_STANDARD_REQUIRED"); initProp("CUDA_EXTENSIONS"); @@ -367,6 +371,11 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, initProp("CUDA_RESOLVE_DEVICE_SYMBOLS"); initProp("CUDA_RUNTIME_LIBRARY"); initProp("CUDA_ARCHITECTURES"); + initProp("CUDA_VISIBILITY_PRESET"); + initProp("VISIBILITY_INLINES_HIDDEN"); + initProp("JOB_POOL_COMPILE"); + initProp("JOB_POOL_LINK"); + initProp("JOB_POOL_PRECOMPILE_HEADER"); initProp("LINK_SEARCH_START_STATIC"); initProp("LINK_SEARCH_END_STATIC"); initProp("Swift_LANGUAGE_VERSION"); @@ -487,16 +496,6 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, impl->Makefile->GetLinkDirectoriesBacktraces()); } - if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY && - this->GetType() != cmStateEnums::UTILITY) { - initProp("C_VISIBILITY_PRESET"); - initProp("CXX_VISIBILITY_PRESET"); - initProp("OBJC_VISIBILITY_PRESET"); - initProp("OBJCXX_VISIBILITY_PRESET"); - initProp("CUDA_VISIBILITY_PRESET"); - initProp("VISIBILITY_INLINES_HIDDEN"); - } - if (impl->TargetType == cmStateEnums::EXECUTABLE) { initProp("ANDROID_GUI"); initProp("CROSSCOMPILING_EMULATOR"); @@ -528,13 +527,6 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, impl->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW); } - if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY && - this->GetType() != cmStateEnums::UTILITY) { - initProp("JOB_POOL_COMPILE"); - initProp("JOB_POOL_LINK"); - initProp("JOB_POOL_PRECOMPILE_HEADER"); - } - if (impl->TargetType <= cmStateEnums::GLOBAL_TARGET) { initProp("DOTNET_TARGET_FRAMEWORK"); initProp("DOTNET_TARGET_FRAMEWORK_VERSION"); -- cgit v0.12 From 6fd7ca5e5126067b2b346b76473adf240fcd8151 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 21 Jul 2020 13:20:10 -0400 Subject: cmTarget: Skip output dir property init for CMake-provided targets --- Source/cmTarget.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 0f0e35b..083095b 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -419,7 +419,8 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, } // Setup per-configuration property default values. - if (this->GetType() != cmStateEnums::UTILITY) { + if (this->GetType() != cmStateEnums::UTILITY && + this->GetType() != cmStateEnums::GLOBAL_TARGET) { static const auto configProps = { /* clang-format needs this comment to break after the opening brace */ "ARCHIVE_OUTPUT_DIRECTORY_", "LIBRARY_OUTPUT_DIRECTORY_", -- cgit v0.12 From bce82df0aaa4046b31fcf0608f0ce1249bdfc9bd Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 23 Jul 2020 13:19:08 -0400 Subject: cmGeneratorTarget: Remove unnecessary target type check in dependency tracing Since commit 2600e923a6 (Disallow INTERFACE libraries with add_custom_command(TARGET)., 2014-03-19, v3.0.0-rc3~1^2), we do not trace dependencies of INTERFACE libraries that do not participate in the build system. Therefore we can remove a check of the target type from the implementation that had been added by commit 9db9c1fc8b (cmTarget: Don't try to get sources of an INTERFACE_LIBRARY., 2014-02-14, v3.0.0-rc1~20^2). --- Source/cmGeneratorTarget.cxx | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index b10ce89..bfefbe6 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -2813,29 +2813,26 @@ cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target) this->CurrentEntry = nullptr; // Queue all the source files already specified for the target. - if (target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { - std::set emitted; - std::vector const& configs = - this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); - for (std::string const& c : configs) { - std::vector sources; - this->GeneratorTarget->GetSourceFiles(sources, c); - for (cmSourceFile* sf : sources) { - const std::set tgts = - this->GlobalGenerator->GetFilenameTargetDepends(sf); - if (cm::contains(tgts, this->GeneratorTarget)) { - std::ostringstream e; - e << "Evaluation output file\n \"" << sf->ResolveFullPath() - << "\"\ndepends on the sources of a target it is used in. This " - "is a dependency loop and is not allowed."; - this->GeneratorTarget->LocalGenerator->IssueMessage( - MessageType::FATAL_ERROR, e.str()); - return; - } - if (emitted.insert(sf).second && - this->SourcesQueued.insert(sf).second) { - this->SourceQueue.push(sf); - } + std::set emitted; + std::vector const& configs = + this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); + for (std::string const& c : configs) { + std::vector sources; + this->GeneratorTarget->GetSourceFiles(sources, c); + for (cmSourceFile* sf : sources) { + const std::set tgts = + this->GlobalGenerator->GetFilenameTargetDepends(sf); + if (cm::contains(tgts, this->GeneratorTarget)) { + std::ostringstream e; + e << "Evaluation output file\n \"" << sf->ResolveFullPath() + << "\"\ndepends on the sources of a target it is used in. This " + "is a dependency loop and is not allowed."; + this->GeneratorTarget->LocalGenerator->IssueMessage( + MessageType::FATAL_ERROR, e.str()); + return; + } + if (emitted.insert(sf).second && this->SourcesQueued.insert(sf).second) { + this->SourceQueue.push(sf); } } } -- cgit v0.12 From 422d9a0ab21ff430e5fd012cf965dd92068d185f Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 20 Jul 2020 11:30:38 -0400 Subject: Factor out generator checks for filtering out interface libraries Add a `cmGeneratorTarget::IsInBuildSystem` helper method to tell generators whether a target should participate in the generated build system. --- Source/cmComputeTargetDepends.cxx | 9 ++++----- Source/cmGeneratorTarget.cxx | 23 ++++++++++++++++++++++- Source/cmGeneratorTarget.h | 1 + Source/cmGlobalCommonGenerator.cxx | 7 +------ Source/cmGlobalGenerator.cxx | 4 ++-- Source/cmGlobalGhsMultiGenerator.cxx | 2 +- Source/cmGlobalNinjaGenerator.cxx | 4 ++-- Source/cmGlobalUnixMakefileGenerator3.cxx | 7 +++---- Source/cmGlobalVisualStudio7Generator.cxx | 6 +++--- Source/cmGlobalVisualStudio8Generator.cxx | 4 ++-- Source/cmGlobalVisualStudioGenerator.cxx | 2 +- Source/cmGlobalXCodeGenerator.cxx | 18 +++++++----------- Source/cmLocalGenerator.cxx | 4 ++-- Source/cmLocalGhsMultiGenerator.cxx | 3 +-- Source/cmLocalNinjaGenerator.cxx | 2 +- Source/cmLocalUnixMakefileGenerator3.cxx | 2 +- Source/cmLocalVisualStudio10Generator.cxx | 2 +- Source/cmLocalVisualStudio7Generator.cxx | 4 ++-- Source/cmVisualStudio10TargetGenerator.cxx | 2 +- 19 files changed, 58 insertions(+), 48 deletions(-) diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index 6b4d110..6846f57 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -184,7 +184,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) { // Get the depender. cmGeneratorTarget const* depender = this->Targets[depender_index]; - if (depender->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!depender->IsInBuildSystem()) { return; } @@ -356,10 +356,9 @@ void cmComputeTargetDepends::AddTargetDepend( int depender_index, cmGeneratorTarget const* dependee, cmListFileBacktrace const& dependee_backtrace, bool linking, bool cross) { - if (dependee->IsImported() || - dependee->GetType() == cmStateEnums::INTERFACE_LIBRARY) { - // Skip IMPORTED and INTERFACE targets but follow their utility - // dependencies. + if (!dependee->IsInBuildSystem()) { + // Skip targets that are not in the buildsystem but follow their + // utility dependencies. std::set const& utils = dependee->GetUtilityItems(); for (cmLinkItem const& i : utils) { if (cmGeneratorTarget const* transitive_dependee = i.Target) { diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index bfefbe6..9978320 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1089,6 +1089,27 @@ std::vector const& cmGeneratorTarget::GetPostBuildCommands() return this->Target->GetPostBuildCommands(); } +bool cmGeneratorTarget::IsInBuildSystem() const +{ + if (this->IsImported()) { + return false; + } + switch (this->Target->GetType()) { + case cmStateEnums::EXECUTABLE: + case cmStateEnums::STATIC_LIBRARY: + case cmStateEnums::SHARED_LIBRARY: + case cmStateEnums::MODULE_LIBRARY: + case cmStateEnums::OBJECT_LIBRARY: + case cmStateEnums::UTILITY: + case cmStateEnums::GLOBAL_TARGET: + return true; + case cmStateEnums::INTERFACE_LIBRARY: + case cmStateEnums::UNKNOWN_LIBRARY: + break; + } + return false; +} + bool cmGeneratorTarget::IsImported() const { return this->Target->IsImported(); @@ -1365,7 +1386,7 @@ void AddSwiftImplicitIncludeDirectories( for (const cmLinkImplItem& library : libraries->Libraries) { if (const cmGeneratorTarget* dependency = library.Target) { - if (dependency->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!dependency->IsInBuildSystem()) { continue; } if (cm::contains(dependency->GetAllConfigCompileLanguages(), diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 08aa015..65683e6 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -45,6 +45,7 @@ public: cmGlobalGenerator* GetGlobalGenerator() const; + bool IsInBuildSystem() const; bool IsImported() const; bool IsImportedGloballyVisible() const; const std::string& GetLocation(const std::string& config) const; diff --git a/Source/cmGlobalCommonGenerator.cxx b/Source/cmGlobalCommonGenerator.cxx index 5eff3b8..9e5bbca 100644 --- a/Source/cmGlobalCommonGenerator.cxx +++ b/Source/cmGlobalCommonGenerator.cxx @@ -42,12 +42,7 @@ cmGlobalCommonGenerator::ComputeDirectoryTargets() const // for all targets in the directory. for (const auto& gt : lg->GetGeneratorTargets()) { cmStateEnums::TargetType const type = gt->GetType(); - if (type != cmStateEnums::EXECUTABLE && - type != cmStateEnums::STATIC_LIBRARY && - type != cmStateEnums::SHARED_LIBRARY && - type != cmStateEnums::MODULE_LIBRARY && - type != cmStateEnums::OBJECT_LIBRARY && - type != cmStateEnums::UTILITY) { + if (type == cmStateEnums::GLOBAL_TARGET || !gt->IsInBuildSystem()) { continue; } DirectoryTarget::Target t; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 5c07e31..b79dfde 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2165,7 +2165,7 @@ bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root, bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root, const cmGeneratorTarget* target) const { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!target->IsInBuildSystem()) { return true; } cmMakefile* mf = root->GetMakefile(); @@ -3054,7 +3054,7 @@ void cmGlobalGenerator::WriteSummary() for (const auto& lg : this->LocalGenerators) { for (const auto& tgt : lg->GetGeneratorTargets()) { - if (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!tgt->IsInBuildSystem()) { continue; } this->WriteSummary(tgt.get()); diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index 1664dd0..9969465 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -467,7 +467,7 @@ void cmGlobalGhsMultiGenerator::WriteAllTarget( this->ProjectTargets.push_back(t); } for (cmGeneratorTarget const* t : sortedProjectTargets) { - if (t->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!t->IsInBuildSystem()) { continue; } if (!IsExcluded(t->GetLocalGenerator(), t)) { diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 80eae82..86ed1e9 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -1129,7 +1129,7 @@ void cmGlobalNinjaGenerator::AppendTargetDepends( cmNinjaDeps outs; for (cmTargetDepend const& targetDep : this->GetTargetDirectDepends(target)) { - if (targetDep->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!targetDep->IsInBuildSystem()) { continue; } if (targetDep.IsCross()) { @@ -1171,7 +1171,7 @@ void cmGlobalNinjaGenerator::AppendTargetDependsClosure( cmNinjaOuts this_outs; // this will be the new cache entry for (auto const& dep_target : this->GetTargetDirectDepends(target)) { - if (dep_target->GetType() == cmStateEnums::INTERFACE_LIBRARY || + if (!dep_target->IsInBuildSystem() || (this->EnableCrossConfigBuild() && !dep_target.IsCross())) { continue; } diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 1764429..ebc90b6 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -845,8 +845,7 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks() for (const auto& gt : lg->GetGeneratorTargets()) { cmLocalGenerator* tlg = gt->GetLocalGenerator(); - if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY || - IsExcluded(lg.get(), gt.get())) { + if (!gt->IsInBuildSystem() || IsExcluded(lg.get(), gt.get())) { continue; } @@ -881,7 +880,7 @@ size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInTarget( if (emitted.insert(target).second) { count = this->ProgressMap[target].Marks.size(); for (cmTargetDepend const& depend : this->GetTargetDirectDepends(target)) { - if (depend->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!depend->IsInBuildSystem()) { continue; } count += this->CountProgressMarksInTarget(depend, emitted); @@ -938,7 +937,7 @@ void cmGlobalUnixMakefileGenerator3::AppendGlobalTargetDepends( for (cmTargetDepend const& i : this->GetTargetDirectDepends(target)) { // Create the target-level dependency. cmGeneratorTarget const* dep = i; - if (dep->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!dep->IsInBuildSystem()) { continue; } cmLocalUnixMakefileGenerator3* lg3 = diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index c851eea..f8b438a 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -339,7 +339,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetConfigurations( // loop over again and write out configurations for each target // in the solution for (cmGeneratorTarget const* target : projectTargets) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!target->IsInBuildSystem()) { continue; } cmProp expath = target->GetProperty("EXTERNAL_MSPROJECT"); @@ -369,7 +369,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( std::string rootBinaryDir = root->GetCurrentBinaryDirectory(); for (cmGeneratorTarget const* target : projectTargets) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!target->IsInBuildSystem()) { continue; } bool written = false; @@ -436,7 +436,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetDepends( std::ostream& fout, OrderedTargetDependSet const& projectTargets) { for (cmGeneratorTarget const* target : projectTargets) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!target->IsInBuildSystem()) { continue; } cmProp vcprojName = target->GetProperty("GENERATOR_FILE_NAME"); diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 29ca154..fcdfc50 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -325,7 +325,7 @@ void cmGlobalVisualStudio8Generator::WriteProjectDepends( TargetDependSet const& unordered = this->GetTargetDirectDepends(gt); OrderedTargetDependSet depends(unordered, std::string()); for (cmTargetDepend const& i : depends) { - if (i->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!i->IsInBuildSystem()) { continue; } std::string guid = this->GetGUID(i->GetName()); @@ -341,7 +341,7 @@ bool cmGlobalVisualStudio8Generator::NeedLinkLibraryDependencies( if (cmGeneratorTarget* depTarget = target->GetLocalGenerator()->FindGeneratorTargetToUse( ui.Value.first)) { - if (depTarget->GetType() != cmStateEnums::INTERFACE_LIBRARY && + if (depTarget->IsInBuildSystem() && depTarget->GetProperty("EXTERNAL_MSPROJECT")) { // This utility dependency names an external .vcproj target. // We use LinkLibraryDependencies="true" to link to it without diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index b31d069..001d876 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -368,7 +368,7 @@ cmGlobalVisualStudioGenerator::GetTargetLinkClosure(cmGeneratorTarget* target) void cmGlobalVisualStudioGenerator::FollowLinkDepends( const cmGeneratorTarget* target, std::set& linked) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!target->IsInBuildSystem()) { return; } if (linked.insert(target).second && diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index e54de5d..26760ea 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1199,7 +1199,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTarget( return true; } - if (gtgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!gtgt->IsInBuildSystem()) { return true; } @@ -1845,7 +1845,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, cmXCodeObject* buildSettings, const std::string& configName) { - if (gtgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!gtgt->IsInBuildSystem()) { return; } @@ -2678,7 +2678,7 @@ const char* cmGlobalXCodeGenerator::GetTargetProductType( cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeTarget( cmGeneratorTarget* gtgt, cmXCodeObject* buildPhases) { - if (gtgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!gtgt->IsInBuildSystem()) { return nullptr; } cmXCodeObject* target = this->CreateObject(cmXCodeObject::PBXNativeTarget); @@ -2821,7 +2821,7 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) cmSystemTools::Error("Error no target on xobject\n"); return; } - if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!gt->IsInBuildSystem()) { return; } @@ -3113,13 +3113,9 @@ bool cmGlobalXCodeGenerator::CreateGroups( // end up with (empty anyhow) ZERO_CHECK, install, or test source // groups: // - if (gtgt->GetType() == cmStateEnums::GLOBAL_TARGET) { - continue; - } - if (gtgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { - continue; - } - if (gtgt->GetName() == CMAKE_CHECK_BUILD_SYSTEM_TARGET) { + if (!gtgt->IsInBuildSystem() || + gtgt->GetType() == cmStateEnums::GLOBAL_TARGET || + gtgt->GetName() == CMAKE_CHECK_BUILD_SYSTEM_TARGET) { continue; } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 028053d..a39ed68 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -284,7 +284,7 @@ void cmLocalGenerator::TraceDependencies() // Generate the rule files for each target. const auto& targets = this->GetGeneratorTargets(); for (const auto& target : targets) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!target->IsInBuildSystem()) { continue; } target->TraceDependencies(); @@ -760,7 +760,7 @@ void cmLocalGenerator::ComputeTargetManifest() // Add our targets to the manifest for each configuration. const auto& targets = this->GetGeneratorTargets(); for (const auto& target : targets) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!target->IsInBuildSystem()) { continue; } for (std::string const& c : configNames) { diff --git a/Source/cmLocalGhsMultiGenerator.cxx b/Source/cmLocalGhsMultiGenerator.cxx index 098fa5a..a23ad57 100644 --- a/Source/cmLocalGhsMultiGenerator.cxx +++ b/Source/cmLocalGhsMultiGenerator.cxx @@ -11,7 +11,6 @@ #include "cmGhsMultiTargetGenerator.h" #include "cmGlobalGenerator.h" #include "cmSourceFile.h" -#include "cmStateTypes.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -33,7 +32,7 @@ std::string cmLocalGhsMultiGenerator::GetTargetDirectory( void cmLocalGhsMultiGenerator::GenerateTargetsDepthFirst( cmGeneratorTarget* target, std::vector& remaining) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!target->IsInBuildSystem()) { return; } // Find this target in the list of remaining targets. diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index aee7f45..50aa955 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -90,7 +90,7 @@ void cmLocalNinjaGenerator::Generate() } for (const auto& target : this->GetGeneratorTargets()) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!target->IsInBuildSystem()) { continue; } auto tg = cmNinjaTargetGenerator::New(target.get()); diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 88754a8..08f0a5f 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -101,7 +101,7 @@ void cmLocalUnixMakefileGenerator3::Generate() cmGlobalUnixMakefileGenerator3* gg = static_cast(this->GlobalGenerator); for (const auto& target : this->GetGeneratorTargets()) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!target->IsInBuildSystem()) { continue; } std::unique_ptr tg( diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx index 9076e26..6c7d6c6 100644 --- a/Source/cmLocalVisualStudio10Generator.cxx +++ b/Source/cmLocalVisualStudio10Generator.cxx @@ -69,7 +69,7 @@ cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator() void cmLocalVisualStudio10Generator::GenerateTargetsDepthFirst( cmGeneratorTarget* target, std::vector& remaining) { - if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!target->IsInBuildSystem()) { return; } // Find this target in the list of remaining targets. diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index ad61ad3..fec6a9d 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -66,7 +66,7 @@ void cmLocalVisualStudio7Generator::AddHelperCommands() // Now create GUIDs for targets const auto& tgts = this->GetGeneratorTargets(); for (const auto& l : tgts) { - if (l->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!l->IsInBuildSystem()) { continue; } cmProp path = l->GetProperty("EXTERNAL_MSPROJECT"); @@ -129,7 +129,7 @@ void cmLocalVisualStudio7Generator::WriteProjectFiles() // Create the project file for each target. for (const auto& l : tgts) { - if (l->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!l->IsInBuildSystem()) { continue; } // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index f291cbd..f0d520a 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -4138,7 +4138,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0) Elem e1(e0, "ItemGroup"); e1.SetHasElements(); for (cmGeneratorTarget const* dt : depends) { - if (dt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + if (!dt->IsInBuildSystem()) { continue; } // skip fortran targets as they can not be processed by MSBuild -- cgit v0.12 From 2f0790df5046bfc99383317eb7d24cd4030200be Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 21 Jul 2020 13:22:26 -0400 Subject: Factor out generator checks for filtering on non-compiling targets Add a `cmGeneratorTarget::CanCompileSources` helper method to tell generators whether a target might compile anything. --- Source/cmGeneratorTarget.cxx | 5 +++++ Source/cmGeneratorTarget.h | 1 + Source/cmGlobalGenerator.cxx | 16 ++++------------ Source/cmLocalGenerator.cxx | 2 +- Source/cmLocalUnixMakefileGenerator3.cxx | 3 +-- Source/cmTarget.cxx | 31 ++++++++++++++++++++++++------- Source/cmTarget.h | 1 + 7 files changed, 37 insertions(+), 22 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 9978320..beafdea 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1120,6 +1120,11 @@ bool cmGeneratorTarget::IsImportedGloballyVisible() const return this->Target->IsImportedGloballyVisible(); } +bool cmGeneratorTarget::CanCompileSources() const +{ + return this->Target->CanCompileSources(); +} + const std::string& cmGeneratorTarget::GetLocationForBuild() const { static std::string location; diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 65683e6..4a03f65 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -48,6 +48,7 @@ public: bool IsInBuildSystem() const; bool IsImported() const; bool IsImportedGloballyVisible() const; + bool CanCompileSources() const; const std::string& GetLocation(const std::string& config) const; std::vector const& GetPreBuildCommands() const; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index b79dfde..ac94a28 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -302,9 +302,7 @@ bool cmGlobalGenerator::CheckTargetsForMissingSources() const bool failed = false; for (const auto& localGen : this->LocalGenerators) { for (const auto& target : localGen->GetGeneratorTargets()) { - if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET || - target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY || - target->GetType() == cmStateEnums::TargetType::UTILITY || + if (!target->CanCompileSources() || cmIsOn(target->GetProperty("ghs_integrity_app"))) { continue; } @@ -358,9 +356,7 @@ bool cmGlobalGenerator::CheckTargetsForPchCompilePdb() const bool failed = false; for (const auto& generator : this->LocalGenerators) { for (const auto& target : generator->GetGeneratorTargets()) { - if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET || - target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY || - target->GetType() == cmStateEnums::TargetType::UTILITY || + if (!target->CanCompileSources() || cmIsOn(target->GetProperty("ghs_integrity_app"))) { continue; } @@ -1595,9 +1591,7 @@ bool cmGlobalGenerator::AddAutomaticSources() for (const auto& lg : this->LocalGenerators) { lg->CreateEvaluationFileOutputs(); for (const auto& gt : lg->GetGeneratorTargets()) { - if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY || - gt->GetType() == cmStateEnums::UTILITY || - gt->GetType() == cmStateEnums::GLOBAL_TARGET) { + if (!gt->CanCompileSources()) { continue; } lg->AddUnityBuild(gt.get()); @@ -1609,9 +1603,7 @@ bool cmGlobalGenerator::AddAutomaticSources() } for (const auto& lg : this->LocalGenerators) { for (const auto& gt : lg->GetGeneratorTargets()) { - if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY || - gt->GetType() == cmStateEnums::UTILITY || - gt->GetType() == cmStateEnums::GLOBAL_TARGET) { + if (!gt->CanCompileSources()) { continue; } // Handle targets that re-use a PCH from an above-handled target. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index a39ed68..646cf5e 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -797,7 +797,7 @@ bool cmLocalGenerator::ComputeTargetCompileFeatures() // Now that C/C++ _STANDARD values have been computed // set the values to ObjC/ObjCXX _STANDARD variables - if (target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { + if (target->CanCompileSources()) { for (std::string const& c : configNames) { target->ComputeCompileFeatures(c, inferredEnabledLanguages); } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 08f0a5f..23e2a94 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -137,8 +137,7 @@ void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles( std::map& localObjectFiles) { for (const auto& gt : this->GetGeneratorTargets()) { - if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY || - gt->GetType() == cmStateEnums::UTILITY) { + if (!gt->CanCompileSources()) { continue; } std::vector objectSources; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 083095b..70bffa6 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -272,8 +272,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, }; // Setup default property values. - if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY && - this->GetType() != cmStateEnums::UTILITY) { + if (this->CanCompileSources()) { initProp("ANDROID_API"); initProp("ANDROID_API_MIN"); initProp("ANDROID_ARCH"); @@ -505,6 +504,8 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, if (impl->TargetType == cmStateEnums::SHARED_LIBRARY || impl->TargetType == cmStateEnums::MODULE_LIBRARY) { this->SetProperty("POSITION_INDEPENDENT_CODE", "True"); + } else if (this->CanCompileSources()) { + initProp("POSITION_INDEPENDENT_CODE"); } if (impl->TargetType == cmStateEnums::SHARED_LIBRARY || impl->TargetType == cmStateEnums::EXECUTABLE) { @@ -512,11 +513,6 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, initProp("WINDOWS_EXPORT_ALL_SYMBOLS"); } - if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY && - this->GetType() != cmStateEnums::UTILITY) { - initProp("POSITION_INDEPENDENT_CODE"); - } - // Record current policies for later use. impl->Makefile->RecordPolicies(impl->PolicyMap); @@ -1910,6 +1906,27 @@ bool cmTarget::IsPerConfig() const return impl->PerConfig; } +bool cmTarget::CanCompileSources() const +{ + if (this->IsImported()) { + return false; + } + switch (this->GetType()) { + case cmStateEnums::EXECUTABLE: + case cmStateEnums::STATIC_LIBRARY: + case cmStateEnums::SHARED_LIBRARY: + case cmStateEnums::MODULE_LIBRARY: + case cmStateEnums::OBJECT_LIBRARY: + return true; + case cmStateEnums::UTILITY: + case cmStateEnums::INTERFACE_LIBRARY: + case cmStateEnums::GLOBAL_TARGET: + case cmStateEnums::UNKNOWN_LIBRARY: + break; + } + return false; +} + const char* cmTarget::GetSuffixVariableInternal( cmStateEnums::ArtifactType artifact) const { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 7a16de8..43f1887 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -196,6 +196,7 @@ public: bool IsImported() const; bool IsImportedGloballyVisible() const; bool IsPerConfig() const; + bool CanCompileSources() const; bool GetMappedConfig(std::string const& desired_config, cmProp& loc, cmProp& imp, std::string& suffix) const; -- cgit v0.12 From 95b5df8646fa2b02c5eba175570f83fc6e2ece55 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 22 Jul 2020 10:45:33 -0400 Subject: cmGeneratorTarget: Skip computing languages for custom targets Targets created by `add_custom_target` do not compile any sources and therefore have no languages. --- Source/cmGeneratorTarget.cxx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index beafdea..554a954 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -7013,6 +7013,11 @@ std::string cmGeneratorTarget::GetDeprecation() const void cmGeneratorTarget::GetLanguages(std::set& languages, const std::string& config) const { + // Targets that do not compile anything have no languages. + if (!this->CanCompileSources()) { + return; + } + std::vector sourceFiles; this->GetSourceFiles(sourceFiles, config); for (cmSourceFile* src : sourceFiles) { -- cgit v0.12 From 7695b67500d3518c6fc935430e681035a442b692 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 22 Jul 2020 12:01:01 -0400 Subject: cmComputeTargetDepends: Add missing nullptr check Check the result of `GetLinkImplementation` before using it. --- Source/cmComputeTargetDepends.cxx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index 6846f57..06ad64d 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -198,16 +198,18 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) std::vector const& configs = depender->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); for (std::string const& it : configs) { - cmLinkImplementation const* impl = depender->GetLinkImplementation(it); - // A target should not depend on itself. emitted.insert(cmLinkItem(depender, false, cmListFileBacktrace())); emitted.insert(cmLinkItem(depender, true, cmListFileBacktrace())); - for (cmLinkImplItem const& lib : impl->Libraries) { - // Don't emit the same library twice for this target. - if (emitted.insert(lib).second) { - this->AddTargetDepend(depender_index, lib, true, false); - this->AddInterfaceDepends(depender_index, lib, it, emitted); + + if (cmLinkImplementation const* impl = + depender->GetLinkImplementation(it)) { + for (cmLinkImplItem const& lib : impl->Libraries) { + // Don't emit the same library twice for this target. + if (emitted.insert(lib).second) { + this->AddTargetDepend(depender_index, lib, true, false); + this->AddInterfaceDepends(depender_index, lib, it, emitted); + } } } -- cgit v0.12 From d6b1f5704e9d22c371ac30c8b02a188a9d80e6cc Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 22 Jul 2020 12:01:42 -0400 Subject: cmGeneratorTarget: Add missing nullptr checks Check the result of `GetLinkImplementationLibraries` before using it. --- Source/cmGeneratorTarget.cxx | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 554a954..2284d68 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -2790,6 +2790,7 @@ cmGeneratorTarget::GetLinkImplementationClosure( cmLinkImplementationLibraries const* impl = this->GetLinkImplementationLibraries(config); + assert(impl); for (cmLinkImplItem const& lib : impl->Libraries) { processILibs(config, this, lib, @@ -3436,23 +3437,24 @@ std::vector> cmGeneratorTarget::GetIncludeDirectories( &dagChecker, entries); if (this->Makefile->IsOn("APPLE")) { - cmLinkImplementationLibraries const* impl = - this->GetLinkImplementationLibraries(config); - for (cmLinkImplItem const& lib : impl->Libraries) { - std::string libDir = cmSystemTools::CollapseFullPath( - lib.AsStr(), this->Makefile->GetHomeOutputDirectory()); - - static cmsys::RegularExpression frameworkCheck( - "(.*\\.framework)(/Versions/[^/]+)?/[^/]+$"); - if (!frameworkCheck.find(libDir)) { - continue; - } + if (cmLinkImplementationLibraries const* impl = + this->GetLinkImplementationLibraries(config)) { + for (cmLinkImplItem const& lib : impl->Libraries) { + std::string libDir = cmSystemTools::CollapseFullPath( + lib.AsStr(), this->Makefile->GetHomeOutputDirectory()); + + static cmsys::RegularExpression frameworkCheck( + "(.*\\.framework)(/Versions/[^/]+)?/[^/]+$"); + if (!frameworkCheck.find(libDir)) { + continue; + } - libDir = frameworkCheck.match(1); + libDir = frameworkCheck.match(1); - EvaluatedTargetPropertyEntry ee(lib, cmListFileBacktrace()); - ee.Values.emplace_back(std::move(libDir)); - entries.Entries.emplace_back(std::move(ee)); + EvaluatedTargetPropertyEntry ee(lib, cmListFileBacktrace()); + ee.Values.emplace_back(std::move(libDir)); + entries.Entries.emplace_back(std::move(ee)); + } } } -- cgit v0.12 From 45158b2afef1dd3b4bd4accfcea07849921ba7df Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 22 Jul 2020 12:02:40 -0400 Subject: cmGeneratorTarget: Simplify logic in ComputeLinkInterfaceLibraries Also check the result of `GetLinkImplementationLibrariesInternal` before using it. --- Source/cmGeneratorTarget.cxx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 2284d68..30af139 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -6549,15 +6549,20 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries( iface.HadHeadSensitiveCondition, iface.HadContextSensitiveCondition, iface.HadLinkLanguageSensitiveCondition); - } else if (!cmp0022NEW) + return; + } + // If CMP0022 is NEW then the plain tll signature sets the // INTERFACE_LINK_LIBRARIES, so if we get here then the project // cleared the property explicitly and we should not fall back // to the link implementation. - { - // The link implementation is the default link interface. - cmLinkImplementationLibraries const* impl = - this->GetLinkImplementationLibrariesInternal(config, headTarget); + if (cmp0022NEW) { + return; + } + + // The link implementation is the default link interface. + if (cmLinkImplementationLibraries const* impl = + this->GetLinkImplementationLibrariesInternal(config, headTarget)) { iface.Libraries.insert(iface.Libraries.end(), impl->Libraries.begin(), impl->Libraries.end()); if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN && -- cgit v0.12 From ef796cc74322ff423da1ddef5e4dd52855dac8c7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 14 Jul 2020 15:54:01 -0400 Subject: cmGeneratorTarget: Skip computing link implementation for custom targets Targets created by `add_custom_target` cannot be used with `target_link_libraries` and so have no link implementation. --- Source/cmGeneratorTarget.cxx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 30af139..64d4ec4 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -2467,6 +2467,12 @@ private: cmGeneratorTarget::LinkClosure const* cmGeneratorTarget::GetLinkClosure( const std::string& config) const { + // There is no link implementation for targets that cannot compile sources. + if (!this->CanCompileSources()) { + static LinkClosure const empty = { {}, {} }; + return ∅ + } + std::string key(cmSystemTools::UpperCase(config)); auto i = this->LinkClosureMap.find(key); if (i == this->LinkClosureMap.end()) { @@ -2783,6 +2789,12 @@ const std::vector& cmGeneratorTarget::GetLinkImplementationClosure( const std::string& config) const { + // There is no link implementation for targets that cannot compile sources. + if (!this->CanCompileSources()) { + static std::vector const empty; + return empty; + } + LinkImplClosure& tgts = this->LinkImplClosureMap[config]; if (!tgts.Done) { tgts.Done = true; @@ -6856,8 +6868,8 @@ const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation( const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation( const std::string& config, bool secondPass) const { - // There is no link implementation for imported targets. - if (this->IsImported()) { + // There is no link implementation for targets that cannot compile sources. + if (!this->CanCompileSources()) { return nullptr; } @@ -7120,8 +7132,8 @@ cmLinkImplementationLibraries const* cmGeneratorTarget::GetLinkImplementationLibrariesInternal( const std::string& config, cmGeneratorTarget const* head) const { - // There is no link implementation for imported targets. - if (this->IsImported()) { + // There is no link implementation for targets that cannot compile sources. + if (!this->CanCompileSources()) { return nullptr; } -- cgit v0.12