Skip to content

Instantly share code, notes, and snippets.

@TrinityCoder
Last active May 8, 2019 15:14
Show Gist options
  • Save TrinityCoder/133c724f904385cac19826de65958dac to your computer and use it in GitHub Desktop.
Save TrinityCoder/133c724f904385cac19826de65958dac to your computer and use it in GitHub Desktop.
CMake module which finds libiberty (inlude dirs & library files) and makes it available to you via IMPORTED library target Libiberty::Libiberty.
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindLibiberty
-------------
Find the libiberty library.
Libiberty is a C library usually distributed with gcc, gdb and binutils.
It consists of a variety of useful functions (see official docs:
https://gcc.gnu.org/onlinedocs/libiberty/).
IMPORTED Targets
^^^^^^^^^^^^^^^^
This module defines :prop_tgt:`IMPORTED` target ``Libiberty::Libiberty``,
if libiberty has been found.
Result variables
^^^^^^^^^^^^^^^^
This module will set the following variables in your project:
``Libiberty_FOUND``
true if libiberty headers and libraries were found
``Libiberty_INCLUDE_DIRS``
the directories containing libiberty headers
``Libiberty_LIBRARIES``
libiberty libraries to be linked
Cache variables
^^^^^^^^^^^^^^^
The following cache variables may also be set:
``Libiberty_INCLUDE_DIR``
the directory containing libiberty headers
``Libiberty_LIBRARY``
path to the libiberty library
#]=======================================================================]
find_path(Libiberty_INCLUDE_DIR
NAMES libiberty.h
PATH_SUFFIXES libiberty)
find_library(Libiberty_LIBRARY
NAMES iberty libiberty)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Libiberty
FOUND_VAR
Libiberty_FOUND
REQUIRED_VARS
Libiberty_LIBRARY
Libiberty_INCLUDE_DIR)
if (Libiberty_FOUND AND NOT TARGET Libiberty::Libiberty)
set(Libiberty_LIBRARIES "${Libiberty_LIBRARY}")
set(Libiberty_INCLUDE_DIRS "${Libiberty_INCLUDE_DIR}")
add_library(Libiberty::Libiberty UNKNOWN IMPORTED)
set_target_properties(Libiberty::Libiberty
PROPERTIES
IMPORTED_LOCATION "${Libiberty_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${Libiberty_INCLUDE_DIRS}")
endif ()
mark_as_advanced(
Libiberty_INCLUDE_DIR
Libiberty_LIBRARY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment