From 9113d7c2fa468a8fe7afb0c34ab4dde34a859b58 Mon Sep 17 00:00:00 2001 From: Horst Schirmeier Date: Sun, 30 Mar 2014 18:16:13 +0200 Subject: [PATCH] cmake: find libiberty headers via cmake module The libiberty headers moved from /usr/include (and a part of binutils-dev) to /usr/include/libiberty (libiberty-dev) between Ubuntu 13.10 and 14.04, which made a proper cmake search module necessary. Searching still continues working well on Debian 7. Change-Id: I324e5ccb847e4664442d6fa7d7a027705a4f0587 --- cmake/FindLibIberty.cmake | 42 ++++++++++++++++++++++++++++++++++++ doc/how-to-build.txt | 2 +- src/core/util/CMakeLists.txt | 10 +++------ 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 cmake/FindLibIberty.cmake diff --git a/cmake/FindLibIberty.cmake b/cmake/FindLibIberty.cmake new file mode 100644 index 00000000..a1ab1815 --- /dev/null +++ b/cmake/FindLibIberty.cmake @@ -0,0 +1,42 @@ +# - FindLibIberty.cmake +# This module can find libiberty on both Debian 7 and Ubuntu 14.04 +# (The libiberty headers moved from /usr/include to /usr/include/libiberty +# between Ubuntu 13.10 and 14.04, which made this search module necessary.) +# +# The following variables will be defined for your use: +# +# LibIberty_FOUND - TRUE if both library and headers were found +# LibIberty_INCLUDE_DIRS - Include directories +# LibIberty_LIBRARIES - Library path + +# set(LibIberty_PREFER_DYNAMIC True) if you want to prefer the dynamic library + +if(LibIberty_PREFER_DYNAMIC) + set(LibIberty_SEARCHORDER libiberty.so libiberty.a) +else() + set(LibIberty_SEARCHORDER libiberty.a libiberty.so) +endif() + +find_library(LibIberty_LIBRARIES NAMES ${LibIberty_SEARCHORDER}) + +find_path(LibIberty_INCLUDE_DIRS libiberty.h + PATHS + /usr/include /usr/include/libiberty + /usr/local/include /usr/local/include/libiberty + DOC "libiberty include directory containing libiberty.h") + +if(LibIberty_INCLUDE_DIRS AND LibIberty_LIBRARIES) + set(LibIberty_FOUND TRUE) +endif() + +if(LibIberty_FOUND) + if(NOT LibIberty_FIND_QUIETLY) + MESSAGE(STATUS "Found libiberty: ${LibIberty_LIBRARIES}") + endif() +else() + if(LibIberty_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find libiberty: install binutils-dev or libiberty-dev") + else() + MESSAGE(STATUS "libiberty not found") + endif() +endif() diff --git a/doc/how-to-build.txt b/doc/how-to-build.txt index dd7fa8b5..4a49a25d 100644 --- a/doc/how-to-build.txt +++ b/doc/how-to-build.txt @@ -13,7 +13,7 @@ Required for Fail*: - protobuf-compiler - cmake 2.8.2 (2.8.11 preferred) - cmake-curses-gui - - binutils-dev + - binutils-dev, on newer systems libiberty-dev - AspectC++ (ag++, ac++): AspectC++ 1.1 or newer is known to work and can be obtained from ; nightlies can be downloaded from . Make sure you use the 64-bit version if running diff --git a/src/core/util/CMakeLists.txt b/src/core/util/CMakeLists.txt index 5544a62f..bc3c3d1e 100644 --- a/src/core/util/CMakeLists.txt +++ b/src/core/util/CMakeLists.txt @@ -43,12 +43,8 @@ include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) # libiberty required by Demangler.cc: -find_library(LIB_IBERTY iberty) -mark_as_advanced(LIB_IBERTY) - -if(${LIB_IBERTY} STREQUAL LIB_IBERTY-NOTFOUND) - message(FATAL_ERROR "libiberty not found. Try installing binutils-dev: [ sudo aptitude install binutils-dev ]") -endif() +find_package(LibIberty REQUIRED) +include_directories(${LibIberty_INCLUDE_DIRS}) # libz required by gzstream find_package(ZLIB REQUIRED) @@ -74,7 +70,7 @@ mark_as_advanced(FAIL_OBJDUMP) add_library(fail-util ${SRCS}) add_dependencies(fail-util fail-comm) target_link_libraries(fail-util fail-comm) -target_link_libraries(fail-util ${PROTOBUF_LIBRARY} ${Boost_LIBRARIES} ${LIB_IBERTY} ${ZLIB_LIBRARIES} ${LIBDWARF_LIBRARIES} ${LIBELF_LIBRARIES}) +target_link_libraries(fail-util ${PROTOBUF_LIBRARY} ${Boost_LIBRARIES} ${LibIberty_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBDWARF_LIBRARIES} ${LIBELF_LIBRARIES}) option(BUILD_LLVM_DISASSEMBLER "Build the LLVM-based disassembler (LLVM 3.3 preferred, for 3.1 and 3.2 read doc/how-to-build.txt)" OFF) if (BUILD_LLVM_DISASSEMBLER)