From 56e1688517ab040cf9554926070830df475980b3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 14 Feb 2018 11:09:55 -0500 Subject: Android.mk: Evaluate generator expressions up front When exporting `INTERFACE_LINK_LIBRARIES`, we must evaluate generator expressions first, before expanding the `;` list, in case they contain or generate semicolons. --- Source/cmExportBuildAndroidMKGenerator.cxx | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Source/cmExportBuildAndroidMKGenerator.cxx b/Source/cmExportBuildAndroidMKGenerator.cxx index 6f31a2d..5bfae1e 100644 --- a/Source/cmExportBuildAndroidMKGenerator.cxx +++ b/Source/cmExportBuildAndroidMKGenerator.cxx @@ -101,12 +101,19 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties( os << "LOCAL_CPP_FEATURES += "; os << (property.second) << "\n"; } else if (property.first == "INTERFACE_LINK_LIBRARIES") { + // evaluate any generator expressions with the current + // build type of the makefile + cmGeneratorExpression ge; + std::unique_ptr cge = + ge.Parse(property.second); + std::string evaluated = + cge->Evaluate(target->GetLocalGenerator(), config); // need to look at list in pi->second and see if static or shared // FindTargetToLink // target->GetLocalGenerator()->FindGeneratorTargetToUse() // then add to LOCAL_CPPFLAGS std::vector libraries; - cmSystemTools::ExpandListArgument(property.second, libraries); + cmSystemTools::ExpandListArgument(evaluated, libraries); std::string staticLibs; std::string sharedLibs; std::string ldlibs; @@ -122,12 +129,6 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties( staticLibs += " " + lib; } } else { - // evaluate any generator expressions with the current - // build type of the makefile - cmGeneratorExpression ge; - std::unique_ptr cge = ge.Parse(lib); - std::string evaluated = - cge->Evaluate(target->GetLocalGenerator(), config); bool relpath = false; if (type == cmExportBuildAndroidMKGenerator::INSTALL) { relpath = lib.substr(0, 3) == "../"; @@ -135,12 +136,12 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties( // check for full path or if it already has a -l, or // in the case of an install check for relative paths // if it is full or a link library then use string directly - if (cmSystemTools::FileIsFullPath(evaluated) || - evaluated.substr(0, 2) == "-l" || relpath) { - ldlibs += " " + evaluated; + if (cmSystemTools::FileIsFullPath(lib) || + lib.substr(0, 2) == "-l" || relpath) { + ldlibs += " " + lib; // if it is not a path and does not have a -l then add -l - } else if (!evaluated.empty()) { - ldlibs += " -l" + evaluated; + } else if (!lib.empty()) { + ldlibs += " -l" + lib; } } } -- cgit v0.12 From b6d68766b1a8537a3a130a38aa91936e579da6fd Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 14 Feb 2018 11:15:48 -0500 Subject: Android.mk: Fix export of static libraries with PRIVATE dependencies The `LINK_ONLY` generator expression is used to represent private dependencies of static libraries in their `INTERFACE_LINK_LIBRARIES` property value. Fix evaluation of generator expressions during export to support the `LINK_ONLY` genex. Extend the RunCMake.AndroidMK test with a case for this. --- Source/cmExportBuildAndroidMKGenerator.cxx | 7 +++++-- Tests/RunCMake/AndroidMK/AndroidMK.cmake | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/cmExportBuildAndroidMKGenerator.cxx b/Source/cmExportBuildAndroidMKGenerator.cxx index 5bfae1e..817b5d9 100644 --- a/Source/cmExportBuildAndroidMKGenerator.cxx +++ b/Source/cmExportBuildAndroidMKGenerator.cxx @@ -8,6 +8,7 @@ #include #include "cmGeneratorExpression.h" +#include "cmGeneratorExpressionDAGChecker.h" #include "cmGeneratorTarget.h" #include "cmLinkItem.h" #include "cmLocalGenerator.h" @@ -104,10 +105,12 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties( // evaluate any generator expressions with the current // build type of the makefile cmGeneratorExpression ge; + cmGeneratorExpressionDAGChecker dagChecker( + target->GetName(), "INTERFACE_LINK_LIBRARIES", nullptr, nullptr); std::unique_ptr cge = ge.Parse(property.second); - std::string evaluated = - cge->Evaluate(target->GetLocalGenerator(), config); + std::string evaluated = cge->Evaluate( + target->GetLocalGenerator(), config, false, target, &dagChecker); // need to look at list in pi->second and see if static or shared // FindTargetToLink // target->GetLocalGenerator()->FindGeneratorTargetToUse() diff --git a/Tests/RunCMake/AndroidMK/AndroidMK.cmake b/Tests/RunCMake/AndroidMK/AndroidMK.cmake index 2596e8c..3fbb2cf 100644 --- a/Tests/RunCMake/AndroidMK/AndroidMK.cmake +++ b/Tests/RunCMake/AndroidMK/AndroidMK.cmake @@ -4,7 +4,7 @@ add_library(foo foo.cxx) add_library(car foo.cxx) add_library(bar bar.c) add_library(dog foo.cxx) -target_link_libraries(foo car bar dog debug -lm) +target_link_libraries(foo PRIVATE car bar dog debug -lm) export(TARGETS bar dog car foo ANDROID_MK ${build_BINARY_DIR}/Android.mk) install(TARGETS bar dog car foo DESTINATION lib EXPORT myexp) -- cgit v0.12