From 4dcebc18228114761ad9dc6a3543bcd4f3317396 Mon Sep 17 00:00:00 2001 From: Andrea Pappacoda Date: Tue, 12 Oct 2021 10:09:21 +0200 Subject: [PATCH] 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. --- CMakeLists.txt | 29 ++++++++++++++++++++++++++++ CMakeModules/dynarmicConfig.cmake.in | 5 +++++ externals/CMakeLists.txt | 4 +--- src/dynarmic/CMakeLists.txt | 20 +++++++++++-------- 4 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 CMakeModules/dynarmicConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index ff98e034..56b7f122 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,3 +171,32 @@ add_subdirectory(src/dynarmic) if (DYNARMIC_TESTS) add_subdirectory(tests) 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() diff --git a/CMakeModules/dynarmicConfig.cmake.in b/CMakeModules/dynarmicConfig.cmake.in new file mode 100644 index 00000000..8c9ad12a --- /dev/null +++ b/CMakeModules/dynarmicConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") + +check_required_components(@PROJECT_NAME@) diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 21ace6fb..e20b5d02 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -24,9 +24,7 @@ target_include_directories(mp INTERFACE $") + add_subdirectory(robin-map) endif() # vixl diff --git a/src/dynarmic/CMakeLists.txt b/src/dynarmic/CMakeLists.txt index 902ac614..d3eecb16 100644 --- a/src/dynarmic/CMakeLists.txt +++ b/src/dynarmic/CMakeLists.txt @@ -350,7 +350,7 @@ if (ARCHITECTURE STREQUAL "x86_64") endif() elseif (UNIX) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_link_libraries(dynarmic PUBLIC rt) + target_link_libraries(dynarmic PRIVATE rt) endif() target_sources(dynarmic PRIVATE backend/x64/exception_handler_posix.cpp) else() @@ -363,20 +363,24 @@ endif() include(CreateDirectoryGroups) create_target_directory_groups(dynarmic) -target_include_directories(dynarmic PUBLIC ..) +target_include_directories(dynarmic PUBLIC + $ + $ +) set_target_properties(dynarmic PROPERTIES VERSION ${dynarmic_VERSION} SOVERSION ${dynarmic_VERSION_MAJOR} ) target_compile_options(dynarmic PRIVATE ${DYNARMIC_CXX_FLAGS}) +# $ required because of https://gitlab.kitware.com/cmake/cmake/-/issues/15415 target_link_libraries(dynarmic - PUBLIC - boost - fmt::fmt - mp + PRIVATE + $ + $ + $ tsl::robin_map - xbyak - Zydis + $ + $ $<$:${llvm_libs}> ) if (DYNARMIC_ENABLE_CPU_FEATURE_DETECTION)