From 6e637b1102ff68a65a18d313e30d3a95032f5f93 Mon Sep 17 00:00:00 2001 From: Martin Duffy Date: Fri, 17 Oct 2025 10:46:45 -0400 Subject: [PATCH] install(PACKAGE_INFO): Fix error when usage requirements contain certain genex Since commit 13c7bb5b0c (cmGeneratorExpression: Update strip function to collect parsed expressions, 2025-04-08, v4.1.0-rc1~361^2~1), the logic to strip generator expressions would error if the stripped expressions were being collected and an expression without a `:` was found inside an expression with a `:`. This resulted in an error when exporting a target that contained such a generator expression in its link libraries or compile definitions. Address the error by checking whether the latest `$<` proceeded the latest `:`. --- Source/cmGeneratorExpression.cxx | 13 +++++++------ .../LinkInterfaceGeneratorExpression.cmake | 2 +- Tests/RunCMake/string/GenexpStrip.cmake | 4 ++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 031935a950..dd4c8867c4 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -191,16 +191,17 @@ static std::string extractAllGeneratorExpressions( colons.push(c); } } else if (c[0] == '>') { - if (collected && !starts.empty() && !colons.empty()) { - (*collected)[std::string(starts.top() + 2, colons.top())].push_back( - std::string(colons.top() + 1, c)); + if (!colons.empty() && !starts.empty() && + starts.top() < colons.top()) { + if (collected) { + (*collected)[std::string(starts.top() + 2, colons.top())] + .push_back(std::string(colons.top() + 1, c)); + } + colons.pop(); } if (!starts.empty()) { starts.pop(); } - if (!colons.empty()) { - colons.pop(); - } if (starts.empty()) { break; } diff --git a/Tests/RunCMake/ExportPackageInfo/LinkInterfaceGeneratorExpression.cmake b/Tests/RunCMake/ExportPackageInfo/LinkInterfaceGeneratorExpression.cmake index 654f15b382..77442eff88 100644 --- a/Tests/RunCMake/ExportPackageInfo/LinkInterfaceGeneratorExpression.cmake +++ b/Tests/RunCMake/ExportPackageInfo/LinkInterfaceGeneratorExpression.cmake @@ -2,7 +2,7 @@ project(LinkInterfaceGeneratorExpression CXX) add_library(foo foo.cxx) add_library(bar foo.cxx) -target_link_libraries(bar $<1:foo>) +target_link_libraries(bar $<1:foo> $<1:$>) install(TARGETS foo EXPORT foo) export(EXPORT foo PACKAGE_INFO foo) diff --git a/Tests/RunCMake/string/GenexpStrip.cmake b/Tests/RunCMake/string/GenexpStrip.cmake index 9de498cf11..632663fa1e 100644 --- a/Tests/RunCMake/string/GenexpStrip.cmake +++ b/Tests/RunCMake/string/GenexpStrip.cmake @@ -35,3 +35,7 @@ test_strip( # Multiple case "1$2$:$>,TRUE,FALSE>3" "123" ) +test_strip( # No : inside of : + "$<1:$>1" + "1" +)