Skip to content

Commit

Permalink
[cmake] Explicitly link dependency libraries in the Host library
Browse files Browse the repository at this point in the history
Add explicit linkage to the necessary system libraries in the Host
library. Otherwise, the library fails to build with -Wl,--as-needed.
The system libraries ended up being listed on the linker command-line
before the static libraries needing them, resulting in --as-needed
stripping them.

Listing the dependent libraries explicitly is the canonical way of
declaring libraries in CMake. It guarantees that the system library
dependencies will be correctly propagated to reverse dependencies.

The code used to link libraries reuses existing EXTRA_LIBS variable,
copying code from other parts of LLDB. We might eventually remove
the direct use of system libraries in the programs; however, I would
prefer if we focused on fixing the build regressions in 5.0 branch
first, and went further after the release.

Differential Revision: https://reviews.llvm.org/D36885

llvm-svn: 311354
  • Loading branch information
mgorny committed Aug 21, 2017
1 parent 00393cc commit 7e1c51e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lldb/source/Host/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -156,9 +156,23 @@ if (${get_python_libdir})
endif()
endif()

set(EXTRA_LIBS)
if (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
set(EXTRA_LIBS kvm)
list(APPEND EXTRA_LIBS kvm)
endif ()
if (APPLE)
list(APPEND EXTRA_LIBS xml2)
else ()
if (LIBXML2_FOUND)
list(APPEND EXTRA_LIBS ${LIBXML2_LIBRARIES})
endif()
endif ()
if (HAVE_LIBDL)
list(APPEND EXTRA_LIBS ${CMAKE_DL_LIBS})
endif()
if (NOT LLDB_DISABLE_LIBEDIT)
list(APPEND EXTRA_LIBS edit)
endif()

add_lldb_library(lldbHost
${HOST_SOURCES}

0 comments on commit 7e1c51e

Please sign in to comment.