diff options
author | Dawid Potocki <dawid@dawidpotocki.com> | 2024-03-05 14:09:27 +1300 |
---|---|---|
committer | Dawid Potocki <dawid@dawidpotocki.com> | 2024-03-05 20:34:15 +1300 |
commit | 063e15900bda8453fb0fc6751e78d064501ccbae (patch) | |
tree | a4cd5f01dbca33a262333aff10e1e035217a30c8 /externals/dynarmic/CMakeModules | |
parent | 537296095ab24eddcb196b5ef98004f91de9c8c2 (diff) |
Diffstat (limited to 'externals/dynarmic/CMakeModules')
6 files changed, 174 insertions, 0 deletions
diff --git a/externals/dynarmic/CMakeModules/CreateDirectoryGroups.cmake b/externals/dynarmic/CMakeModules/CreateDirectoryGroups.cmake new file mode 100644 index 0000000000..175899e7dd --- /dev/null +++ b/externals/dynarmic/CMakeModules/CreateDirectoryGroups.cmake @@ -0,0 +1,17 @@ +# This function should be passed a name of an existing target. It will automatically generate +# file groups following the directory hierarchy, so that the layout of the files in IDEs matches the +# one in the filesystem. +function(create_target_directory_groups target_name) + # Place any files that aren't in the source list in a separate group so that they don't get in + # the way. + source_group("Other Files" REGULAR_EXPRESSION ".") + + get_target_property(target_sources "${target_name}" SOURCES) + + foreach(file_name IN LISTS target_sources) + get_filename_component(dir_name "${file_name}" PATH) + # Group names use '\' as a separator even though the entire rest of CMake uses '/'... + string(REPLACE "/" "\\" group_name "${dir_name}") + source_group("${group_name}" FILES "${file_name}") + endforeach() +endfunction() diff --git a/externals/dynarmic/CMakeModules/DetectArchitecture.cmake b/externals/dynarmic/CMakeModules/DetectArchitecture.cmake new file mode 100644 index 0000000000..28bd1ef263 --- /dev/null +++ b/externals/dynarmic/CMakeModules/DetectArchitecture.cmake @@ -0,0 +1,62 @@ +include(CheckSymbolExists) + +if (CMAKE_OSX_ARCHITECTURES) + set(DYNARMIC_MULTIARCH_BUILD 1) + set(ARCHITECTURE "${CMAKE_OSX_ARCHITECTURES}") + return() +endif() + +function(detect_architecture symbol arch) + if (NOT DEFINED ARCHITECTURE) + set(CMAKE_REQUIRED_QUIET YES) + check_symbol_exists("${symbol}" "" DETECT_ARCHITECTURE_${arch}) + unset(CMAKE_REQUIRED_QUIET) + + if (DETECT_ARCHITECTURE_${arch}) + set(ARCHITECTURE "${arch}" PARENT_SCOPE) + endif() + + unset(DETECT_ARCHITECTURE_${arch} CACHE) + endif() +endfunction() + +detect_architecture("__ARM64__" arm64) +detect_architecture("__aarch64__" arm64) +detect_architecture("_M_ARM64" arm64) + +detect_architecture("__arm__" arm) +detect_architecture("__TARGET_ARCH_ARM" arm) +detect_architecture("_M_ARM" arm) + +detect_architecture("__x86_64" x86_64) +detect_architecture("__x86_64__" x86_64) +detect_architecture("__amd64" x86_64) +detect_architecture("_M_X64" x86_64) + +detect_architecture("__i386" x86) +detect_architecture("__i386__" x86) +detect_architecture("_M_IX86" x86) + +detect_architecture("__ia64" ia64) +detect_architecture("__ia64__" ia64) +detect_architecture("_M_IA64" ia64) + +detect_architecture("__mips" mips) +detect_architecture("__mips__" mips) +detect_architecture("_M_MRX000" mips) + +detect_architecture("__ppc64__" ppc64) +detect_architecture("__powerpc64__" ppc64) + +detect_architecture("__ppc__" ppc) +detect_architecture("__ppc" ppc) +detect_architecture("__powerpc__" ppc) +detect_architecture("_ARCH_COM" ppc) +detect_architecture("_ARCH_PWR" ppc) +detect_architecture("_ARCH_PPC" ppc) +detect_architecture("_M_MPPC" ppc) +detect_architecture("_M_PPC" ppc) + +detect_architecture("__riscv" riscv) + +detect_architecture("__EMSCRIPTEN__" wasm) diff --git a/externals/dynarmic/CMakeModules/FindUnicorn.cmake b/externals/dynarmic/CMakeModules/FindUnicorn.cmake new file mode 100644 index 0000000000..71fc08ac37 --- /dev/null +++ b/externals/dynarmic/CMakeModules/FindUnicorn.cmake @@ -0,0 +1,37 @@ +# Exports: +# +# Variables: +# LIBUNICORN_FOUND +# LIBUNICORN_INCLUDE_DIR +# LIBUNICORN_LIBRARY +# +# Target: +# Unicorn::Unicorn +# + +find_path(LIBUNICORN_INCLUDE_DIR + unicorn/unicorn.h + HINTS $ENV{UNICORNDIR} + PATH_SUFFIXES include) + +find_library(LIBUNICORN_LIBRARY + NAMES unicorn + HINTS $ENV{UNICORNDIR}) + +include(FindPackageHandleStandardArgs) +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) diff --git a/externals/dynarmic/CMakeModules/TargetArchitectureSpecificSources.cmake b/externals/dynarmic/CMakeModules/TargetArchitectureSpecificSources.cmake new file mode 100644 index 0000000000..f08911c6f2 --- /dev/null +++ b/externals/dynarmic/CMakeModules/TargetArchitectureSpecificSources.cmake @@ -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() diff --git a/externals/dynarmic/CMakeModules/dynarmicConfig.cmake.in b/externals/dynarmic/CMakeModules/dynarmicConfig.cmake.in new file mode 100644 index 0000000000..0261239105 --- /dev/null +++ b/externals/dynarmic/CMakeModules/dynarmicConfig.cmake.in @@ -0,0 +1,29 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +set(ARCHITECTURE "@ARCHITECTURE@") + +if (NOT @BUILD_SHARED_LIBS@) + find_dependency(Boost 1.57) + find_dependency(fmt 9) + find_dependency(mcl 0.1.12 EXACT) + find_dependency(tsl-robin-map) + + if ("arm64" IN_LIST ARCHITECTURE) + find_dependency(oaknut 2.0.1) + endif() + + if ("x86_64" IN_LIST ARCHITECTURE) + find_dependency(xbyak 7) + find_dependency(Zydis 4) + endif() + + if (@DYNARMIC_USE_LLVM@) + find_dependency(LLVM) + endif() +endif() + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") + +check_required_components(@PROJECT_NAME@) diff --git a/externals/dynarmic/CMakeModules/impl/TargetArchitectureSpecificSourcesWrapFile.cmake b/externals/dynarmic/CMakeModules/impl/TargetArchitectureSpecificSourcesWrapFile.cmake new file mode 100644 index 0000000000..82b3078a11 --- /dev/null +++ b/externals/dynarmic/CMakeModules/impl/TargetArchitectureSpecificSourcesWrapFile.cmake @@ -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") |