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