[PATCH] D74176: [CMake] Link against ZLIB::ZLIB

Thomas Preud'homme via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 15:31:12 PST 2020


Hi Petr,

I've noticed that ZLIB::ZLIB ends up in the INTERFACE_LINK_LIBRARIES target property for LLVMSupport in LLVMExports.cmake in the install tree. This means that an external project doing find_package(LLVM) and linking against LLVMSupport will get a dependency against ZLIB::ZLIB target which is not defined in that external dependency and thus result in a failure:

  Target "Foo" links to target "ZLIB::ZLIB" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

I would expect that INTERFACE_LINK_LIBRARIES in an export file to only list libraries and no imported target since it's meant for external consumption. Does that make sense? If yes, do you have an idea of what could cause this?

Best regards,

Thomas

________________________________
From: llvm-commits <llvm-commits-bounces at lists.llvm.org> on behalf of Petr Hosek via Phabricator via llvm-commits <llvm-commits at lists.llvm.org>
Sent: 29 February 2020 19:10
To: phosek at google.com <phosek at google.com>; compnerd at compnerd.org <compnerd at compnerd.org>; smeenai at fb.com <smeenai at fb.com>
Cc: llvm-commits at lists.llvm.org <llvm-commits at lists.llvm.org>; zturner at roblox.com <zturner at roblox.com>; hiraditya at msn.com <hiraditya at msn.com>
Subject: [PATCH] D74176: [CMake] Link against ZLIB::ZLIB

     [This message was sent from somebody outside of your organisation]



This revision was automatically updated to reflect the committed changes.
phosek marked an inline comment as done.
Closed by commit rG2181bf40d871: [CMake] Link against ZLIB::ZLIB (authored by phosek).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74176/new/

https://reviews.llvm.org/D74176

Files:
  llvm/lib/Support/CMakeLists.txt


Index: llvm/lib/Support/CMakeLists.txt
===================================================================
--- llvm/lib/Support/CMakeLists.txt
+++ llvm/lib/Support/CMakeLists.txt
@@ -1,5 +1,5 @@
 if(LLVM_ENABLE_ZLIB)
-  set(system_libs ${ZLIB_LIBRARY})
+  set(imported_libs ZLIB::ZLIB)
 endif()

 if( MSVC OR MINGW )
@@ -186,10 +186,29 @@
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/ADT
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support
   ${Backtrace_INCLUDE_DIRS}
-  LINK_LIBS ${system_libs} ${delayload_flags} ${Z3_LINK_FILES}
+  LINK_LIBS ${system_libs} ${imported_libs} ${delayload_flags} ${Z3_LINK_FILES}
   )

-set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${system_libs}")
+set(llvm_system_libs ${system_libs})
+
+if(LLVM_ENABLE_ZLIB)
+  string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
+  get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION_${build_type})
+  if(NOT zlib_library)
+    get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION)
+  endif()
+  get_filename_component(zlib_library ${zlib_library} NAME)
+  if(zlib_library MATCHES "^${CMAKE_STATIC_LIBRARY_PREFIX}.*${CMAKE_STATIC_LIBRARY_SUFFIX}$")
+    STRING(REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX}" "" zlib_library ${zlib_library})
+    STRING(REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX}$" "" zlib_library ${zlib_library})
+  elseif(zlib_library MATCHES "^${CMAKE_SHARED_LIBRARY_PREFIX}.*${CMAKE_SHARED_LIBRARY_SUFFIX}$")
+    STRING(REGEX REPLACE "^${CMAKE_SHARED_LIBRARY_PREFIX}" "" zlib_library ${zlib_library})
+    STRING(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_SUFFIX}$" "" zlib_library ${zlib_library})
+  endif()
+  set(llvm_system_libs ${llvm_system_libs} "${zlib_library}")
+endif()
+
+set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}")

 if(LLVM_WITH_Z3)
   target_include_directories(LLVMSupport SYSTEM


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200303/50c5895c/attachment-0001.html>


More information about the llvm-commits mailing list