Make zigzag encoding of externIds optional
[hiphop-php.git] / CMake / FindLibElf.cmake
blobba27592d76202babb3d17a4484467b2951f7c2b2
1 # - Try to find libelf
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
12 #  BSD license.
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
25   NAMES
26     libelf.h
27   PATHS
28     ${PkgConfig_LibElf_INCLUDE_DIRS}
29     /usr/include
30     /usr/include/libelf
31     /usr/local/include
32     /usr/local/include/libelf
33     /opt/local/include
34     /opt/local/include/libelf
35     /sw/include
36     /sw/include/libelf
37     ENV CPATH)
39 find_library (LIBELF_LIBRARIES
40   NAMES
41     elf
42   PATHS
43     /usr/lib
44     /usr/local/lib
45     /opt/local/lib
46     /sw/lib
47     ${PkgConfig_LibElf_LIBRARY_DIRS}
48     ENV LIBRARY_PATH
49     ENV LD_LIBRARY_PATH)
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
56   LIBELF_LIBRARIES
57   LIBELF_INCLUDE_DIRS)
59 SET(CMAKE_REQUIRED_LIBRARIES elf)
60 INCLUDE(CheckCXXSourceCompiles)
61 CHECK_CXX_SOURCE_COMPILES("#include <libelf.h>
62 int main() {
63   Elf *e = (Elf*)0;
64   size_t sz;
65   elf_getshdrstrndx(e, &sz);
66   return 0;
67 }" ELF_GETSHDRSTRNDX)
68 SET(CMAKE_REQUIRED_LIBRARIES)
70 mark_as_advanced(LIBELF_INCLUDE_DIRS LIBELF_LIBRARIES ELF_GETSHDRSTRNDX)