-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Libiberty cmake modernization (#1334)
* LibIberty cmake modernization * Use INCLUDE_DIRS directly
- Loading branch information
Showing
5 changed files
with
66 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,64 @@ | ||
#======================================================================================== | ||
# FindLibIberty.cmake | ||
# | ||
# Find LibIberty include dirs and libraries | ||
# | ||
# ---------------------------------------- | ||
# | ||
# Use this module by invoking find_package with the form:: | ||
# | ||
# find_package(LibIberty | ||
# [REQUIRED] # Fail with error if LibIberty is not found | ||
# ) | ||
# | ||
# This module reads hints about search locations from variables:: | ||
# | ||
# LibIberty_ROOT_DIR - Base directory the of LibIberty installation | ||
# LibIberty_LIBRARYDIR - Hint directory that contains the LibIberty library files | ||
# IBERTY_LIBRARIES - Alias for LibIberty_LIBRARIES (backwards compatibility only) | ||
# LibIberty_INCLUDEDIR - Hint directory that contains the libiberty headers files | ||
# | ||
# and saves search results persistently in CMake cache entries:: | ||
# | ||
# LibIberty_FOUND - True if headers and requested libraries were found | ||
# IBERTY_FOUND - Alias for LibIberty_FOUND (backwards compatibility only) | ||
# LibIberty_INCLUDE_DIRS - libiberty include directories | ||
# LibIberty_LIBRARY_DIRS - Link directories for LibIberty libraries | ||
# LibIberty_LIBRARIES - LibIberty library files | ||
# IBERTY_LIBRARIES - Alias for LibIberty_LIBRARIES (backwards compatibility only) | ||
# | ||
#======================================================================================== | ||
#[=======================================================================[.rst: | ||
FindLibIberty | ||
------------- | ||
|
||
if(LibIberty_FOUND) | ||
return() | ||
endif() | ||
Find libiberty, a collection of subroutines used by various GNU programs. | ||
|
||
# Keep the semantics of IBERTY_LIBRARIES for backward compatibility NB: If both are | ||
# specified, LibIberty_LIBRARIES is ignored | ||
if(NOT "${IBERTY_LIBRARIES}" STREQUAL "") | ||
set(LibIberty_LIBRARIES ${IBERTY_LIBRARIES}) | ||
endif() | ||
Imported targets | ||
^^^^^^^^^^^^^^^^ | ||
|
||
This module defines the following :prop_tgt:`IMPORTED` target: | ||
|
||
``LibIberty::LibIberty`` | ||
The libiberty library, if found. | ||
|
||
include(DyninstSystemPaths) | ||
Result variables | ||
^^^^^^^^^^^^^^^^ | ||
|
||
# Non-standard subdirectories to search | ||
set(_path_suffixes libiberty iberty) | ||
This module will set the following variables in your project: | ||
|
||
``LibIberty_INCLUDE_DIRS`` | ||
where to find libiberty.h, etc. | ||
``LibIberty_LIBRARIES`` | ||
the libraries to link against to use libiberty. | ||
``LibIberty_FOUND`` | ||
If false, do not try to use libiberty. | ||
|
||
LibIberty does not have its own version number or release schedule. | ||
See https://gcc.gnu.org/onlinedocs/libiberty/Using.html#Using for details. | ||
|
||
#]=======================================================================] | ||
cmake_policy(SET CMP0074 NEW) # Use <Package>_ROOT | ||
|
||
find_path( | ||
LibIberty_INCLUDE_DIRS | ||
LibIberty_INCLUDE_DIR | ||
NAMES libiberty.h | ||
HINTS ${LibIberty_ROOT_DIR} ${LibIberty_ROOT_DIR}/include ${LibIberty_INCLUDEDIR} | ||
PATHS ${DYNINST_SYSTEM_INCLUDE_PATHS} | ||
PATH_SUFFIXES ${_path_suffixes} | ||
DOC "LibIberty include directories") | ||
PATH_SUFFIXES libiberty) | ||
mark_as_advanced(LibIberty_INCLUDE_DIR) | ||
|
||
# iberty_pic is for Debian <= wheezy | ||
find_library( | ||
LibIberty_LIBRARIES | ||
NAMES iberty_pic iberty | ||
HINTS ${LibIberty_ROOT_DIR} ${LibIberty_LIBRARYDIR} ${IBERTY_LIBRARIES} | ||
PATHS ${DYNINST_SYSTEM_LIBRARY_PATHS} | ||
PATH_SUFFIXES ${_path_suffixes}) | ||
LibIberty_LIBRARY | ||
NAMES libiberty iberty | ||
PATH_SUFFIXES libiberty) | ||
mark_as_advanced(LibIberty_LIBRARY) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args( | ||
LibIberty | ||
FOUND_VAR LibIberty_FOUND | ||
REQUIRED_VARS LibIberty_LIBRARIES) | ||
|
||
# For backwards compatibility only | ||
set(IBERTY_FOUND ${LibIberty_FOUND}) | ||
REQUIRED_VARS LibIberty_LIBRARY LibIberty_INCLUDE_DIR) | ||
|
||
if(LibIberty_FOUND) | ||
foreach(l ${LibIberty_LIBRARIES}) | ||
get_filename_component(_dir ${l} DIRECTORY) | ||
list(APPEND LibIberty_LIBRARY_DIRS ${_dir}) | ||
endforeach() | ||
set(LibIberty_INCLUDE_DIRS ${LibIberty_INCLUDE_DIR}) | ||
set(LibIberty_LIBRARIES ${LibIberty_LIBRARY}) | ||
|
||
if(NOT TARGET LibIberty::LibIberty) | ||
add_library(LibIberty::LibIberty UNKNOWN IMPORTED) | ||
set_target_properties(LibIberty::LibIberty PROPERTIES INTERFACE_INCLUDE_DIRECTORIES | ||
"${LibIberty_INCLUDE_DIRS}") | ||
|
||
# For backwards compatibility only | ||
set(IBERTY_LIBRARIES ${LibIberty_LIBRARIES}) | ||
set_target_properties( | ||
LibIberty::LibIberty PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" | ||
IMPORTED_LOCATION "${LibIberty_LIBRARIES}") | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,33 @@ | ||
#====================================================================================== | ||
# LibIberty.cmake | ||
#================================================================ | ||
# | ||
# Configure LibIberty for Dyninst | ||
# Configure libiberty | ||
# | ||
# ---------------------------------------- | ||
# | ||
# Directly exports the following CMake variables | ||
# LibIberty_ROOT_DIR - Directory hint for libiberty installation | ||
# | ||
# LibIberty_ROOT_DIR - Computed base directory the of LibIberty installation | ||
# LibIberty_LIBRARY_DIRS - Link directories for LibIberty libraries | ||
# LibIberty_LIBRARIES - LibIberty library files | ||
# LibIberty_INCLUDE - LibIberty include files | ||
# | ||
# NOTE: | ||
# The exported LibIberty_ROOT_DIR can be different from the value provided by the user | ||
# in the case that it is determined to build LibIberty from source. In such a case, | ||
# LibIberty_ROOT_DIR will contain the directory of the from-source installation. | ||
# | ||
# See Modules/FindLibIberty.cmake for details | ||
# | ||
#====================================================================================== | ||
#================================================================ | ||
|
||
if(LibIberty_FOUND) | ||
return() | ||
endif() | ||
include_guard(GLOBAL) | ||
|
||
# libiberty is only available on Unixes; provide a dummy target on other platforms | ||
if(NOT UNIX) | ||
if(NOT TARGET Dyninst::LibIberty) | ||
add_library(Dyninst::LibIberty INTERFACE) | ||
endif() | ||
return() | ||
endif() | ||
|
||
# -------------- PATHS -------------------------------------------------------- | ||
|
||
# Base directory the of LibIberty installation | ||
set(LibIberty_ROOT_DIR | ||
"/usr" | ||
CACHE PATH "Base directory the of LibIberty installation") | ||
|
||
# Hint directory that contains the LibIberty library files | ||
set(LibIberty_LIBRARYDIR | ||
"${LibIberty_ROOT_DIR}/lib" | ||
CACHE PATH "Hint directory that contains the LibIberty library files") | ||
|
||
# -------------- PACKAGES ----------------------------------------------------- | ||
mark_as_advanced(LibIberty_ROOT_DIR) | ||
|
||
find_package(LibIberty REQUIRED) | ||
|
||
# -------------- EXPORT VARIABLES --------------------------------------------- | ||
|
||
add_library(LibIberty STATIC IMPORTED GLOBAL) | ||
set_target_properties(LibIberty PROPERTIES IMPORTED_LOCATION ${LibIberty_LIBRARIES}) | ||
set_target_properties(LibIberty PROPERTIES INTERFACE_INCLUDE_DIRECTORIES | ||
${LibIberty_INCLUDE_DIRS}) | ||
|
||
set(LibIberty_ROOT_DIR | ||
${LibIberty_ROOT_DIR} | ||
CACHE PATH "Base directory the of LibIberty installation" FORCE) | ||
set(LibIberty_INCLUDE_DIRS | ||
${LibIberty_INCLUDE_DIRS} | ||
CACHE PATH "LibIberty include directories" FORCE) | ||
set(LibIberty_LIBRARY_DIRS | ||
${LibIberty_LIBRARY_DIRS} | ||
CACHE PATH "LibIberty library directory" FORCE) | ||
set(LibIberty_LIBRARIES | ||
${LibIberty_LIBRARIES} | ||
CACHE FILEPATH "LibIberty library files" FORCE) | ||
|
||
# For backward compatibility only | ||
set(IBERTY_LIBRARIES ${LibIberty_LIBRARIES}) | ||
|
||
message(STATUS "LibIberty include dirs: ${LibIberty_INCLUDE_DIRS}") | ||
message(STATUS "LibIberty library dirs: ${LibIberty_LIBRARY_DIRS}") | ||
message(STATUS "LibIberty libraries: ${LibIberty_LIBRARIES}") | ||
if(NOT TARGET Dyninst::LibIberty) | ||
add_library(Dyninst::LibIberty INTERFACE IMPORTED) | ||
target_include_directories(Dyninst::LibIberty SYSTEM INTERFACE ${LibIberty_INCLUDE_DIRS}) | ||
target_link_libraries(Dyninst::LibIberty INTERFACE LibIberty::LibIberty) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters