파일
rocm-systems/cmake/Modules/Findlibelf.cmake
T
lancesix 066e659d6e rocprofiler-sdk-codeobj: use pkg-config to find libdw / libelf (#749)
* rocprofiler-sdk-codeobj: use pkg-config to find libdw / libelf

The current version of source/lib/rocprofiler-sdk-codeobj/CMakeLists.txt
adds -ldw and -lelf to target_link_libraries. However, on a system where
libdw-dev / libelf-dev is missing, the cmake configuration phase will
run properly and a compile time error will eventually be raised.

This patch changes the CMakelists.txt to search for libelf libdw and
configures the target as needed.  Systems missing the required support
should report an error when running cmake instead of in the middle of
the compilation.

* Use INTERFACE targets

* Resolve issues with Findlib{dw,elf}

---------

Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
2024-04-12 03:48:35 -05:00

81 라인
2.1 KiB
CMake

# Try to find libelf headers and libraries.
#
# Usage of this module as follows:
#
# find_package(libelf)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# libelf_ROOT Set this variable to the root installation of
# libelf if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# libelf_FOUND System has libelf libraries and headers
# libelf_LIBRARIES The libelf library
# libelf_INCLUDE_DIRS The location of libelf headers
#
# Interface targets defined by this module:
#
# libelf::libelf
#
find_package(PkgConfig)
if(PkgConfig_FOUND)
pkg_check_modules(ELF libelf)
if(ELF_FOUND)
set(libelf_INCLUDE_DIR
"${ELF_INCLUDE_DIRS}"
CACHE FILEPATH "libelf include directory")
set(libelf_LIBRARY
"${ELF_LIBRARIES}"
CACHE FILEPATH "libelf libraries")
endif()
endif()
if(NOT PkgConfig_FOUND OR NOT ELF_FOUND)
find_path(
libelf_ROOT_DIR
NAMES include/gelf.h include/elf.h
HINTS ${libelf_ROOT}
PATHS ${libelf_ROOT})
mark_as_advanced(libelf_ROOT_DIR)
find_path(
libelf_INCLUDE_DIR
NAMES gelf.h elf.h
HINTS ${libelf_ROOT}
PATHS ${libelf_ROOT}
PATH_SUFFIXES include)
find_library(
libelf_LIBRARY
NAMES elf
HINTS ${libelf_ROOT}
PATHS ${libelf_ROOT}
PATH_SUFFIXES lib lib64)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(libelf DEFAULT_MSG libelf_LIBRARY libelf_INCLUDE_DIR)
if(libelf_FOUND)
if(NOT TARGET libelf::libelf)
add_library(libelf::libelf INTERFACE IMPORTED)
endif()
if(TARGET PkgConfig::ELF AND ELF_FOUND)
target_link_libraries(libelf::libelf INTERFACE PkgConfig::ELF)
else()
target_link_libraries(libelf::libelf INTERFACE ${libelf_LIBRARY})
target_include_directories(libelf::libelf SYSTEM INTERFACE ${libelf_INCLUDE_DIR})
endif()
endif()
mark_as_advanced(libelf_INCLUDE_DIR libelf_LIBRARY)