[PATCH] D133707: Let llvm-config --system-libs print full paths if we use them

Aaron Puchert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 12 09:48:16 PDT 2022


aaronpuchert created this revision.
aaronpuchert added reviewers: beanz, mstorsjo.
Herald added subscribers: hiraditya, mgorny.
Herald added a project: All.
aaronpuchert requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

CMake's `find_package` produces full paths even if we could rely on the
linker to find the library in the standard search path. In that case
perhaps `llvm-config --system-libs` should reflect this and also use
full paths to mirror the link command that we're using.

This could be an issue for distributors, if they build with libraries in
some local path, but expect users to have them in their standard search
path.

Fixes an issue raised in D132799 <https://reviews.llvm.org/D132799>, since we're now using the same list
for linking libLLVM.

As an alternative, we could produce two different lists, one with just
stems for llvm-config and another with (possibly) full paths for
linking libLLVM.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133707

Files:
  llvm/cmake/modules/GetLibraryName.cmake
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/WindowsManifest/CMakeLists.txt


Index: llvm/lib/WindowsManifest/CMakeLists.txt
===================================================================
--- llvm/lib/WindowsManifest/CMakeLists.txt
+++ llvm/lib/WindowsManifest/CMakeLists.txt
@@ -29,6 +29,5 @@
   if(NOT libxml2_library)
     get_property(libxml2_library TARGET LibXml2::LibXml2 PROPERTY LOCATION)
   endif()
-  get_library_name(${libxml2_library} libxml2_library)
   set_property(TARGET LLVMWindowsManifest PROPERTY LLVM_SYSTEM_LIBS ${libxml2_library})
 endif()
Index: llvm/lib/Support/CMakeLists.txt
===================================================================
--- llvm/lib/Support/CMakeLists.txt
+++ llvm/lib/Support/CMakeLists.txt
@@ -301,7 +301,6 @@
   if(NOT zlib_library)
     get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION)
   endif()
-  get_library_name(${zlib_library} zlib_library)
   set(llvm_system_libs ${llvm_system_libs} "${zlib_library}")
 endif()
 
@@ -314,7 +313,6 @@
   if(NOT zstd_library)
     get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION)
   endif()
-  get_library_name(${zstd_library} zstd_library)
   set(llvm_system_libs ${llvm_system_libs} "${zstd_library}")
 endif()
 
@@ -322,7 +320,6 @@
   if(NOT terminfo_library)
     get_property(terminfo_library TARGET Terminfo::terminfo PROPERTY LOCATION)
   endif()
-  get_library_name(${terminfo_library} terminfo_library)
   set(llvm_system_libs ${llvm_system_libs} "${terminfo_library}")
 endif()
 
Index: llvm/cmake/modules/GetLibraryName.cmake
===================================================================
--- llvm/cmake/modules/GetLibraryName.cmake
+++ /dev/null
@@ -1,17 +0,0 @@
-# Returns library name for a given path.
-function(get_library_name path name)
-  get_filename_component(path ${path} NAME)
-  set(prefixes ${CMAKE_FIND_LIBRARY_PREFIXES})
-  set(suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
-  list(FILTER prefixes EXCLUDE REGEX "^\\s*$")
-  list(FILTER suffixes EXCLUDE REGEX "^\\s*$")
-  if(prefixes)
-    string(REPLACE ";" "|" prefixes "${prefixes}")
-    string(REGEX REPLACE "^(${prefixes})" "" path ${path})
-  endif()
-  if(suffixes)
-    string(REPLACE ";" "|" suffixes "${suffixes}")
-    string(REGEX REPLACE "(${suffixes})$" "" path ${path})
-  endif()
-  set(${name} "${path}" PARENT_SCOPE)
-endfunction()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133707.459494.patch
Type: text/x-patch
Size: 2281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220912/48abf9e6/attachment.bin>


More information about the llvm-commits mailing list