CMake initial WIP commit
[dyninst.git] / cmake / Modules / FindLibDwarf.cmake
1 # - Try to find libdwarf
2 # Once done this will define
3 #
4 #  LIBDWARF_FOUND - system has libdwarf
5 #  LIBDWARF_INCLUDE_DIRS - the libdwarf include directory
6 #  LIBDWARF_LIBRARIES - Link these to use libdwarf
7 #  LIBDWARF_DEFINITIONS - Compiler switches required for using libdwarf
8 #
9
10 # Locate libelf library at first
11 if (NOT LIBELF_FOUND)
12    find_package (LibElf REQUIRED)
13 endif (NOT LIBELF_FOUND)
14
15 if (LIBDWARF_LIBRARIES AND LIBDWARF_INCLUDE_DIRS)
16   set (LibDwarf_FIND_QUIETLY TRUE)
17 endif (LIBDWARF_LIBRARIES AND LIBDWARF_INCLUDE_DIRS)
18
19 find_path (DWARF_INCLUDE_DIR
20     NAMES
21       dwarf.h
22     PATHS
23       /usr/include
24       /usr/include/libdwarf
25       /usr/local/include
26       /opt/local/include
27       /sw/include
28       ENV CPATH) # PATH and INCLUDE will also work
29
30 if (DWARF_INCLUDE_DIR)
31     set (LIBDWARF_INCLUDE_DIRS  ${DWARF_INCLUDE_DIR})
32 endif ()
33
34 find_library (LIBDWARF_LIBRARIES
35     NAMES
36       dwarf
37     PATHS
38       /usr/lib
39       /usr/local/lib
40       /opt/local/lib
41       /sw/lib
42       ENV LIBRARY_PATH   # PATH and LIB will also work
43       ENV LD_LIBRARY_PATH)
44 include (FindPackageHandleStandardArgs)
45
46
47 # handle the QUIETLY and REQUIRED arguments and set LIBDWARF_FOUND to TRUE
48 # if all listed variables are TRUE
49 FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibDwarf DEFAULT_MSG
50     LIBDWARF_LIBRARIES
51     LIBDWARF_INCLUDE_DIRS)
52
53 mark_as_advanced(LIBDW_INCLUDE_DIR DWARF_INCLUDE_DIR)
54 mark_as_advanced(LIBDWARF_INCLUDE_DIRS LIBDWARF_LIBRARIES)