xref: /aosp_15_r20/external/bcc/cmake/FindLibElf.cmake (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1*387f9dfdSAndroid Build Coastguard Worker# - Try to find libelf
2*387f9dfdSAndroid Build Coastguard Worker# Once done this will define
3*387f9dfdSAndroid Build Coastguard Worker#
4*387f9dfdSAndroid Build Coastguard Worker#  LIBELF_FOUND - system has libelf
5*387f9dfdSAndroid Build Coastguard Worker#  LIBELF_INCLUDE_DIRS - the libelf include directory
6*387f9dfdSAndroid Build Coastguard Worker#  LIBELF_LIBRARIES - Link these to use libelf
7*387f9dfdSAndroid Build Coastguard Worker#  LIBELF_DEFINITIONS - Compiler switches required for using libelf
8*387f9dfdSAndroid Build Coastguard Worker#
9*387f9dfdSAndroid Build Coastguard Worker#  Copyright (c) 2008 Bernhard Walle <[email protected]>
10*387f9dfdSAndroid Build Coastguard Worker#
11*387f9dfdSAndroid Build Coastguard Worker#  Redistribution and use is allowed according to the terms of the New
12*387f9dfdSAndroid Build Coastguard Worker#  BSD license.
13*387f9dfdSAndroid Build Coastguard Worker#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
14*387f9dfdSAndroid Build Coastguard Worker#
15*387f9dfdSAndroid Build Coastguard Worker
16*387f9dfdSAndroid Build Coastguard Worker
17*387f9dfdSAndroid Build Coastguard Workerif (LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS)
18*387f9dfdSAndroid Build Coastguard Worker  set (LibElf_FIND_QUIETLY TRUE)
19*387f9dfdSAndroid Build Coastguard Workerendif (LIBELF_LIBRARIES AND LIBELF_INCLUDE_DIRS)
20*387f9dfdSAndroid Build Coastguard Worker
21*387f9dfdSAndroid Build Coastguard Workerfind_path (LIBELF_INCLUDE_DIRS
22*387f9dfdSAndroid Build Coastguard Worker  NAMES
23*387f9dfdSAndroid Build Coastguard Worker    libelf.h
24*387f9dfdSAndroid Build Coastguard Worker  PATHS
25*387f9dfdSAndroid Build Coastguard Worker    /usr/include
26*387f9dfdSAndroid Build Coastguard Worker    /usr/include/libelf
27*387f9dfdSAndroid Build Coastguard Worker    /usr/local/include
28*387f9dfdSAndroid Build Coastguard Worker    /usr/local/include/libelf
29*387f9dfdSAndroid Build Coastguard Worker    /opt/local/include
30*387f9dfdSAndroid Build Coastguard Worker    /opt/local/include/libelf
31*387f9dfdSAndroid Build Coastguard Worker    /sw/include
32*387f9dfdSAndroid Build Coastguard Worker    /sw/include/libelf
33*387f9dfdSAndroid Build Coastguard Worker    ENV CPATH)
34*387f9dfdSAndroid Build Coastguard Worker
35*387f9dfdSAndroid Build Coastguard Workerfind_library (LIBELF_LIBRARIES
36*387f9dfdSAndroid Build Coastguard Worker  NAMES
37*387f9dfdSAndroid Build Coastguard Worker    elf
38*387f9dfdSAndroid Build Coastguard Worker  PATHS
39*387f9dfdSAndroid Build Coastguard Worker    /usr/lib
40*387f9dfdSAndroid Build Coastguard Worker    /usr/local/lib
41*387f9dfdSAndroid Build Coastguard Worker    /opt/local/lib
42*387f9dfdSAndroid Build Coastguard Worker    /sw/lib
43*387f9dfdSAndroid Build Coastguard Worker    ENV LIBRARY_PATH
44*387f9dfdSAndroid Build Coastguard Worker    ENV LD_LIBRARY_PATH)
45*387f9dfdSAndroid Build Coastguard Worker
46*387f9dfdSAndroid Build Coastguard Workerinclude (FindPackageHandleStandardArgs)
47*387f9dfdSAndroid Build Coastguard Worker
48*387f9dfdSAndroid Build Coastguard Worker
49*387f9dfdSAndroid Build Coastguard Worker# handle the QUIETLY and REQUIRED arguments and set LIBELF_FOUND to TRUE if all listed variables are TRUE
50*387f9dfdSAndroid Build Coastguard WorkerFIND_PACKAGE_HANDLE_STANDARD_ARGS(LibElf DEFAULT_MSG
51*387f9dfdSAndroid Build Coastguard Worker  LIBELF_LIBRARIES
52*387f9dfdSAndroid Build Coastguard Worker  LIBELF_INCLUDE_DIRS)
53*387f9dfdSAndroid Build Coastguard Worker
54*387f9dfdSAndroid Build Coastguard WorkerSET(CMAKE_REQUIRED_LIBRARIES elf)
55*387f9dfdSAndroid Build Coastguard WorkerINCLUDE(CheckCXXSourceCompiles)
56*387f9dfdSAndroid Build Coastguard WorkerCHECK_CXX_SOURCE_COMPILES("#include <libelf.h>
57*387f9dfdSAndroid Build Coastguard Workerint main() {
58*387f9dfdSAndroid Build Coastguard Worker  Elf *e = (Elf*)0;
59*387f9dfdSAndroid Build Coastguard Worker  size_t sz;
60*387f9dfdSAndroid Build Coastguard Worker  elf_getshdrstrndx(e, &sz);
61*387f9dfdSAndroid Build Coastguard Worker  return 0;
62*387f9dfdSAndroid Build Coastguard Worker}" ELF_GETSHDRSTRNDX)
63*387f9dfdSAndroid Build Coastguard Worker
64*387f9dfdSAndroid Build Coastguard Workermark_as_advanced(LIBELF_INCLUDE_DIRS LIBELF_LIBRARIES ELF_GETSHDRSTRNDX)
65