2018-01-01 15:09:45 +00:00
|
|
|
cmake_minimum_required(VERSION 3.8)
|
2021-04-25 21:52:32 +01:00
|
|
|
project(dynarmic C CXX ASM)
|
2016-07-01 14:01:06 +01: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()
|
|
|
|
|
2016-07-01 14:01:06 +01: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 20:52:50 +01:00
|
|
|
option(DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT "Enables support for systems that require W^X" OFF)
|
2019-08-14 20:50:36 +01:00
|
|
|
option(DYNARMIC_FATAL_ERRORS "Errors are fatal" OFF)
|
2017-02-04 20:31:10 +00:00
|
|
|
option(DYNARMIC_TESTS "Build tests" ${MASTER_PROJECT})
|
2018-01-13 18:04:19 +00:00
|
|
|
option(DYNARMIC_TESTS_USE_UNICORN "Enable fuzzing tests against unicorn" OFF)
|
2018-08-23 20:52:50 +01:00
|
|
|
option(DYNARMIC_USE_LLVM "Support disassembly of jitted x86_64 code using LLVM" OFF)
|
2017-02-04 20:31:10 +00:00
|
|
|
option(DYNARMIC_WARNINGS_AS_ERRORS "Warnings as errors" ${MASTER_PROJECT})
|
2020-04-18 11:32:38 +01:00
|
|
|
if (NOT DEFINED DYNARMIC_FRONTENDS)
|
|
|
|
set(DYNARMIC_FRONTENDS "A32;A64" CACHE STRING "Selects which frontends to enable")
|
|
|
|
endif()
|
2016-07-01 14:01:06 +01: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 14:12:46 +01:00
|
|
|
# Set hard requirements for C++
|
2018-01-01 15:09:45 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2016-08-22 14:12:46 +01:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2016-08-25 18:22:08 +01: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 14:12:46 +01:00
|
|
|
|
2016-07-01 14:01:06 +01:00
|
|
|
# Compiler flags
|
2016-08-22 14:25:30 +01:00
|
|
|
if (MSVC)
|
2016-12-19 00:41:21 +00:00
|
|
|
set(DYNARMIC_CXX_FLAGS
|
2019-05-04 05:29:54 +01:00
|
|
|
/std:c++latest # CMAKE_CXX_STANDARD has no effect on MSVC until CMake 3.10.
|
2020-05-21 22:31:54 +01:00
|
|
|
/experimental:external
|
|
|
|
/external:W0
|
|
|
|
/external:anglebrackets
|
2016-12-19 00:41:21 +00:00
|
|
|
/W4
|
2020-05-21 22:31:54 +01: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 22:31:54 +01: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 01:18:20 +01:00
|
|
|
/permissive- # Stricter C++ standards conformance
|
2016-12-19 00:41:21 +00:00
|
|
|
/MP
|
|
|
|
/Zi
|
|
|
|
/Zo
|
|
|
|
/EHsc
|
2019-05-04 05:29:54 +01: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 05:46:22 +01:00
|
|
|
/volatile:iso # Use strict standard-abiding volatile semantics
|
2020-04-23 20:38:57 +01: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()
|
|
|
|
|
2016-12-03 16:06:09 +00:00
|
|
|
if (CMAKE_VS_PLATFORM_TOOLSET MATCHES "LLVM-vs[0-9]+")
|
2016-12-19 00:41:21 +00:00
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS
|
|
|
|
-Qunused-arguments
|
2017-06-12 01:17:04 +01:00
|
|
|
-Wno-missing-braces)
|
2016-12-03 16:06:09 +00:00
|
|
|
endif()
|
2016-08-22 14:25:30 +01:00
|
|
|
else()
|
2016-12-19 00:41:21 +00:00
|
|
|
set(DYNARMIC_CXX_FLAGS
|
|
|
|
-Wall
|
|
|
|
-Wextra
|
|
|
|
-Wcast-qual
|
|
|
|
-pedantic
|
|
|
|
-pedantic-errors
|
2017-06-12 01:17:04 +01:00
|
|
|
-Wno-missing-braces)
|
2016-08-22 22:21:00 +01:00
|
|
|
|
2017-02-04 20:31:10 +00:00
|
|
|
if (DYNARMIC_WARNINGS_AS_ERRORS)
|
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS
|
|
|
|
-Werror)
|
|
|
|
endif()
|
2019-08-14 20:50:36 +01:00
|
|
|
|
|
|
|
if (DYNARMIC_FATAL_ERRORS)
|
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS
|
|
|
|
-Wfatal-errors)
|
|
|
|
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 13:25:33 +01:00
|
|
|
endif()
|
2016-07-01 14:01:06 +01:00
|
|
|
|
|
|
|
# Arch detection
|
2016-08-22 14:12:46 +01:00
|
|
|
include(DetectArchitecture)
|
2016-07-01 14:01:06 +01:00
|
|
|
if (NOT DEFINED ARCHITECTURE)
|
2019-05-04 05:10:45 +01:00
|
|
|
message(FATAL_ERROR "Unsupported architecture encountered. Ending CMake generation.")
|
2016-07-01 14:01:06 +01:00
|
|
|
endif()
|
|
|
|
message(STATUS "Target architecture: ${ARCHITECTURE}")
|
|
|
|
|
|
|
|
# Include Boost
|
2017-12-07 20:28:33 +00:00
|
|
|
if (NOT TARGET boost)
|
|
|
|
if (NOT Boost_INCLUDE_DIRS)
|
|
|
|
find_package(Boost 1.57.0 REQUIRED)
|
2016-07-01 14:01:06 +01:00
|
|
|
endif()
|
2018-02-11 14:57:35 +00:00
|
|
|
add_library(boost INTERFACE)
|
|
|
|
target_include_directories(boost SYSTEM INTERFACE ${Boost_INCLUDE_DIRS})
|
2016-07-01 14:01:06 +01:00
|
|
|
endif()
|
|
|
|
|
2017-02-25 17:31:53 +00:00
|
|
|
# Enable unit-testing.
|
|
|
|
enable_testing(true)
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2016-08-05 01:50:31 +01:00
|
|
|
# Include LLVM
|
|
|
|
if (DYNARMIC_USE_LLVM)
|
|
|
|
find_package(LLVM REQUIRED CONFIG)
|
|
|
|
include_directories(${LLVM_INCLUDE_DIRS})
|
|
|
|
add_definitions(-DDYNARMIC_USE_LLVM ${LLVM_DEFINITIONS})
|
2020-05-17 22:30:46 +01:00
|
|
|
llvm_map_components_to_libnames(llvm_libs armdesc armdisassembler aarch64desc aarch64disassembler x86desc x86disassembler)
|
2016-08-05 01:50:31 +01:00
|
|
|
endif()
|
|
|
|
|
2018-01-13 18:04:19 +00:00
|
|
|
if (DYNARMIC_TESTS_USE_UNICORN)
|
2018-01-14 12:58:30 +00:00
|
|
|
find_package(Unicorn REQUIRED)
|
2018-01-13 18:04:19 +00:00
|
|
|
endif()
|
|
|
|
|
2016-08-25 22:21:19 +01:00
|
|
|
# Pull in externals CMakeLists for libs where available
|
|
|
|
add_subdirectory(externals)
|
|
|
|
|
2016-07-01 14:01:06 +01:00
|
|
|
# Dynarmic project files
|
2021-05-19 17:28:35 +01:00
|
|
|
add_subdirectory(src/dynarmic)
|
2016-09-02 12:29:19 +01:00
|
|
|
if (DYNARMIC_TESTS)
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|