From b4f1a77a14d57e4b9cd82cad3bb054fdc3d51d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Fri, 5 May 2017 13:09:38 +0200 Subject: [PATCH] CMake: Move finding radare2 using pkg-config to FindRadare2.cmake --- src/CMakeLists.txt | 13 +---- src/cmake/FindRadare2.cmake | 108 +++++++++++++++++++++--------------- 2 files changed, 66 insertions(+), 55 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 34706be9..18d05f43 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,19 +26,12 @@ if(WIN32) endif() set(RADARE2_INCLUDE_DIRS "${IAITO_WIN32_DIR}/radare2/include/libr" "${IAITO_WIN32_DIR}/include") - - find_package(Radare2 REQUIRED) -else() - # support sys/user.sh install - list(APPEND CMAKE_PREFIX_PATH "$ENV{HOME}/bin/prefix/radare2") - - find_package(PkgConfig REQUIRED) - pkg_search_module(RADARE2 REQUIRED r_core) - - link_directories(${RADARE2_LIBRARY_DIRS}) endif() + +find_package(Radare2 REQUIRED) include_directories(${RADARE2_INCLUDE_DIRS}) +link_directories(${RADARE2_LIBRARY_DIRS}) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" diff --git a/src/cmake/FindRadare2.cmake b/src/cmake/FindRadare2.cmake index 612aa104..db9a0789 100644 --- a/src/cmake/FindRadare2.cmake +++ b/src/cmake/FindRadare2.cmake @@ -1,57 +1,75 @@ # - Find Radare2 (libr) # # RADARE2_FOUND - True if libr has been found. -# RADARE2_INCLUDE_DIRS - libr Include Directory +# RADARE2_INCLUDE_DIRS - libr include directory # RADARE2_LIBRARIES - List of libraries when using libr. +# RADARE2_LIBRARY_DIRS - libr library directories +# +# If libr was found using find_library and not pkg-config, the following variables will also be set: # RADARE2_LIBRARY_ - Path to library r_ -find_path(RADARE2_INCLUDE_DIRS - NAMES r_core.h r_bin.h r_util.h - HINTS - "$ENV{HOME}/bin/prefix/radare2/include/libr" - /usr/local/include/libr - /usr/include/libr) - -set(RADARE2_LIBRARY_NAMES - core - config - cons - io - util - flag - asm - debug - hash - bin - lang - io - anal - parse - bp - egg - reg - search - syscall - socket - fs - magic - crypto) - -set(RADARE2_LIBRARIES "") -set(RADARE2_LIBRARIES_VARS "") -foreach(libname ${RADARE2_LIBRARY_NAMES}) - find_library(RADARE2_LIBRARY_${libname} - r_${libname} +if(WIN32) + find_path(RADARE2_INCLUDE_DIRS + NAMES r_core.h r_bin.h r_util.h HINTS - "$ENV{HOME}/bin/prefix/radare2/lib" - /usr/local/lib - /usr/lib) + "$ENV{HOME}/bin/prefix/radare2/include/libr" + /usr/local/include/libr + /usr/include/libr) - list(APPEND RADARE2_LIBRARIES ${RADARE2_LIBRARY_${libname}}) - list(APPEND RADARE2_LIBRARIES_VARS "RADARE2_LIBRARY_${libname}") -endforeach() + set(RADARE2_LIBRARY_NAMES + core + config + cons + io + util + flag + asm + debug + hash + bin + lang + io + anal + parse + bp + egg + reg + search + syscall + socket + fs + magic + crypto) + + set(RADARE2_LIBRARIES "") + set(RADARE2_LIBRARIES_VARS "") + foreach(libname ${RADARE2_LIBRARY_NAMES}) + find_library(RADARE2_LIBRARY_${libname} + r_${libname} + HINTS + "$ENV{HOME}/bin/prefix/radare2/lib" + /usr/local/lib + /usr/lib) + + list(APPEND RADARE2_LIBRARIES ${RADARE2_LIBRARY_${libname}}) + list(APPEND RADARE2_LIBRARIES_VARS "RADARE2_LIBRARY_${libname}") + endforeach() + + set(RADARE2_LIBRARY_DIRS "") +else() + # support sys/user.sh install + set(RADARE2_CMAKE_PREFIX_PATH_TEMP ${CMAKE_PREFIX_PATH}) + list(APPEND CMAKE_PREFIX_PATH "$ENV{HOME}/bin/prefix/radare2") + + find_package(PkgConfig REQUIRED) + pkg_search_module(RADARE2 REQUIRED r_core) + + # reset CMAKE_PREFIX_PATH + set(CMAKE_PREFIX_PATH ${RADARE2_CMAKE_PREFIX_PATH_TEMP}) + mark_as_advanced(RADARE2_CMAKE_PREFIX_PATH_TEMP) +endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(RADARE2 REQUIRED_VARS ${RADARE2_LIBRARIES_VARS} RADARE2_INCLUDE_DIRS) +find_package_handle_standard_args(RADARE2 REQUIRED_VARS RADARE2_LIBRARIES RADARE2_INCLUDE_DIRS) mark_as_advanced(RADARE2_LIBRARIES_VARS)