CMakeLists: Support multi-architecture builds

This commit is contained in:
Merry 2023-01-06 14:27:06 +00:00
parent c72ee5473b
commit 6b41b5be07
9 changed files with 59 additions and 19 deletions

View file

@ -134,7 +134,7 @@ find_package(fmt 9 QUIET)
find_package(mcl 0.1.12 EXACT QUIET) find_package(mcl 0.1.12 EXACT QUIET)
find_package(tsl-robin-map QUIET) find_package(tsl-robin-map QUIET)
if (ARCHITECTURE STREQUAL "x86" OR ARCHITECTURE STREQUAL "x86_64") if ("x86_64" IN_LIST ARCHITECTURE)
find_package(xbyak 6 QUIET) find_package(xbyak 6 QUIET)
find_package(Zydis 4 QUIET) find_package(Zydis 4 QUIET)
endif() endif()

View file

@ -1,5 +1,11 @@
include(CheckSymbolExists) include(CheckSymbolExists)
if (CMAKE_OSX_ARCHITECTURES)
set(DYNARMIC_MULTIARCH_BUILD 1)
set(ARCHITECTURE "${CMAKE_OSX_ARCHITECTURES}")
return()
endif()
function(detect_architecture symbol arch) function(detect_architecture symbol arch)
if (NOT DEFINED ARCHITECTURE) if (NOT DEFINED ARCHITECTURE)
set(CMAKE_REQUIRED_QUIET YES) set(CMAKE_REQUIRED_QUIET YES)

View file

@ -0,0 +1,26 @@
function(target_architecture_specific_sources project arch)
if (NOT DYNARMIC_MULTIARCH_BUILD)
target_sources("${project}" PRIVATE ${ARGN})
return()
endif()
foreach(input_file IN LISTS ARGN)
if(input_file MATCHES ".cpp$")
if(NOT IS_ABSOLUTE ${input_file})
set(input_file "${CMAKE_CURRENT_SOURCE_DIR}/${input_file}")
endif()
set(output_file "${CMAKE_CURRENT_BINARY_DIR}/arch_gen/${input_file}")
add_custom_command(
OUTPUT "${output_file}"
COMMAND ${CMAKE_COMMAND} "-Darch=${arch}"
"-Dinput_file=${input_file}"
"-Doutput_file=${output_file}"
-P "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/impl/TargetArchitectureSpecificSourcesWrapFile.cmake"
DEPENDS "${input_file}"
VERBATIM
)
target_sources(${project} PRIVATE "${output_file}")
endif()
endforeach()
endfunction()

View file

@ -0,0 +1,3 @@
string(TOUPPER "${arch}" arch)
file(READ "${input_file}" f_contents)
file(WRITE "${output_file}" "#include <mcl/macro/architecture.hpp>\n#if defined(MCL_ARCHITECTURE_${arch})\n${f_contents}\n#endif\n")

View file

@ -40,7 +40,7 @@ endif()
# oaknut # oaknut
if (NOT TARGET merry::oaknut) if (NOT TARGET merry::oaknut)
if (ARCHITECTURE STREQUAL "arm64") if ("arm64" IN_LIST ARCHITECTURE)
add_subdirectory(oaknut EXCLUDE_FROM_ALL) add_subdirectory(oaknut EXCLUDE_FROM_ALL)
endif() endif()
endif() endif()
@ -54,7 +54,7 @@ endif()
# xbyak # xbyak
if (NOT TARGET xbyak::xbyak) if (NOT TARGET xbyak::xbyak)
if (ARCHITECTURE STREQUAL "x86" OR ARCHITECTURE STREQUAL "x86_64") if ("x86_64" IN_LIST ARCHITECTURE)
add_subdirectory(xbyak EXCLUDE_FROM_ALL) add_subdirectory(xbyak EXCLUDE_FROM_ALL)
endif() endif()
endif() endif()
@ -62,7 +62,7 @@ endif()
# zydis # zydis
if (NOT TARGET Zydis::Zydis) if (NOT TARGET Zydis::Zydis)
if (ARCHITECTURE STREQUAL "x86" OR ARCHITECTURE STREQUAL "x86_64") if ("x86_64" IN_LIST ARCHITECTURE)
set(ZYDIS_BUILD_TOOLS OFF) set(ZYDIS_BUILD_TOOLS OFF)
set(ZYDIS_BUILD_EXAMPLES OFF) set(ZYDIS_BUILD_EXAMPLES OFF)
set(ZYDIS_BUILD_DOXYGEN OFF) set(ZYDIS_BUILD_DOXYGEN OFF)

View file

@ -1,3 +1,5 @@
include(TargetArchitectureSpecificSources)
add_library(dynarmic add_library(dynarmic
backend/exception_handler.h backend/exception_handler.h
common/cast_util.h common/cast_util.h
@ -255,14 +257,14 @@ if ("A64" IN_LIST DYNARMIC_FRONTENDS)
) )
endif() endif()
if (ARCHITECTURE STREQUAL "x86_64") if ("x86_64" IN_LIST ARCHITECTURE)
target_link_libraries(dynarmic target_link_libraries(dynarmic
PRIVATE PRIVATE
xbyak::xbyak xbyak::xbyak
Zydis::Zydis Zydis::Zydis
) )
target_sources(dynarmic PRIVATE target_architecture_specific_sources(dynarmic "x86_64"
backend/x64/abi.cpp backend/x64/abi.cpp
backend/x64/abi.h backend/x64/abi.h
backend/x64/block_of_code.cpp backend/x64/block_of_code.cpp
@ -309,7 +311,7 @@ if (ARCHITECTURE STREQUAL "x86_64")
) )
if ("A32" IN_LIST DYNARMIC_FRONTENDS) if ("A32" IN_LIST DYNARMIC_FRONTENDS)
target_sources(dynarmic PRIVATE target_architecture_specific_sources(dynarmic "x86_64"
backend/x64/a32_emit_x64.cpp backend/x64/a32_emit_x64.cpp
backend/x64/a32_emit_x64.h backend/x64/a32_emit_x64.h
backend/x64/a32_emit_x64_memory.cpp backend/x64/a32_emit_x64_memory.cpp
@ -320,7 +322,7 @@ if (ARCHITECTURE STREQUAL "x86_64")
endif() endif()
if ("A64" IN_LIST DYNARMIC_FRONTENDS) if ("A64" IN_LIST DYNARMIC_FRONTENDS)
target_sources(dynarmic PRIVATE target_architecture_specific_sources(dynarmic "x86_64"
backend/x64/a64_emit_x64.cpp backend/x64/a64_emit_x64.cpp
backend/x64/a64_emit_x64.h backend/x64/a64_emit_x64.h
backend/x64/a64_emit_x64_memory.cpp backend/x64/a64_emit_x64_memory.cpp
@ -329,11 +331,12 @@ if (ARCHITECTURE STREQUAL "x86_64")
backend/x64/a64_jitstate.h backend/x64/a64_jitstate.h
) )
endif() endif()
endif()
elseif(ARCHITECTURE STREQUAL "arm64") if("arm64" IN_LIST ARCHITECTURE)
target_link_libraries(dynarmic PRIVATE merry::oaknut) target_link_libraries(dynarmic PRIVATE merry::oaknut)
target_sources(dynarmic PRIVATE target_architecture_specific_sources(dynarmic "arm64"
backend/arm64/a32_jitstate.cpp backend/arm64/a32_jitstate.cpp
backend/arm64/a32_jitstate.h backend/arm64/a32_jitstate.h
backend/arm64/a64_jitstate.h backend/arm64/a64_jitstate.h
@ -372,7 +375,7 @@ elseif(ARCHITECTURE STREQUAL "arm64")
) )
if ("A32" IN_LIST DYNARMIC_FRONTENDS) if ("A32" IN_LIST DYNARMIC_FRONTENDS)
target_sources(dynarmic PRIVATE target_architecture_specific_sources(dynarmic "arm64"
backend/arm64/a32_address_space.cpp backend/arm64/a32_address_space.cpp
backend/arm64/a32_address_space.h backend/arm64/a32_address_space.h
backend/arm64/a32_core.h backend/arm64/a32_core.h
@ -381,7 +384,7 @@ elseif(ARCHITECTURE STREQUAL "arm64")
endif() endif()
if ("A64" IN_LIST DYNARMIC_FRONTENDS) if ("A64" IN_LIST DYNARMIC_FRONTENDS)
target_sources(dynarmic PRIVATE target_architecture_specific_sources(dynarmic "arm64"
backend/arm64/a64_address_space.cpp backend/arm64/a64_address_space.cpp
backend/arm64/a64_address_space.h backend/arm64/a64_address_space.h
backend/arm64/a64_core.h backend/arm64/a64_core.h
@ -481,9 +484,9 @@ target_compile_definitions(dynarmic PRIVATE FMT_USE_USER_DEFINED_LITERALS=1)
if (DYNARMIC_USE_PRECOMPILED_HEADERS) if (DYNARMIC_USE_PRECOMPILED_HEADERS)
set(PRECOMPILED_HEADERS "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/ir/ir_emitter.h>") set(PRECOMPILED_HEADERS "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/ir/ir_emitter.h>")
if (ARCHITECTURE STREQUAL "x86_64") if ("x86_64" IN_LIST ARCHITECTURE)
list(PREPEND PRECOMPILED_HEADERS "$<$<COMPILE_LANGUAGE:CXX>:<xbyak/xbyak.h$<ANGLE-R>>") list(PREPEND PRECOMPILED_HEADERS "$<$<COMPILE_LANGUAGE:CXX>:<xbyak/xbyak.h$<ANGLE-R>>")
elseif(ARCHITECTURE STREQUAL "arm64") elseif("arm64" IN_LIST ARCHITECTURE)
list(PREPEND PRECOMPILED_HEADERS "$<$<COMPILE_LANGUAGE:CXX>:<oaknut/oaknut.hpp$<ANGLE-R>>") list(PREPEND PRECOMPILED_HEADERS "$<$<COMPILE_LANGUAGE:CXX>:<oaknut/oaknut.hpp$<ANGLE-R>>")
endif() endif()
target_precompile_headers(dynarmic PRIVATE ${PRECOMPILED_HEADERS}) target_precompile_headers(dynarmic PRIVATE ${PRECOMPILED_HEADERS})

View file

@ -132,7 +132,7 @@ void A32EmitX64::GenFastmemFallbacks() {
} }
#define Axx A32 #define Axx A32
#include "emit_x64_memory.cpp.inc" #include "dynarmic/backend/x64/emit_x64_memory.cpp.inc"
#undef Axx #undef Axx
void A32EmitX64::EmitA32ReadMemory8(A32EmitContext& ctx, IR::Inst* inst) { void A32EmitX64::EmitA32ReadMemory8(A32EmitContext& ctx, IR::Inst* inst) {

View file

@ -280,7 +280,7 @@ void A64EmitX64::GenFastmemFallbacks() {
} }
#define Axx A64 #define Axx A64
#include "emit_x64_memory.cpp.inc" #include "dynarmic/backend/x64/emit_x64_memory.cpp.inc"
#undef Axx #undef Axx
void A64EmitX64::EmitA64ReadMemory8(A64EmitContext& ctx, IR::Inst* inst) { void A64EmitX64::EmitA64ReadMemory8(A64EmitContext& ctx, IR::Inst* inst) {

View file

@ -1,3 +1,5 @@
include(TargetArchitectureSpecificSources)
add_executable(dynarmic_tests add_executable(dynarmic_tests
fp/FPToFixed.cpp fp/FPToFixed.cpp
fp/FPValue.cpp fp/FPValue.cpp
@ -55,14 +57,14 @@ if (DYNARMIC_TESTS_USE_UNICORN)
endif() endif()
endif() endif()
if (ARCHITECTURE STREQUAL "x86_64") if ("x86_64" IN_LIST ARCHITECTURE)
target_link_libraries(dynarmic_tests PRIVATE xbyak::xbyak) target_link_libraries(dynarmic_tests PRIVATE xbyak::xbyak)
target_sources(dynarmic_tests PRIVATE target_architecture_specific_sources(dynarmic_tests "x86_64"
x64_cpu_info.cpp x64_cpu_info.cpp
) )
if (NOT MSVC) if (NOT MSVC AND NOT DYNARMIC_MULTIARCH_BUILD)
target_sources(dynarmic_tests PRIVATE target_sources(dynarmic_tests PRIVATE
rsqrt_test.cpp rsqrt_test.cpp
rsqrt_test_fn.s rsqrt_test_fn.s