1# - Try to find libelf 2# Once done this will define 3# 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 8# 9# Copyright (c) 2008 Bernhard Walle <bernhard.walle@gmx.de> 10# 11# Redistribution and use is allowed according to the terms of the New 12# BSD license. 13# For details see the accompanying COPYING-CMAKE-SCRIPTS file. 14# 15 16 17if (LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS) 18 set (LibElf_FIND_QUIETLY TRUE) 19endif (LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS) 20 21find_path (LIBELF_INCLUDE_DIRS 22 NAMES 23 libelf.h 24 PATHS 25 /usr/include 26 /usr/include/libelf 27 /usr/local/include 28 /usr/local/include/libelf 29 /opt/local/include 30 /opt/local/include/libelf 31 /sw/include 32 /sw/include/libelf 33 ENV CPATH) 34 35find_library (LIBELF_LIBRARIES 36 NAMES 37 elf 38 PATHS 39 /usr/lib 40 /usr/local/lib 41 /opt/local/lib 42 /sw/lib 43 ENV LIBRARY_PATH 44 ENV LD_LIBRARY_PATH) 45 46include (FindPackageHandleStandardArgs) 47 48 49# handle the QUIETLY and REQUIRED arguments and set LIBELF_FOUND to TRUE if all listed variables are TRUE 50FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibElf DEFAULT_MSG 51 LIBELF_LIBRARIES 52 LIBELF_INCLUDE_DIRS) 53 54SET(CMAKE_REQUIRED_LIBRARIES elf) 55INCLUDE(CheckCXXSourceCompiles) 56CHECK_CXX_SOURCE_COMPILES("#include <libelf.h> 57int main() { 58 Elf *e = (Elf*)0; 59 size_t sz; 60 elf_getshdrstrndx(e, &sz); 61 return 0; 62}" ELF_GETSHDRSTRNDX) 63 64mark_as_advanced(LIBELF_INCLUDE_DIRS LIBELF_LIBRARIES ELF_GETSHDRSTRNDX) 65