From 6572640089ba6bc81003fd2d4f924ee62a545ce1 Mon Sep 17 00:00:00 2001 From: Peter Matula Date: Thu, 8 Dec 2022 09:51:53 +0100 Subject: [PATCH] deps/capstone: add RETDEC_USE_SYSTEM_CAPSTONE option --- cmake/options.cmake | 1 + deps/capstone/CMakeLists.txt | 45 +++++++++++++++++++ .../retdec-system-capstone-config.cmake | 4 ++ 3 files changed, 50 insertions(+) create mode 100644 deps/capstone/retdec-system-capstone-config.cmake diff --git a/cmake/options.cmake b/cmake/options.cmake index fe5a6cf4a..bb3d4fc17 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -6,6 +6,7 @@ option(RETDEC_TESTS "Build tests." OFF) option(RETDEC_DEV_TOOLS "Build dev tools." OFF) option(RETDEC_COMPILE_YARA "Compile YARA rules at installation." ON) option(RETDEC_MSVC_STATIC_RUNTIME "Use a multi-threaded statically-linked runtime library." OFF) +option(RETDEC_USE_SYSTEM_CAPSTONE "Use Capstone installed in the system." OFF) # Component options. # diff --git a/deps/capstone/CMakeLists.txt b/deps/capstone/CMakeLists.txt index d19c45966..8823dc360 100644 --- a/deps/capstone/CMakeLists.txt +++ b/deps/capstone/CMakeLists.txt @@ -1,4 +1,49 @@ +if(RETDEC_USE_SYSTEM_CAPSTONE) + message(STATUS "Capstone: using system Capstone.") + + include(FindPkgConfig) + pkg_check_modules(CAPSTONE REQUIRED capstone>=5.0) + + add_library(capstone INTERFACE) + add_library(retdec::deps::capstone ALIAS capstone) + + target_include_directories(capstone + SYSTEM INTERFACE + $ + $ + ) + + target_link_libraries(capstone INTERFACE + $ + $ + ) + + # Install targets. + install(TARGETS capstone + EXPORT capstone-targets + ) + + # Export targets. + install(EXPORT capstone-targets + FILE "retdec-capstone-targets.cmake" + NAMESPACE retdec::deps:: + DESTINATION ${RETDEC_INSTALL_CMAKE_DIR} + ) + + # Install CMake files. + install( + FILES + "${CMAKE_CURRENT_LIST_DIR}/retdec-system-capstone-config.cmake" + DESTINATION + "${RETDEC_INSTALL_CMAKE_DIR}" + RENAME + "retdec-capstone-config.cmake" + ) + + return() +endif() + set(CAPSTONE_INSTALL_DIR ${CMAKE_BINARY_DIR}/deps/install/capstone) set(CAPSTONE_LIB_NAME ${CMAKE_STATIC_LIBRARY_PREFIX}capstone${CMAKE_STATIC_LIBRARY_SUFFIX}) diff --git a/deps/capstone/retdec-system-capstone-config.cmake b/deps/capstone/retdec-system-capstone-config.cmake new file mode 100644 index 000000000..f2de7fd5f --- /dev/null +++ b/deps/capstone/retdec-system-capstone-config.cmake @@ -0,0 +1,4 @@ + +if(NOT TARGET retdec::deps::capstone) + include(${CMAKE_CURRENT_LIST_DIR}/retdec-capstone-targets.cmake) +endif()