From aea1b03617bed037bbd12af36d7ef92feff0ba74 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 15 Jan 2016 10:02:52 -0500 Subject: [PATCH] Fix export of STATIC library PRIVATE dependencies with CMP0022 NEW MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The target_link_libraries command records the PRIVATE dependencies of a STATIC library in INTERFACE_LINK_LIBRARIES as "$". This hides the target name from export namespacing logic inside a generator expression. When user-written generator expressions reference a target name they must put it inside a "$" expression to allow the export logic to rename the target. In the case that the private dependency is not already a generator expression, target_link_libraries must use "$>" to allow the export logic to rename the target. Reported-by: Tamás Kenéz --- Source/cmTargetLinkLibrariesCommand.cxx | 7 +++++-- Tests/ExportImport/Export/CMakeLists.txt | 6 ++++++ Tests/ExportImport/Export/testLibDepends.c | 7 ++++++- Tests/ExportImport/Export/testStaticLibRequiredPrivate.c | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 Tests/ExportImport/Export/testStaticLibRequiredPrivate.c diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index 435346a30..5f3246ace 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -432,8 +432,11 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, { std::string configLib = this->Target ->GetDebugGeneratorExpressions(lib, llt); - if (cmGeneratorExpression::IsValidTargetName(lib) - || cmGeneratorExpression::Find(lib) != std::string::npos) + if (cmGeneratorExpression::IsValidTargetName(configLib)) + { + configLib = "$>"; + } + else if (cmGeneratorExpression::Find(configLib) != std::string::npos) { configLib = "$"; } diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index 9c50d6cc6..c2ecb0b1c 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -136,6 +136,8 @@ cmake_policy(SET CMP0022 NEW) add_library(testLibRequired testLibRequired.c) add_library(testLibDepends testLibDepends.c) target_link_libraries(testLibDepends LINK_PUBLIC testLibRequired) +add_library(testStaticLibRequiredPrivate testStaticLibRequiredPrivate.c) +target_link_libraries(testLibDepends PRIVATE testStaticLibRequiredPrivate) cmake_policy(POP) macro(add_include_lib _libName) @@ -394,6 +396,10 @@ install(TARGETS INCLUDES DESTINATION $/include/$ ) +install(TARGETS + testStaticLibRequiredPrivate + EXPORT RequiredExp DESTINATION lib +) install(EXPORT RequiredExp NAMESPACE Req:: FILE testLibRequiredTargets.cmake DESTINATION lib/cmake/testLibRequired) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/installIncludesTest") diff --git a/Tests/ExportImport/Export/testLibDepends.c b/Tests/ExportImport/Export/testLibDepends.c index fb5a002e0..3c7774eed 100644 --- a/Tests/ExportImport/Export/testLibDepends.c +++ b/Tests/ExportImport/Export/testLibDepends.c @@ -16,5 +16,10 @@ #endif extern int testLibRequired(void); +extern int testStaticLibRequiredPrivate(void); -int testLibDepends(void) { return testLibRequired(); } +int testLibDepends(void) { + return testLibRequired() + + testStaticLibRequiredPrivate() + ; +} diff --git a/Tests/ExportImport/Export/testStaticLibRequiredPrivate.c b/Tests/ExportImport/Export/testStaticLibRequiredPrivate.c new file mode 100644 index 000000000..28a2675ff --- /dev/null +++ b/Tests/ExportImport/Export/testStaticLibRequiredPrivate.c @@ -0,0 +1 @@ +int testStaticLibRequiredPrivate(void) { return 0; }