[CMake] Fix OCaml build failure because of absolute path in system libs

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 adds
the full library path to imported_libs, and adds a stripped down version
without directories, lib prefix and lib suffix to system_libs

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
D85820 and D79219.

Patch By: haampie

Differential Revision: https://reviews.llvm.org/D86134
This commit is contained in:
Petr Hosek 2020-08-19 10:33:03 -07:00
parent 495f91fd33
commit 8e4acb82f7
1 changed files with 16 additions and 12 deletions

View File

@ -2,6 +2,15 @@ if(LLVM_ENABLE_ZLIB)
set(imported_libs ZLIB::ZLIB)
endif()
function(get_system_libname libpath libname)
get_filename_component(libpath ${libpath} NAME)
string(REPLACE ";" "|" PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
string(REPLACE ";" "|" SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
STRING(REGEX REPLACE "^(${PREFIXES})" "" libpath ${libpath})
STRING(REGEX REPLACE "(${SUFFIXES})$" "" libpath ${libpath})
set(${libname} "${libpath}" 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 +31,7 @@ elseif( CMAKE_HOST_UNIX )
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 +215,15 @@ if(LLVM_ENABLE_ZLIB)
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_LIB} terminfo_library)
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)