2 # Once done this will define
4 # LIBELF_FOUND - system has libelf
5 # LIBELF_INCLUDE_DIRS - the libelf include directory
6 # LIBELF_LIBRARIES - Link these to use libelf
7 # LIBELF_DEFINITIONS - Compiler switches required for using libelf
9 # Copyright (c) 2008 Bernhard Walle <bernhard.walle@gmx.de>
11 # Redistribution and use is allowed according to the terms of the New
13 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
17 if (LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS)
18 set (LibElf_FIND_QUIETLY TRUE)
19 endif (LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS)
21 find_package(PkgConfig)
22 pkg_check_modules(PkgConfig_LibElf QUIET libelf)
24 find_path (LIBELF_INCLUDE_DIRS
28 ${PkgConfig_LibElf_INCLUDE_DIRS}
32 /usr/local/include/libelf
34 /opt/local/include/libelf
39 find_library (LIBELF_LIBRARIES
47 ${PkgConfig_LibElf_LIBRARY_DIRS}
51 include (FindPackageHandleStandardArgs)
54 # handle the QUIETLY and REQUIRED arguments and set LIBELF_FOUND to TRUE if all listed variables are TRUE
55 FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibElf DEFAULT_MSG
59 SET(CMAKE_REQUIRED_LIBRARIES elf)
60 INCLUDE(CheckCXXSourceCompiles)
61 CHECK_CXX_SOURCE_COMPILES("#include <libelf.h>
65 elf_getshdrstrndx(e, &sz);
68 SET(CMAKE_REQUIRED_LIBRARIES)
70 mark_as_advanced(LIBELF_INCLUDE_DIRS LIBELF_LIBRARIES ELF_GETSHDRSTRNDX)