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.
This commit is contained in:
Lioncash 2018-04-18 10:20:12 -04:00 committed by MerryMage
parent 181c3b0790
commit cd0b71159a
3 changed files with 21 additions and 6 deletions

View file

@ -126,12 +126,7 @@ if (DYNARMIC_USE_LLVM)
endif() endif()
if (DYNARMIC_TESTS_USE_UNICORN) if (DYNARMIC_TESTS_USE_UNICORN)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(Unicorn 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() endif()
# Pull in externals CMakeLists for libs where available # Pull in externals CMakeLists for libs where available

View file

@ -1,7 +1,13 @@
# Exports: # Exports:
#
# Variables:
# LIBUNICORN_FOUND # LIBUNICORN_FOUND
# LIBUNICORN_INCLUDE_DIR # LIBUNICORN_INCLUDE_DIR
# LIBUNICORN_LIBRARY # LIBUNICORN_LIBRARY
#
# Target:
# Unicorn::Unicorn
#
find_path(LIBUNICORN_INCLUDE_DIR find_path(LIBUNICORN_INCLUDE_DIR
unicorn/unicorn.h unicorn/unicorn.h
@ -14,4 +20,18 @@ find_library(LIBUNICORN_LIBRARY
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(unicorn DEFAULT_MSG LIBUNICORN_LIBRARY LIBUNICORN_INCLUDE_DIR) 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) mark_as_advanced(LIBUNICORN_INCLUDE_DIR LIBUNICORN_LIBRARY)

View file

@ -41,7 +41,7 @@ if (DYNARMIC_TESTS_USE_UNICORN)
A64/unicorn_emu/unicorn_load.cpp A64/unicorn_emu/unicorn_load.cpp
A64/verify_unicorn.cpp A64/verify_unicorn.cpp
) )
target_link_libraries(dynarmic_tests PRIVATE Unicorn) target_link_libraries(dynarmic_tests PRIVATE Unicorn::Unicorn)
endif() endif()
include(CreateDirectoryGroups) include(CreateDirectoryGroups)