Skip to content
Snippets Groups Projects
Commit aea1b036 authored by Brad King's avatar Brad King
Browse files

Fix export of STATIC library PRIVATE dependencies with CMP0022 NEW


The target_link_libraries command records the PRIVATE dependencies of a
STATIC library in INTERFACE_LINK_LIBRARIES as "$<LINK_ONLY:dep>".  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 "$<TARGET_NAME:dep>" 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 "$<LINK_ONLY:$<TARGET_NAME:dep>>" to allow the export logic to
rename the target.

Reported-by: default avatarTamás Kenéz <tamas.kenez@gmail.com>
parent e5cbec14
Branches
Tags
No related merge requests found
......@@ -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 = "$<LINK_ONLY:$<TARGET_NAME:" + configLib + ">>";
}
else if (cmGeneratorExpression::Find(configLib) != std::string::npos)
{
configLib = "$<LINK_ONLY:" + configLib + ">";
}
......
......@@ -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
$<INSTALL_PREFIX>/include/$<TARGET_PROPERTY:NAME>
)
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")
......
......@@ -16,5 +16,10 @@
#endif
extern int testLibRequired(void);
extern int testStaticLibRequiredPrivate(void);
int testLibDepends(void) { return testLibRequired(); }
int testLibDepends(void) {
return testLibRequired()
+ testStaticLibRequiredPrivate()
;
}
int testStaticLibRequiredPrivate(void) { return 0; }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment