[PATCH] D86134: Fix OCaml build failure because of absolute path in system libs

Harmen Stoppels via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 04:37:54 PDT 2020


haampie created this revision.
haampie added reviewers: JDevlieghere, phosek, smeenai.
Herald added subscribers: llvm-commits, hiraditya, mgorny.
Herald added a project: LLVM.
haampie requested review of this revision.

https://reviews.llvm.org/D85820 introduced a full path in the `LLVM_SYSTEM_LIBS` property of the `LLVMSupport` target, which made the OCaml bindings fail to build, since they use `-l [system_lib]` flags for every lib in `LLVM_SYSTEM_LIBS`, which cannot work with absolute paths.

This patch solves the issue in a similar vain as ZLIB does it: it strips the directories, lib prefix and lib suffix from the the library path.

In the future we should probably make some changes to LLVM_SYSTEM_LIBS, since both zlib and ncurses do not necessarily have to be system libs anymore due to the find_package / find_library bits introduced in https://reviews.llvm.org/D85820 and https://reviews.llvm.org/D79219.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86134

Files:
  llvm/lib/Support/CMakeLists.txt


Index: llvm/lib/Support/CMakeLists.txt
===================================================================
--- llvm/lib/Support/CMakeLists.txt
+++ llvm/lib/Support/CMakeLists.txt
@@ -2,6 +2,22 @@
   set(imported_libs ZLIB::ZLIB)
 endif()
 
+function(get_system_libname OUTPUT LIBNAME)
+  get_filename_component(LIBNAME ${LIBNAME} NAME)
+  if(CMAKE_STATIC_LIBRARY_PREFIX AND CMAKE_STATIC_LIBRARY_SUFFIX AND
+      LIBNAME MATCHES "^${CMAKE_STATIC_LIBRARY_PREFIX}.*${CMAKE_STATIC_LIBRARY_SUFFIX}$")
+    STRING(REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX}" "" LIBNAME ${LIBNAME})
+    STRING(REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX}$" "" LIBNAME ${LIBNAME})
+  endif()
+  if(CMAKE_SHARED_LIBRARY_PREFIX AND CMAKE_SHARED_LIBRARY_SUFFIX AND
+      LIBNAME MATCHES "^${CMAKE_SHARED_LIBRARY_PREFIX}.*${CMAKE_SHARED_LIBRARY_SUFFIX}$")
+    STRING(REGEX REPLACE "^${CMAKE_SHARED_LIBRARY_PREFIX}" "" LIBNAME ${LIBNAME})
+    STRING(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_SUFFIX}$" "" LIBNAME ${LIBNAME})
+  endif()
+
+  set(${OUTPUT} "${LIBNAME}" PARENT_SCOPE)
+endfunction()
+
 if( MSVC OR MINGW )
   # libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
   # advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc.
@@ -22,7 +38,7 @@
     set(system_libs ${system_libs} ${Backtrace_LIBFILE})
   endif()
   if( LLVM_ENABLE_TERMINFO )
-    set(system_libs ${system_libs} ${TERMINFO_LIB})
+    set(imported_libs ${imported_libs} "${TERMINFO_LIB}")
   endif()
   if( LLVM_ENABLE_THREADS AND (HAVE_LIBATOMIC OR HAVE_CXX_LIBATOMICS64) )
     set(system_libs ${system_libs} atomic)
@@ -206,20 +222,15 @@
   if(NOT zlib_library)
     get_property(zlib_library TARGET ZLIB::ZLIB PROPERTY LOCATION)
   endif()
-  get_filename_component(zlib_library ${zlib_library} NAME)
-  if(CMAKE_STATIC_LIBRARY_PREFIX AND CMAKE_STATIC_LIBRARY_SUFFIX AND
-      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})
-  endif()
-  if(CMAKE_SHARED_LIBRARY_PREFIX AND CMAKE_SHARED_LIBRARY_SUFFIX AND
-      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()
+  get_system_libname(zlib_library ${zlib_library})
   set(llvm_system_libs ${llvm_system_libs} "${zlib_library}")
 endif()
 
+if(LLVM_ENABLE_TERMINFO)
+  get_system_libname(terminfo_library ${TERMINFO_LIB})
+  set(llvm_system_libs ${llvm_system_libs} "${terminfo_library}")
+endif()
+
 set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}")
 
 if(LLVM_WITH_Z3)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86134.286247.patch
Type: text/x-patch
Size: 2918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200818/e46a2586/attachment.bin>


More information about the llvm-commits mailing list