From cd0b71159ab51f49a8d392c0a284735ffb7601c5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Apr 2018 10:20:12 -0400 Subject: [PATCH] CMake: Make FindUnicorn introduce a unicorn target Makes the find module do all the work of properly setting up the target instead of needing to do it in the main CMakeLists file. --- CMakeLists.txt | 5 ----- CMakeModules/FindUnicorn.cmake | 20 ++++++++++++++++++++ tests/CMakeLists.txt | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b93ec885..ba8948e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,12 +126,7 @@ if (DYNARMIC_USE_LLVM) endif() if (DYNARMIC_TESTS_USE_UNICORN) - set(THREADS_PREFER_PTHREAD_FLAG ON) - find_package(Threads REQUIRED) find_package(Unicorn REQUIRED) - add_library(Unicorn INTERFACE) - target_link_libraries(Unicorn INTERFACE "${LIBUNICORN_LIBRARY}" Threads::Threads) - target_include_directories(Unicorn INTERFACE "${LIBUNICORN_INCLUDE_DIR}") endif() # Pull in externals CMakeLists for libs where available diff --git a/CMakeModules/FindUnicorn.cmake b/CMakeModules/FindUnicorn.cmake index 35590b0c..1383bacb 100644 --- a/CMakeModules/FindUnicorn.cmake +++ b/CMakeModules/FindUnicorn.cmake @@ -1,7 +1,13 @@ # Exports: +# +# Variables: # LIBUNICORN_FOUND # LIBUNICORN_INCLUDE_DIR # LIBUNICORN_LIBRARY +# +# Target: +# Unicorn::Unicorn +# find_path(LIBUNICORN_INCLUDE_DIR unicorn/unicorn.h @@ -14,4 +20,18 @@ find_library(LIBUNICORN_LIBRARY include(FindPackageHandleStandardArgs) find_package_handle_standard_args(unicorn DEFAULT_MSG LIBUNICORN_LIBRARY LIBUNICORN_INCLUDE_DIR) + +if (UNICORN_FOUND) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + unset(THREADS_PREFER_PTHREAD_FLAG) + + add_library(Unicorn::Unicorn UNKNOWN IMPORTED) + set_target_properties(Unicorn::Unicorn PROPERTIES + IMPORTED_LOCATION ${LIBUNICORN_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${LIBUNICORN_INCLUDE_DIR} + INTERFACE_LINK_LIBRARIES Threads::Threads + ) +endif() + mark_as_advanced(LIBUNICORN_INCLUDE_DIR LIBUNICORN_LIBRARY) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ca44580d..575d64a5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -41,7 +41,7 @@ if (DYNARMIC_TESTS_USE_UNICORN) A64/unicorn_emu/unicorn_load.cpp A64/verify_unicorn.cpp ) - target_link_libraries(dynarmic_tests PRIVATE Unicorn) + target_link_libraries(dynarmic_tests PRIVATE Unicorn::Unicorn) endif() include(CreateDirectoryGroups)