From 94648953befa6464e46469b1fa8d46b68d486321 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 2 Aug 2019 14:42:14 -0400 Subject: cmLinkItem: Simplify tracking of whether link interface is explicit We now only need a boolean. --- Source/cmGeneratorTarget.cxx | 4 ++-- Source/cmLinkItem.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 7340bc2..42683db 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5219,7 +5219,7 @@ void cmGeneratorTarget::ComputeLinkInterface( const std::string& config, cmOptionalLinkInterface& iface, cmGeneratorTarget const* headTarget) const { - if (iface.ExplicitLibraries) { + if (iface.Explicit) { if (this->GetType() == cmStateEnums::SHARED_LIBRARY || this->GetType() == cmStateEnums::STATIC_LIBRARY || this->GetType() == cmStateEnums::INTERFACE_LIBRARY) { @@ -5659,7 +5659,7 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries( return; } iface.Exists = true; - iface.ExplicitLibraries = explicitLibraries; + iface.Explicit = explicitLibraries != nullptr; if (explicitLibraries) { // The interface libraries have been explicitly set. diff --git a/Source/cmLinkItem.h b/Source/cmLinkItem.h index 6450c62..d71ff49 100644 --- a/Source/cmLinkItem.h +++ b/Source/cmLinkItem.h @@ -87,7 +87,7 @@ struct cmOptionalLinkInterface : public cmLinkInterface bool LibrariesDone = false; bool AllDone = false; bool Exists = false; - const char* ExplicitLibraries = nullptr; + bool Explicit = false; }; struct cmHeadToLinkInterfaceMap -- cgit v0.12 From 4b2e1fc9eeeb0b0b686b2e38a2a29e49eedb45e5 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 2 Aug 2019 14:47:33 -0400 Subject: cmGeneratorTarget: Use local var to de-duplicate CMP0022 checks --- Source/cmGeneratorTarget.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 42683db..747051d 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5603,8 +5603,9 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries( // libraries and executables that export symbols. const char* explicitLibraries = nullptr; std::string linkIfaceProp; - if (this->GetPolicyStatusCMP0022() != cmPolicies::OLD && - this->GetPolicyStatusCMP0022() != cmPolicies::WARN) { + bool const cmp0022NEW = (this->GetPolicyStatusCMP0022() != cmPolicies::OLD && + this->GetPolicyStatusCMP0022() != cmPolicies::WARN); + if (cmp0022NEW) { // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES. linkIfaceProp = "INTERFACE_LINK_LIBRARIES"; explicitLibraries = this->GetProperty(linkIfaceProp); @@ -5666,8 +5667,7 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries( this->ExpandLinkItems(linkIfaceProp, explicitLibraries, config, headTarget, usage_requirements_only, iface.Libraries, iface.HadHeadSensitiveCondition); - } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN || - this->GetPolicyStatusCMP0022() == cmPolicies::OLD) + } else if (!cmp0022NEW) // If CMP0022 is NEW then the plain tll signature sets the // INTERFACE_LINK_LIBRARIES, so if we get here then the project // cleared the property explicitly and we should not fall back -- cgit v0.12 From d75cad01f0a43c55f999768fb63287fc247f9685 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 2 Aug 2019 14:50:43 -0400 Subject: Fix rpath-link for shared lib with only private deps Under CMP0022 NEW behavior, the link interface is explicit even if there are no public dependencies (`INTERFACE_LINK_LIBRARIES` is not set). Mark it as such to activate our tracking of private runtime dependencies of shared libraries for generation of `-rpath-link` flags. Fixes: #19556 --- Source/cmGeneratorTarget.cxx | 2 +- Tests/RuntimePath/CMakeLists.txt | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 747051d..d9e5e71 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5660,7 +5660,7 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries( return; } iface.Exists = true; - iface.Explicit = explicitLibraries != nullptr; + iface.Explicit = cmp0022NEW || explicitLibraries != nullptr; if (explicitLibraries) { // The interface libraries have been explicitly set. diff --git a/Tests/RuntimePath/CMakeLists.txt b/Tests/RuntimePath/CMakeLists.txt index 6583a87..bb87440 100644 --- a/Tests/RuntimePath/CMakeLists.txt +++ b/Tests/RuntimePath/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 2.6) +cmake_minimum_required (VERSION 3.15) project(RuntimePath C) # Add a simple chain of shared libraries that must be found. @@ -31,3 +31,14 @@ if(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG) set_property(TARGET bar2 PROPERTY LIBRARY_OUTPUT_DIRECTORY A) target_link_libraries(bar2 foo2) endif() + +# Add a library that is missing the rpath for its dependency. +add_library(bar1_no_rpath SHARED bar1.c) +set_property(TARGET bar1_no_rpath PROPERTY LIBRARY_OUTPUT_DIRECTORY B) +set_property(TARGET bar1_no_rpath PROPERTY SKIP_BUILD_RPATH 1) +target_link_libraries(bar1_no_rpath PRIVATE foo1) + +# Add an executable linking to the library with a missing dependency rpath. +# CMake should generate the proper rpath-link flag to find it at build time. +add_executable(main_with_bar1_no_rpath main.c) +target_link_libraries(main_with_bar1_no_rpath bar1_no_rpath) -- cgit v0.12