cmake: multiple simplifications

This commit is contained in:
Alexandre Bouvier 2022-11-22 02:42:52 +01:00 committed by merry
parent b24780d10b
commit 905d822810
6 changed files with 63 additions and 90 deletions

View file

@ -44,7 +44,7 @@ jobs:
run: > run: >
cmake cmake
-B ${{github.workspace}}/build-arm64 -B ${{github.workspace}}/build-arm64
-DBoost_INCLUDE_DIRS=${{github.workspace}}/externals/ext-boost -DBOOST_INCLUDEDIR=${{github.workspace}}/externals/ext-boost
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-DDYNARMIC_TESTS_USE_UNICORN=0 -DDYNARMIC_TESTS_USE_UNICORN=0
-DDYNARMIC_USE_LLVM=0 -DDYNARMIC_USE_LLVM=0
@ -62,7 +62,7 @@ jobs:
run: > run: >
cmake cmake
-B ${{github.workspace}}/build-x64 -B ${{github.workspace}}/build-x64
-DBoost_INCLUDE_DIRS=${{github.workspace}}/externals/ext-boost -DBOOST_INCLUDEDIR=${{github.workspace}}/externals/ext-boost
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache

View file

@ -57,7 +57,7 @@ jobs:
run: > run: >
cmake cmake
-B ${{github.workspace}}/build -B ${{github.workspace}}/build
-DBoost_INCLUDE_DIRS=${{github.workspace}}/externals/ext-boost -DBOOST_INCLUDEDIR=${{github.workspace}}/externals/ext-boost
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-DDYNARMIC_ENABLE_CPU_FEATURE_DETECTION=${{matrix.cpu_detection}} -DDYNARMIC_ENABLE_CPU_FEATURE_DETECTION=${{matrix.cpu_detection}}
-DDYNARMIC_TESTS_USE_UNICORN=1 -DDYNARMIC_TESTS_USE_UNICORN=1
@ -71,7 +71,7 @@ jobs:
run: > run: >
cmake cmake
-B ${{github.workspace}}/build -B ${{github.workspace}}/build
-DBoost_INCLUDE_DIRS=${{github.workspace}}/externals/ext-boost -DBOOST_INCLUDEDIR=${{github.workspace}}/externals/ext-boost
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-DDYNARMIC_ENABLE_CPU_FEATURE_DETECTION=${{matrix.cpu_detection}} -DDYNARMIC_ENABLE_CPU_FEATURE_DETECTION=${{matrix.cpu_detection}}
-DDYNARMIC_TESTS_USE_UNICORN=1 -DDYNARMIC_TESTS_USE_UNICORN=1
@ -85,7 +85,7 @@ jobs:
run: > run: >
cmake cmake
-B ${{github.workspace}}/build -B ${{github.workspace}}/build
-DBoost_INCLUDE_DIRS=${{github.workspace}}/externals/ext-boost -DBOOST_INCLUDEDIR=${{github.workspace}}/externals/ext-boost
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-DDYNARMIC_ENABLE_CPU_FEATURE_DETECTION=${{matrix.cpu_detection}} -DDYNARMIC_ENABLE_CPU_FEATURE_DETECTION=${{matrix.cpu_detection}}
-G "Visual Studio 17 2022" -G "Visual Studio 17 2022"

View file

@ -113,36 +113,14 @@ if (NOT DEFINED ARCHITECTURE)
endif() endif()
message(STATUS "Target architecture: ${ARCHITECTURE}") message(STATUS "Target architecture: ${ARCHITECTURE}")
# Include Boost # Forced use of external for non-REQUIRED library is possible with e.g. cmake -DCMAKE_DISABLE_FIND_PACKAGE_fmt=ON ...
if (NOT TARGET boost) find_package(Boost 1.57 REQUIRED)
if (NOT Boost_INCLUDE_DIRS) find_package(fmt 9)
find_package(Boost 1.57.0 REQUIRED) find_package(tsl-robin-map)
endif()
add_library(boost INTERFACE)
target_include_directories(boost SYSTEM INTERFACE ${Boost_INCLUDE_DIRS})
endif()
if (DYNARMIC_NO_BUNDLED_FMT AND NOT TARGET fmt AND NOT TARGET fmt::fmt) if (ARCHITECTURE STREQUAL "x86" OR ARCHITECTURE STREQUAL "x86_64")
find_package(fmt REQUIRED) find_package(xbyak 6)
add_library(fmt ALIAS fmt::fmt) find_package(Zydis 4)
endif()
if (DYNARMIC_NO_BUNDLED_ROBIN_MAP AND NOT TARGET tsl::robin_map)
find_package(tsl-robin-map REQUIRED)
endif()
if (DYNARMIC_NO_BUNDLED_XBYAK AND NOT TARGET xbyak)
if (ARCHITECTURE STREQUAL "x86" OR ARCHITECTURE STREQUAL "x86_64")
find_package(xbyak REQUIRED)
add_library(xbyak ALIAS xbyak::xbyak)
endif()
endif()
if (DYNARMIC_NO_BUNDLED_ZYDIS AND NOT TARGET Zydis)
if (ARCHITECTURE STREQUAL "x86" OR ARCHITECTURE STREQUAL "x86_64")
find_package(Zydis REQUIRED)
add_library(Zydis ALIAS Zydis::Zydis)
endif()
endif() endif()
# Enable unit-testing. # Enable unit-testing.
@ -156,13 +134,11 @@ if (DYNARMIC_USE_LLVM)
llvm_map_components_to_libnames(llvm_libs armdesc armdisassembler aarch64desc aarch64disassembler x86desc x86disassembler) llvm_map_components_to_libnames(llvm_libs armdesc armdisassembler aarch64desc aarch64disassembler x86desc x86disassembler)
endif() endif()
if (DYNARMIC_TESTS_USE_UNICORN AND DYNARMIC_TESTS) if (DYNARMIC_TESTS)
find_package(Unicorn REQUIRED) find_package(Catch2 2)
endif() if (DYNARMIC_TESTS_USE_UNICORN)
find_package(Unicorn REQUIRED)
if (DYNARMIC_TESTS AND DYNARMIC_NO_BUNDLED_CATCH AND NOT TARGET catch) endif()
find_package(Catch2 REQUIRED)
add_library(catch ALIAS Catch2::Catch2)
endif() endif()
# Pull in externals CMakeLists for libs where available # Pull in externals CMakeLists for libs where available
@ -177,28 +153,26 @@ endif()
# #
# Install # Install
# #
if (MASTER_PROJECT) include(GNUInstallDirs)
include(GNUInstallDirs) include(CMakePackageConfigHelpers)
include(CMakePackageConfigHelpers)
install(TARGETS dynarmic EXPORT dynarmicTargets) install(TARGETS dynarmic EXPORT dynarmicTargets)
install(EXPORT dynarmicTargets install(EXPORT dynarmicTargets
NAMESPACE dynarmic:: NAMESPACE dynarmic::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynarmic" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynarmic"
) )
configure_package_config_file(CMakeModules/dynarmicConfig.cmake.in configure_package_config_file(CMakeModules/dynarmicConfig.cmake.in
dynarmicConfig.cmake dynarmicConfig.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynarmic" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynarmic"
) )
write_basic_package_version_file(dynarmicConfigVersion.cmake write_basic_package_version_file(dynarmicConfigVersion.cmake
COMPATIBILITY SameMajorVersion COMPATIBILITY SameMajorVersion
) )
install(FILES install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/dynarmicConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/dynarmicConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/dynarmicConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/dynarmicConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynarmic" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynarmic"
) )
install(DIRECTORY src/dynarmic TYPE INCLUDE FILES_MATCHING PATTERN "*.h") install(DIRECTORY src/dynarmic TYPE INCLUDE FILES_MATCHING PATTERN "*.h")
endif()

View file

@ -10,58 +10,59 @@ endif()
# catch # catch
if (DYNARMIC_TESTS AND NOT TARGET catch) if (NOT TARGET Catch2::Catch2)
add_library(catch INTERFACE) if (DYNARMIC_TESTS)
target_include_directories(catch INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/catch/include>) add_library(Catch2::Catch2 INTERFACE IMPORTED GLOBAL)
target_include_directories(Catch2::Catch2 INTERFACE catch/include)
endif()
endif() endif()
# fmt # fmt
if (NOT TARGET fmt AND NOT TARGET fmt::fmt) if (NOT TARGET fmt::fmt)
# fmtlib formatting library # fmtlib formatting library
add_subdirectory(fmt) option(FMT_INSTALL "" ON)
add_subdirectory(fmt EXCLUDE_FROM_ALL)
endif() endif()
# mcl # mcl
if (NOT TARGET merry::mcl) if (NOT TARGET merry::mcl)
add_subdirectory(mcl) option(MCL_INSTALL "" ON)
add_subdirectory(mcl EXCLUDE_FROM_ALL)
endif() endif()
# oaknut # oaknut
if (NOT TARGET merry::oaknut) if (NOT TARGET merry::oaknut)
if (ARCHITECTURE STREQUAL "arm64") if (ARCHITECTURE STREQUAL "arm64")
add_subdirectory(oaknut) add_subdirectory(oaknut EXCLUDE_FROM_ALL)
endif() endif()
endif() endif()
# robin-map # robin-map
if (NOT TARGET tsl::robin_map) if (NOT TARGET tsl::robin_map)
add_subdirectory(robin-map) add_subdirectory(robin-map EXCLUDE_FROM_ALL)
endif() endif()
# xbyak # xbyak
if (NOT TARGET xbyak) if (NOT TARGET xbyak::xbyak)
if (ARCHITECTURE STREQUAL "x86" OR ARCHITECTURE STREQUAL "x86_64") if (ARCHITECTURE STREQUAL "x86" OR ARCHITECTURE STREQUAL "x86_64")
add_library(xbyak INTERFACE) add_subdirectory(xbyak EXCLUDE_FROM_ALL)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/xbyak/include)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/xbyak/xbyak DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/xbyak/include)
target_include_directories(xbyak SYSTEM INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/xbyak/include)
target_compile_definitions(xbyak INTERFACE XBYAK_NO_OP_NAMES)
endif() endif()
endif() endif()
# zydis # zydis
if (NOT TARGET Zydis) if (NOT TARGET Zydis::Zydis)
if (ARCHITECTURE STREQUAL "x86" OR ARCHITECTURE STREQUAL "x86_64") if (ARCHITECTURE STREQUAL "x86" OR ARCHITECTURE STREQUAL "x86_64")
option(ZYDIS_BUILD_TOOLS "" OFF) option(ZYDIS_BUILD_TOOLS "" OFF)
option(ZYDIS_BUILD_EXAMPLES "" OFF) option(ZYDIS_BUILD_EXAMPLES "" OFF)
option(ZYDIS_BUILD_DOXYGEN "" OFF) option(ZYDIS_BUILD_DOXYGEN "" OFF)
set(ZYAN_ZYCORE_PATH "${CMAKE_CURRENT_LIST_DIR}/zycore" CACHE PATH "") set(ZYAN_ZYCORE_PATH "${CMAKE_CURRENT_LIST_DIR}/zycore" CACHE PATH "")
add_subdirectory(zydis EXCLUDE_FROM_ALL) add_subdirectory(zydis EXCLUDE_FROM_ALL)
add_library(Zydis::Zydis ALIAS Zydis)
endif() endif()
endif() endif()

View file

@ -257,8 +257,8 @@ endif()
if (ARCHITECTURE STREQUAL "x86_64") if (ARCHITECTURE STREQUAL "x86_64")
target_link_libraries(dynarmic target_link_libraries(dynarmic
PRIVATE PRIVATE
$<BUILD_INTERFACE:xbyak> xbyak::xbyak
$<BUILD_INTERFACE:Zydis> Zydis::Zydis
) )
target_sources(dynarmic PRIVATE target_sources(dynarmic PRIVATE
@ -366,7 +366,7 @@ if (ARCHITECTURE STREQUAL "x86_64")
target_sources(dynarmic PRIVATE backend/x64/exception_handler_generic.cpp) target_sources(dynarmic PRIVATE backend/x64/exception_handler_generic.cpp)
endif() endif()
elseif(ARCHITECTURE STREQUAL "arm64") elseif(ARCHITECTURE STREQUAL "arm64")
target_link_libraries(dynarmic PRIVATE $<BUILD_INTERFACE:merry::oaknut>) target_link_libraries(dynarmic PRIVATE merry::oaknut)
target_sources(dynarmic PRIVATE target_sources(dynarmic PRIVATE
backend/arm64/a32_jitstate.cpp backend/arm64/a32_jitstate.cpp
@ -431,13 +431,11 @@ set_target_properties(dynarmic PROPERTIES
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
$<BUILD_INTERFACE:merry::mcl>
PRIVATE PRIVATE
$<BUILD_INTERFACE:boost> Boost::boost
$<BUILD_INTERFACE:fmt::fmt> fmt::fmt
merry::mcl
tsl::robin_map tsl::robin_map
"$<$<BOOL:DYNARMIC_USE_LLVM>:${llvm_libs}>" "$<$<BOOL:DYNARMIC_USE_LLVM>:${llvm_libs}>"
) )

View file

@ -55,7 +55,7 @@ if (DYNARMIC_TESTS_USE_UNICORN)
endif() endif()
if (ARCHITECTURE STREQUAL "x86_64") if (ARCHITECTURE STREQUAL "x86_64")
target_link_libraries(dynarmic_tests PRIVATE xbyak) target_link_libraries(dynarmic_tests PRIVATE xbyak::xbyak)
target_sources(dynarmic_tests PRIVATE target_sources(dynarmic_tests PRIVATE
x64_cpu_info.cpp x64_cpu_info.cpp
@ -78,7 +78,7 @@ if (("A32" IN_LIST DYNARMIC_FRONTENDS) AND ("A64" IN_LIST DYNARMIC_FRONTENDS))
create_target_directory_groups(dynarmic_print_info) create_target_directory_groups(dynarmic_print_info)
target_link_libraries(dynarmic_print_info PRIVATE dynarmic boost catch fmt) target_link_libraries(dynarmic_print_info PRIVATE dynarmic Boost::boost Catch2::Catch2 fmt::fmt merry::mcl)
target_include_directories(dynarmic_print_info PRIVATE . ../src) target_include_directories(dynarmic_print_info PRIVATE . ../src)
target_compile_options(dynarmic_print_info PRIVATE ${DYNARMIC_CXX_FLAGS}) target_compile_options(dynarmic_print_info PRIVATE ${DYNARMIC_CXX_FLAGS})
target_compile_definitions(dynarmic_print_info PRIVATE FMT_USE_USER_DEFINED_LITERALS=1) target_compile_definitions(dynarmic_print_info PRIVATE FMT_USE_USER_DEFINED_LITERALS=1)
@ -93,7 +93,7 @@ if ("A32" IN_LIST DYNARMIC_FRONTENDS)
create_target_directory_groups(dynarmic_test_generator) create_target_directory_groups(dynarmic_test_generator)
target_link_libraries(dynarmic_test_generator PRIVATE dynarmic boost catch fmt) target_link_libraries(dynarmic_test_generator PRIVATE dynarmic Boost::boost Catch2::Catch2 fmt::fmt merry::mcl)
target_include_directories(dynarmic_test_generator PRIVATE . ../src) target_include_directories(dynarmic_test_generator PRIVATE . ../src)
target_compile_options(dynarmic_test_generator PRIVATE ${DYNARMIC_CXX_FLAGS}) target_compile_options(dynarmic_test_generator PRIVATE ${DYNARMIC_CXX_FLAGS})
target_compile_definitions(dynarmic_test_generator PRIVATE FMT_USE_USER_DEFINED_LITERALS=1) target_compile_definitions(dynarmic_test_generator PRIVATE FMT_USE_USER_DEFINED_LITERALS=1)
@ -101,7 +101,7 @@ endif()
create_target_directory_groups(dynarmic_tests) create_target_directory_groups(dynarmic_tests)
target_link_libraries(dynarmic_tests PRIVATE dynarmic boost catch fmt) target_link_libraries(dynarmic_tests PRIVATE dynarmic Boost::boost Catch2::Catch2 fmt::fmt merry::mcl)
target_include_directories(dynarmic_tests PRIVATE . ../src) target_include_directories(dynarmic_tests PRIVATE . ../src)
target_compile_options(dynarmic_tests PRIVATE ${DYNARMIC_CXX_FLAGS}) target_compile_options(dynarmic_tests PRIVATE ${DYNARMIC_CXX_FLAGS})
target_compile_definitions(dynarmic_tests PRIVATE FMT_USE_USER_DEFINED_LITERALS=1 CATCH_CONFIG_ENABLE_BENCHMARKING=1) target_compile_definitions(dynarmic_tests PRIVATE FMT_USE_USER_DEFINED_LITERALS=1 CATCH_CONFIG_ENABLE_BENCHMARKING=1)