2022-08-15 18:00:14 +00:00
|
|
|
cmake_minimum_required(VERSION 3.12)
|
2024-03-02 17:06:53 +00:00
|
|
|
project(dynarmic LANGUAGES C CXX ASM VERSION 6.7.0)
|
2016-07-01 13:01:06 +00:00
|
|
|
|
2017-02-04 20:31:10 +00:00
|
|
|
# Determine if we're built as a subproject (using add_subdirectory)
|
|
|
|
# or if this is the master project.
|
|
|
|
set(MASTER_PROJECT OFF)
|
|
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
|
|
set(MASTER_PROJECT ON)
|
|
|
|
endif()
|
|
|
|
|
2022-12-31 18:43:35 +00:00
|
|
|
if (MASTER_PROJECT)
|
|
|
|
include(CTest)
|
|
|
|
endif()
|
2022-11-24 08:09:19 +00:00
|
|
|
|
2016-07-01 13:01:06 +00:00
|
|
|
# Dynarmic project options
|
2018-01-24 19:14:19 +00:00
|
|
|
option(DYNARMIC_ENABLE_CPU_FEATURE_DETECTION "Turning this off causes dynarmic to assume the host CPU doesn't support anything later than SSE3" ON)
|
2018-08-23 19:52:50 +00:00
|
|
|
option(DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT "Enables support for systems that require W^X" OFF)
|
2019-08-14 19:50:36 +00:00
|
|
|
option(DYNARMIC_FATAL_ERRORS "Errors are fatal" OFF)
|
2021-08-15 15:09:37 +00:00
|
|
|
option(DYNARMIC_IGNORE_ASSERTS "Ignore asserts" OFF)
|
2022-12-31 18:43:35 +00:00
|
|
|
option(DYNARMIC_TESTS "Build tests" ${BUILD_TESTING})
|
2018-01-13 18:04:19 +00:00
|
|
|
option(DYNARMIC_TESTS_USE_UNICORN "Enable fuzzing tests against unicorn" OFF)
|
2018-08-23 19:52:50 +00:00
|
|
|
option(DYNARMIC_USE_LLVM "Support disassembly of jitted x86_64 code using LLVM" OFF)
|
2022-11-22 03:45:11 +00:00
|
|
|
option(DYNARMIC_USE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
|
2022-11-30 00:28:48 +00:00
|
|
|
option(DYNARMIC_USE_BUNDLED_EXTERNALS "Use all bundled externals (useful when e.g. cross-compiling)" OFF)
|
2017-02-04 20:31:10 +00:00
|
|
|
option(DYNARMIC_WARNINGS_AS_ERRORS "Warnings as errors" ${MASTER_PROJECT})
|
2020-04-18 10:32:38 +00:00
|
|
|
if (NOT DEFINED DYNARMIC_FRONTENDS)
|
|
|
|
set(DYNARMIC_FRONTENDS "A32;A64" CACHE STRING "Selects which frontends to enable")
|
|
|
|
endif()
|
2016-07-01 13:01:06 +00:00
|
|
|
|
2017-11-28 20:08:45 +00:00
|
|
|
# Default to a Release build
|
|
|
|
if (NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
|
|
|
message(STATUS "Defaulting to a Release build")
|
|
|
|
endif()
|
|
|
|
|
2016-08-22 13:12:46 +00:00
|
|
|
# Set hard requirements for C++
|
2021-08-15 14:16:31 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
2016-08-22 13:12:46 +00:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2016-08-25 17:22:08 +00:00
|
|
|
# Disable in-source builds
|
|
|
|
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
|
|
|
|
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
|
|
|
|
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
|
|
|
|
message(SEND_ERROR "In-source builds are not allowed.")
|
|
|
|
endif()
|
|
|
|
|
2017-02-23 01:34:51 +00:00
|
|
|
# Add the module directory to the list of paths
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules")
|
2016-08-22 13:12:46 +00:00
|
|
|
|
2016-07-01 13:01:06 +00:00
|
|
|
# Compiler flags
|
2016-08-22 13:25:30 +00:00
|
|
|
if (MSVC)
|
2016-12-19 00:41:21 +00:00
|
|
|
set(DYNARMIC_CXX_FLAGS
|
2020-05-21 21:31:54 +00:00
|
|
|
/experimental:external
|
|
|
|
/external:W0
|
|
|
|
/external:anglebrackets
|
2016-12-19 00:41:21 +00:00
|
|
|
/W4
|
2020-05-21 21:31:54 +00:00
|
|
|
/w44263 # Non-virtual member function hides base class virtual function
|
2016-12-19 00:41:21 +00:00
|
|
|
/w44265 # Class has virtual functions, but destructor is not virtual
|
2020-05-21 21:31:54 +00:00
|
|
|
/w44456 # Declaration of 'var' hides previous local declaration
|
|
|
|
/w44457 # Declaration of 'var' hides function parameter
|
|
|
|
/w44458 # Declaration of 'var' hides class member
|
|
|
|
/w44459 # Declaration of 'var' hides global definition
|
|
|
|
/w44946 # Reinterpret-cast between related types
|
2016-12-19 00:41:21 +00:00
|
|
|
/wd4592 # Symbol will be dynamically initialized (implementation limitation)
|
2017-06-12 00:18:20 +00:00
|
|
|
/permissive- # Stricter C++ standards conformance
|
2016-12-19 00:41:21 +00:00
|
|
|
/MP
|
|
|
|
/Zi
|
|
|
|
/Zo
|
|
|
|
/EHsc
|
2019-05-04 04:29:54 +00:00
|
|
|
/Zc:externConstexpr # Allows external linkage for variables declared "extern constexpr", as the standard permits.
|
|
|
|
/Zc:inline # Omits inline functions from object-file output.
|
|
|
|
/Zc:throwingNew # Assumes new (without std::nothrow) never returns null.
|
2019-05-04 04:46:22 +00:00
|
|
|
/volatile:iso # Use strict standard-abiding volatile semantics
|
2020-04-23 19:38:57 +00:00
|
|
|
/bigobj # Increase number of sections in .obj files
|
2016-12-19 00:41:21 +00:00
|
|
|
/DNOMINMAX)
|
2016-12-03 16:06:09 +00:00
|
|
|
|
2017-02-04 20:31:10 +00:00
|
|
|
if (DYNARMIC_WARNINGS_AS_ERRORS)
|
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS
|
|
|
|
/WX)
|
|
|
|
endif()
|
|
|
|
|
2023-11-23 20:24:21 +00:00
|
|
|
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
2016-12-19 00:41:21 +00:00
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS
|
|
|
|
-Qunused-arguments
|
2017-06-12 00:17:04 +00:00
|
|
|
-Wno-missing-braces)
|
2016-12-03 16:06:09 +00:00
|
|
|
endif()
|
2016-08-22 13:25:30 +00:00
|
|
|
else()
|
2016-12-19 00:41:21 +00:00
|
|
|
set(DYNARMIC_CXX_FLAGS
|
|
|
|
-Wall
|
|
|
|
-Wextra
|
|
|
|
-Wcast-qual
|
|
|
|
-pedantic
|
2017-06-12 00:17:04 +00:00
|
|
|
-Wno-missing-braces)
|
2016-08-22 21:21:00 +00:00
|
|
|
|
2017-02-04 20:31:10 +00:00
|
|
|
if (DYNARMIC_WARNINGS_AS_ERRORS)
|
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS
|
2023-09-01 20:09:34 +00:00
|
|
|
-pedantic-errors
|
2017-02-04 20:31:10 +00:00
|
|
|
-Werror)
|
|
|
|
endif()
|
2019-08-14 19:50:36 +00:00
|
|
|
|
|
|
|
if (DYNARMIC_FATAL_ERRORS)
|
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS
|
|
|
|
-Wfatal-errors)
|
|
|
|
endif()
|
2021-02-16 20:07:55 +00:00
|
|
|
|
2023-08-20 21:30:09 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|
|
|
# GCC produces bogus -Warray-bounds warnings from xbyak headers for code paths that are not
|
|
|
|
# actually reachable. Specifically, it happens in cases where some code casts an Operand&
|
|
|
|
# to Address& after first checking isMEM(), and that code is inlined in a situation where
|
|
|
|
# GCC knows that the variable is actually a Reg64. isMEM() will never return true for a
|
|
|
|
# Reg64, but GCC doesn't know that.
|
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS -Wno-array-bounds)
|
|
|
|
endif()
|
|
|
|
|
2021-02-16 20:07:55 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang")
|
|
|
|
# Bracket depth determines maximum size of a fold expression in Clang since 9c9974c3ccb6.
|
|
|
|
# And this in turns limits the size of a std::array.
|
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS -fbracket-depth=1024)
|
|
|
|
endif()
|
2016-07-12 12:25:33 +00:00
|
|
|
endif()
|
2016-07-01 13:01:06 +00:00
|
|
|
|
|
|
|
# Arch detection
|
2016-08-22 13:12:46 +00:00
|
|
|
include(DetectArchitecture)
|
2016-07-01 13:01:06 +00:00
|
|
|
if (NOT DEFINED ARCHITECTURE)
|
2019-05-04 04:10:45 +00:00
|
|
|
message(FATAL_ERROR "Unsupported architecture encountered. Ending CMake generation.")
|
2016-07-01 13:01:06 +00:00
|
|
|
endif()
|
|
|
|
message(STATUS "Target architecture: ${ARCHITECTURE}")
|
|
|
|
|
2022-11-30 00:28:48 +00:00
|
|
|
# Forced use of individual bundled libraries for non-REQUIRED library is possible with e.g. cmake -DCMAKE_DISABLE_FIND_PACKAGE_fmt=ON ...
|
|
|
|
|
|
|
|
if (DYNARMIC_USE_BUNDLED_EXTERNALS)
|
|
|
|
set(CMAKE_DISABLE_FIND_PACKAGE_Catch2 ON)
|
|
|
|
set(CMAKE_DISABLE_FIND_PACKAGE_fmt ON)
|
2022-12-28 19:29:51 +00:00
|
|
|
set(CMAKE_DISABLE_FIND_PACKAGE_mcl ON)
|
2024-01-29 21:40:57 +00:00
|
|
|
set(CMAKE_DISABLE_FIND_PACKAGE_oaknut ON)
|
2022-11-30 00:28:48 +00:00
|
|
|
set(CMAKE_DISABLE_FIND_PACKAGE_tsl-robin-map ON)
|
|
|
|
set(CMAKE_DISABLE_FIND_PACKAGE_xbyak ON)
|
|
|
|
set(CMAKE_DISABLE_FIND_PACKAGE_Zydis ON)
|
|
|
|
endif()
|
|
|
|
|
2022-11-22 01:42:52 +00:00
|
|
|
find_package(Boost 1.57 REQUIRED)
|
2024-01-29 21:40:57 +00:00
|
|
|
find_package(fmt 9 CONFIG)
|
|
|
|
find_package(mcl 0.1.12 EXACT CONFIG)
|
|
|
|
find_package(tsl-robin-map CONFIG)
|
|
|
|
|
|
|
|
if ("arm64" IN_LIST ARCHITECTURE OR DYNARMIC_TESTS)
|
|
|
|
find_package(oaknut 2.0.1 CONFIG)
|
|
|
|
endif()
|
2021-08-10 14:05:38 +00:00
|
|
|
|
2023-01-06 14:27:06 +00:00
|
|
|
if ("x86_64" IN_LIST ARCHITECTURE)
|
2024-01-30 00:36:49 +00:00
|
|
|
find_package(xbyak 7 CONFIG)
|
2024-01-29 21:40:57 +00:00
|
|
|
find_package(Zydis 4 CONFIG)
|
2021-08-24 10:28:44 +00:00
|
|
|
endif()
|
|
|
|
|
2016-08-05 00:50:31 +00:00
|
|
|
if (DYNARMIC_USE_LLVM)
|
2024-01-29 21:40:57 +00:00
|
|
|
find_package(LLVM REQUIRED)
|
2023-02-27 08:16:10 +00:00
|
|
|
separate_arguments(LLVM_DEFINITIONS)
|
2016-08-05 00:50:31 +00:00
|
|
|
endif()
|
|
|
|
|
2022-11-22 01:42:52 +00:00
|
|
|
if (DYNARMIC_TESTS)
|
2024-01-29 21:40:57 +00:00
|
|
|
find_package(Catch2 3 CONFIG)
|
2022-11-22 01:42:52 +00:00
|
|
|
if (DYNARMIC_TESTS_USE_UNICORN)
|
|
|
|
find_package(Unicorn REQUIRED)
|
|
|
|
endif()
|
2021-08-10 14:05:38 +00:00
|
|
|
endif()
|
|
|
|
|
2016-08-25 21:21:19 +00:00
|
|
|
# Pull in externals CMakeLists for libs where available
|
|
|
|
add_subdirectory(externals)
|
|
|
|
|
2016-07-01 13:01:06 +00:00
|
|
|
# Dynarmic project files
|
2021-05-19 16:28:35 +00:00
|
|
|
add_subdirectory(src/dynarmic)
|
2016-09-02 11:29:19 +00:00
|
|
|
if (DYNARMIC_TESTS)
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|
2021-10-12 08:09:21 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Install
|
|
|
|
#
|
2022-11-22 01:42:52 +00:00
|
|
|
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")
|