build(cmake): add install target

This makes dynarmic installable, and also adds a CMake package config
file, that allows projects to use `find_package(dynarmic)` to import the
library.

I know #636 adds the same thing, but while experimenting with the
different install options in
https://github.com/merryhime/dynarmic/pull/636#discussion_r725656034
I ended up with a working patch, so I'm proposing this as well. This
implements solution 2.
This commit is contained in:
Andrea Pappacoda 2021-10-12 10:09:21 +02:00 committed by merry
parent cce7e4ee5d
commit 4dcebc1822
4 changed files with 47 additions and 11 deletions

View file

@ -171,3 +171,32 @@ add_subdirectory(src/dynarmic)
if (DYNARMIC_TESTS) if (DYNARMIC_TESTS)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()
#
# Install
#
if (MASTER_PROJECT)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(TARGETS dynarmic EXPORT dynarmicTargets)
install(EXPORT dynarmicTargets
NAMESPACE dynarmic::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynarmic"
)
configure_package_config_file(CMakeModules/dynarmicConfig.cmake.in
dynarmicConfig.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynarmic"
)
write_basic_package_version_file(dynarmicConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/dynarmicConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/dynarmicConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynarmic"
)
install(DIRECTORY src/dynarmic TYPE INCLUDE FILES_MATCHING PATTERN "*.h")
endif()

View file

@ -0,0 +1,5 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
check_required_components(@PROJECT_NAME@)

View file

@ -24,9 +24,7 @@ target_include_directories(mp INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE
# robin-map # robin-map
if (NOT TARGET tsl::robin_map) if (NOT TARGET tsl::robin_map)
add_library(robin_map INTERFACE) add_subdirectory(robin-map)
add_library(tsl::robin_map ALIAS robin_map)
target_include_directories(robin_map SYSTEM INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/robin-map/include>")
endif() endif()
# vixl # vixl

View file

@ -350,7 +350,7 @@ if (ARCHITECTURE STREQUAL "x86_64")
endif() endif()
elseif (UNIX) elseif (UNIX)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux") if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(dynarmic PUBLIC rt) target_link_libraries(dynarmic PRIVATE rt)
endif() endif()
target_sources(dynarmic PRIVATE backend/x64/exception_handler_posix.cpp) target_sources(dynarmic PRIVATE backend/x64/exception_handler_posix.cpp)
else() else()
@ -363,20 +363,24 @@ endif()
include(CreateDirectoryGroups) include(CreateDirectoryGroups)
create_target_directory_groups(dynarmic) create_target_directory_groups(dynarmic)
target_include_directories(dynarmic PUBLIC ..) target_include_directories(dynarmic PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
set_target_properties(dynarmic PROPERTIES set_target_properties(dynarmic PROPERTIES
VERSION ${dynarmic_VERSION} VERSION ${dynarmic_VERSION}
SOVERSION ${dynarmic_VERSION_MAJOR} SOVERSION ${dynarmic_VERSION_MAJOR}
) )
target_compile_options(dynarmic PRIVATE ${DYNARMIC_CXX_FLAGS}) target_compile_options(dynarmic PRIVATE ${DYNARMIC_CXX_FLAGS})
# $<BUILD_INTERFACE:> required because of https://gitlab.kitware.com/cmake/cmake/-/issues/15415
target_link_libraries(dynarmic target_link_libraries(dynarmic
PUBLIC PRIVATE
boost $<BUILD_INTERFACE:boost>
fmt::fmt $<BUILD_INTERFACE:fmt::fmt>
mp $<BUILD_INTERFACE:mp>
tsl::robin_map tsl::robin_map
xbyak $<BUILD_INTERFACE:xbyak>
Zydis $<BUILD_INTERFACE:Zydis>
$<$<BOOL:DYNARMIC_USE_LLVM>:${llvm_libs}> $<$<BOOL:DYNARMIC_USE_LLVM>:${llvm_libs}>
) )
if (DYNARMIC_ENABLE_CPU_FEATURE_DETECTION) if (DYNARMIC_ENABLE_CPU_FEATURE_DETECTION)