diff --git a/Source/cmExportPackageInfoGenerator.cxx b/Source/cmExportPackageInfoGenerator.cxx index 20c1978698..1e32b32834 100644 --- a/Source/cmExportPackageInfoGenerator.cxx +++ b/Source/cmExportPackageInfoGenerator.cxx @@ -386,6 +386,28 @@ bool cmExportPackageInfoGenerator::NoteLinkedTarget( return false; } +std::vector cmExportPackageInfoGenerator::ExtractRequirements( + std::vector const& names, bool& result, + std::vector& libraryPaths) const +{ + std::vector output; + + for (auto const& name : names) { + auto const& ti = this->LinkTargets.find(name); + if (ti != this->LinkTargets.end()) { + if (ti->second.empty()) { + result = false; + } else { + output.emplace_back(ti->second); + } + } else { + libraryPaths.emplace_back(name); + } + } + + return output; +} + void cmExportPackageInfoGenerator::GenerateInterfaceLinkProperties( bool& result, Json::Value& component, cmGeneratorTarget const* target, ImportPropertyMap const& properties) const @@ -397,43 +419,26 @@ void cmExportPackageInfoGenerator::GenerateInterfaceLinkProperties( // Extract any $ from the link libraries, and assert that no // other generator expressions are present. - std::map> allowList = { - { "COMPILE_ONLY", {} }, - { "LINK_ONLY", {} }, - }; + std::map> + allowedGeneratorExpressions = { + { "COMPILE_ONLY", {} }, + { "LINK_ONLY", {} }, + }; std::string interfaceLinkLibraries; if (!cmGeneratorExpression::ForbidGeneratorExpressions( target, iter->first, iter->second, interfaceLinkLibraries, - allowList)) { + allowedGeneratorExpressions)) { result = false; return; } - std::vector buildRequires; - std::vector compileRequires; - std::vector linkRequires; std::vector linkLibraries; - - auto addLibraries = [this, &linkLibraries, - &result](std::vector const& names, - std::vector& output) -> void { - for (auto const& name : names) { - auto const& ti = this->LinkTargets.find(name); - if (ti != this->LinkTargets.end()) { - if (ti->second.empty()) { - result = false; - } else { - output.emplace_back(ti->second); - } - } else { - linkLibraries.emplace_back(name); - } - } - }; - - addLibraries(allowList["COMPILE_ONLY"], compileRequires); - addLibraries(allowList["LINK_ONLY"], linkRequires); - addLibraries(cmList{ interfaceLinkLibraries }, buildRequires); + std::vector buildRequires = this->ExtractRequirements( + cmList{ interfaceLinkLibraries }, result, linkLibraries); + std::vector compileRequires = this->ExtractRequirements( + allowedGeneratorExpressions["COMPILE_ONLY"], result, linkLibraries); + std::vector linkRequires = this->ExtractRequirements( + allowedGeneratorExpressions["LINK_ONLY"], result, linkLibraries); BuildArray(component, "requires", buildRequires); BuildArray(component, "link_requires", linkRequires); diff --git a/Source/cmExportPackageInfoGenerator.h b/Source/cmExportPackageInfoGenerator.h index c5d1f75bb6..d7eeba275d 100644 --- a/Source/cmExportPackageInfoGenerator.h +++ b/Source/cmExportPackageInfoGenerator.h @@ -94,6 +94,10 @@ private: bool CheckVersion() const; bool CheckDefaultTargets() const; + std::vector ExtractRequirements( + std::vector const& names, bool& result, + std::vector& libraryPaths) const; + void GenerateInterfaceLinkProperties( bool& result, Json::Value& component, cmGeneratorTarget const* target, ImportPropertyMap const& properties) const;