| 1 |
# - Find Dwarf |
| 2 |
# Find the dwarf.h header from elf utils |
| 3 |
# |
| 4 |
# DWARF_INCLUDE_DIR - where to find dwarf.h, etc. |
| 5 |
# DWARF_LIBRARIES - List of libraries when using elf utils. |
| 6 |
# DWARF_FOUND - True if fdo found. |
| 7 |
|
| 8 |
message(STATUS "Checking availability of DWARF and ELF development libraries") |
| 9 |
|
| 10 |
INCLUDE(CheckLibraryExists) |
| 11 |
|
| 12 |
if (DWARF_INCLUDE_DIR AND LIBDW_INCLUDE_DIR AND DWARF_LIBRARY AND ELF_LIBRARY) |
| 13 |
# Already in cache, be silent |
| 14 |
set(DWARF_FIND_QUIETLY TRUE) |
| 15 |
endif (DWARF_INCLUDE_DIR AND LIBDW_INCLUDE_DIR AND DWARF_LIBRARY AND ELF_LIBRARY) |
| 16 |
|
| 17 |
find_path(DWARF_INCLUDE_DIR dwarf.h |
| 18 |
/usr/include |
| 19 |
/usr/local/include |
| 20 |
/usr/include/libdwarf |
| 21 |
~/usr/local/include |
| 22 |
) |
| 23 |
|
| 24 |
find_path(LIBDW_INCLUDE_DIR elfutils/libdw.h |
| 25 |
/usr/include |
| 26 |
/usr/local/include |
| 27 |
~/usr/local/include |
| 28 |
) |
| 29 |
|
| 30 |
find_library(DWARF_LIBRARY |
| 31 |
NAMES dw dwarf |
| 32 |
PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64 ~/usr/local/lib ~/usr/local/lib64 |
| 33 |
) |
| 34 |
|
| 35 |
find_library(ELF_LIBRARY |
| 36 |
NAMES elf |
| 37 |
PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64 ~/usr/local/lib ~/usr/local/lib64 |
| 38 |
) |
| 39 |
|
| 40 |
if (DWARF_INCLUDE_DIR AND LIBDW_INCLUDE_DIR AND DWARF_LIBRARY AND ELF_LIBRARY) |
| 41 |
set(DWARF_FOUND TRUE) |
| 42 |
set(DWARF_LIBRARIES ${DWARF_LIBRARY} ${ELF_LIBRARY}) |
| 43 |
|
| 44 |
set(CMAKE_REQUIRED_LIBRARIES ${DWARF_LIBRARIES}) |
| 45 |
# check if libdw have the dwfl_module_build_id routine, i.e. if it supports the buildid |
| 46 |
# mechanism to match binaries to detached debug info sections (the -debuginfo packages |
| 47 |
# in distributions such as fedora). We do it against libelf because, IIRC, some distros |
| 48 |
# include libdw linked statically into libelf. |
| 49 |
check_library_exists(elf dwfl_module_build_id "" HAVE_DWFL_MODULE_BUILD_ID) |
| 50 |
else (DWARF_INCLUDE_DIR AND LIBDW_INCLUDE_DIR AND DWARF_LIBRARY AND ELF_LIBRARY) |
| 51 |
set(DWARF_FOUND FALSE) |
| 52 |
set(DWARF_LIBRARIES) |
| 53 |
endif (DWARF_INCLUDE_DIR AND LIBDW_INCLUDE_DIR AND DWARF_LIBRARY AND ELF_LIBRARY) |
| 54 |
|
| 55 |
if (DWARF_FOUND) |
| 56 |
if (NOT DWARF_FIND_QUIETLY) |
| 57 |
message(STATUS "Found dwarf.h header: ${DWARF_INCLUDE_DIR}") |
| 58 |
message(STATUS "Found elfutils/libdw.h header: ${LIBDW_INCLUDE_DIR}") |
| 59 |
message(STATUS "Found libdw library: ${DWARF_LIBRARY}") |
| 60 |
message(STATUS "Found libelf library: ${ELF_LIBRARY}") |
| 61 |
endif (NOT DWARF_FIND_QUIETLY) |
| 62 |
else (DWARF_FOUND) |
| 63 |
if (DWARF_FIND_REQUIRED) |
| 64 |
# Check if we are in a Red Hat (RHEL) or Fedora system to tell |
| 65 |
# exactly which packages should be installed. Please send |
| 66 |
# patches for other distributions. |
| 67 |
find_path(FEDORA fedora-release /etc) |
| 68 |
find_path(REDHAT redhat-release /etc) |
| 69 |
if (FEDORA OR REDHAT) |
| 70 |
if (NOT DWARF_INCLUDE_DIR OR NOT LIBDW_INCLUDE_DIR) |
| 71 |
message(STATUS "Please install the elfutils-devel package") |
| 72 |
endif (NOT DWARF_INCLUDE_DIR OR NOT LIBDW_INCLUDE_DIR) |
| 73 |
if (NOT DWARF_LIBRARY) |
| 74 |
message(STATUS "Please install the elfutils-libs package") |
| 75 |
endif (NOT DWARF_LIBRARY) |
| 76 |
if (NOT ELF_LIBRARY) |
| 77 |
message(STATUS "Please install the elfutils-libelf package") |
| 78 |
endif (NOT ELF_LIBRARY) |
| 79 |
else (FEDORA OR REDHAT) |
| 80 |
if (NOT DWARF_INCLUDE_DIR) |
| 81 |
message(STATUS "Could NOT find dwarf include dir") |
| 82 |
endif (NOT DWARF_INCLUDE_DIR) |
| 83 |
if (NOT LIBDW_INCLUDE_DIR) |
| 84 |
message(STATUS "Could NOT find libdw include dir") |
| 85 |
endif (NOT LIBDW_INCLUDE_DIR) |
| 86 |
if (NOT DWARF_LIBRARY) |
| 87 |
message(STATUS "Could NOT find libdw library") |
| 88 |
endif (NOT DWARF_LIBRARY) |
| 89 |
if (NOT ELF_LIBRARY) |
| 90 |
message(STATUS "Could NOT find libelf library") |
| 91 |
endif (NOT ELF_LIBRARY) |
| 92 |
endif (FEDORA OR REDHAT) |
| 93 |
message(FATAL_ERROR "Could NOT find some ELF and DWARF libraries, please install the missing packages") |
| 94 |
endif (DWARF_FIND_REQUIRED) |
| 95 |
endif (DWARF_FOUND) |
| 96 |
|
| 97 |
mark_as_advanced(DWARF_INCLUDE_DIR LIBDW_INCLUDE_DIR DWARF_LIBRARY ELF_LIBRARY) |
| 98 |
include_directories(${DWARF_INCLUDE_DIR} ${LIBDW_INCLUDE_DIR}) |
| 99 |
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h) |
| 100 |
|
| 101 |
message(STATUS "Checking availability of DWARF and ELF development libraries - done") |