From d04d150799fd059d27b9eebebe3727bcd068252b Mon Sep 17 00:00:00 2001 From: Clayton Wheeler Date: Fri, 17 Dec 2021 11:45:00 -0600 Subject: [PATCH] Find dependencies for statically-linked libdw, try to use pkg-config BackwardConfig.cmake was not explicitly pulling in the dependencies (libelf, libz, etc.) of libdw, which made it fail to link when libdw was built as a static library (and therefore didn't explicitly encode those dependencies). This changes it to first try using pkg-config to find libdw and its dependencies, and then fall back to looking up the individual libraries it might depend on. --- BackwardConfig.cmake | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/BackwardConfig.cmake b/BackwardConfig.cmake index c95c0d5..56d1fd0 100644 --- a/BackwardConfig.cmake +++ b/BackwardConfig.cmake @@ -53,6 +53,10 @@ endif() # CONFIGS ############################################################################### include(FindPackageHandleStandardArgs) +if(NOT PKG_CONFIG_FOUND) + include(CMakeFindDependencyMacro) + find_dependency(PkgConfig) +endif() if (STACK_WALKING_LIBUNWIND) # libunwind works on the macOS without having to add special include @@ -87,12 +91,30 @@ if (${STACK_DETAILS_AUTO_DETECT}) set(_name_mismatched_arg NAME_MISMATCHED) endif() # find libdw - find_path(LIBDW_INCLUDE_DIR NAMES "elfutils/libdw.h" "elfutils/libdwfl.h") - find_library(LIBDW_LIBRARY dw) - set(LIBDW_INCLUDE_DIRS ${LIBDW_INCLUDE_DIR} ) - set(LIBDW_LIBRARIES ${LIBDW_LIBRARY} ) - find_package_handle_standard_args(libdw ${_name_mismatched_arg} - REQUIRED_VARS LIBDW_LIBRARY LIBDW_INCLUDE_DIR) + # start by trying pkg-config + pkg_search_module(LIBDW libdw) + if(NOT LIBDW_FOUND) + find_path(LIBDW_INCLUDE_DIR NAMES "elfutils/libdw.h" "elfutils/libdwfl.h") + find_library(LIBDW_LIBRARY dw) + # if it's statically linked, look for all the possible dependencies + find_library(LIBELF_LIBRARY elf) + find_library(LIBZ_LIBRARY z) + find_library(LIBBZ2_LIBRARY bz2) + find_library(LIBLZMA_LIBRARY lzma) + find_library(LIBZSTD_LIBRARY zstd) + set(LIBDW_INCLUDE_DIRS ${LIBDW_INCLUDE_DIR} ) + set(LIBDW_LIBRARIES ${LIBDW_LIBRARY} + $<$:${LIBELF_LIBRARY}> + $<$:${LIBZ_LIBRARY}> + $<$:${LIBBZ2_LIBRARY}> + $<$:${LIBLZMA_LIBRARY}> + $<$:${LIBZSTD_LIBRARY}>) + find_package_handle_standard_args(libdw ${_name_mismatched_arg} + REQUIRED_VARS LIBDW_LIBRARY LIBDW_INCLUDE_DIR) + endif() + # libdw doesn't declare its pthread dependency + find_library(LIBPTHREAD_LIBRARY pthread) + set(LIBDW_LIBRARIES ${LIBDW_LIBRARIES} ${LIBPTHREAD_LIBRARY}) mark_as_advanced(LIBDW_INCLUDE_DIR LIBDW_LIBRARY) # find libbfd