Skip to content

Commit

Permalink
deps/capstone: add RETDEC_USE_SYSTEM_CAPSTONE option
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMatula committed Dec 8, 2022
1 parent e571dc8 commit 6572640
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
45 changes: 45 additions & 0 deletions deps/capstone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${CAPSTONE_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:${CAPSTONE_INCLUDE_DIRS}>
)

target_link_libraries(capstone INTERFACE
$<BUILD_INTERFACE:${CAPSTONE_LINK_LIBRARIES}>
$<INSTALL_INTERFACE:${CAPSTONE_LINK_LIBRARIES}>
)

# 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})
Expand Down
4 changes: 4 additions & 0 deletions deps/capstone/retdec-system-capstone-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

if(NOT TARGET retdec::deps::capstone)
include(${CMAKE_CURRENT_LIST_DIR}/retdec-capstone-targets.cmake)
endif()

0 comments on commit 6572640

Please sign in to comment.