2018-01-01 16:09:45 +01:00
|
|
|
cmake_minimum_required(VERSION 3.8)
|
2016-08-25 19:22:08 +02:00
|
|
|
project(dynarmic CXX)
|
2016-07-01 15:01:06 +02:00
|
|
|
|
2017-02-04 21:31:10 +01: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 15:01:06 +02:00
|
|
|
# Dynarmic project options
|
2018-01-24 20:14:19 +01: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 21:52:50 +02:00
|
|
|
option(DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT "Enables support for systems that require W^X" OFF)
|
2017-02-04 21:31:10 +01:00
|
|
|
option(DYNARMIC_TESTS "Build tests" ${MASTER_PROJECT})
|
2018-01-13 19:04:19 +01:00
|
|
|
option(DYNARMIC_TESTS_USE_UNICORN "Enable fuzzing tests against unicorn" OFF)
|
2018-08-23 21:52:50 +02:00
|
|
|
option(DYNARMIC_USE_LLVM "Support disassembly of jitted x86_64 code using LLVM" OFF)
|
2017-02-04 21:31:10 +01:00
|
|
|
option(DYNARMIC_WARNINGS_AS_ERRORS "Warnings as errors" ${MASTER_PROJECT})
|
2016-07-01 15:01:06 +02:00
|
|
|
|
2017-11-28 21:08:45 +01: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 15:12:46 +02:00
|
|
|
# Set hard requirements for C++
|
2018-01-01 16:09:45 +01:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2016-08-22 15:12:46 +02:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2016-08-22 15:15:05 +02:00
|
|
|
# Warn on CMake API deprecations
|
|
|
|
set(CMAKE_WARN_DEPRECATED ON)
|
|
|
|
|
2016-08-25 19:22:08 +02: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 02:34:51 +01:00
|
|
|
# Add the module directory to the list of paths
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules")
|
2016-08-22 15:12:46 +02:00
|
|
|
|
2016-07-01 15:01:06 +02:00
|
|
|
# Compiler flags
|
2016-08-22 15:25:30 +02:00
|
|
|
if (MSVC)
|
2016-12-19 01:41:21 +01:00
|
|
|
set(DYNARMIC_CXX_FLAGS
|
2018-01-09 19:41:22 +01:00
|
|
|
/std:c++latest # CMAKE_CXX_STANDARD as no effect on MSVC until CMake 3.10.
|
2016-12-19 01:41:21 +01:00
|
|
|
/W4
|
|
|
|
/w34263 # Non-virtual member function hides base class virtual function
|
|
|
|
/w44265 # Class has virtual functions, but destructor is not virtual
|
|
|
|
/w34456 # Declaration of 'var' hides previous local declaration
|
|
|
|
/w34457 # Declaration of 'var' hides function parameter
|
|
|
|
/w34458 # Declaration of 'var' hides class member
|
|
|
|
/w34459 # Declaration of 'var' hides global definition
|
|
|
|
/w34946 # Reinterpret-cast between related types
|
|
|
|
/wd4592 # Symbol will be dynamically initialized (implementation limitation)
|
2017-06-12 02:18:20 +02:00
|
|
|
/permissive- # Stricter C++ standards conformance
|
2016-12-19 01:41:21 +01:00
|
|
|
/MP
|
|
|
|
/Zi
|
|
|
|
/Zo
|
|
|
|
/EHsc
|
2017-06-12 02:18:20 +02:00
|
|
|
/Zc:throwingNew # Assumes new never returns null
|
|
|
|
/Zc:inline # Omits inline functions from object-file output
|
2016-12-19 01:41:21 +01:00
|
|
|
/DNOMINMAX)
|
2016-12-03 17:06:09 +01:00
|
|
|
|
2017-02-04 21:31:10 +01:00
|
|
|
if (DYNARMIC_WARNINGS_AS_ERRORS)
|
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS
|
|
|
|
/WX)
|
|
|
|
endif()
|
|
|
|
|
2016-12-03 17:06:09 +01:00
|
|
|
if (CMAKE_VS_PLATFORM_TOOLSET MATCHES "LLVM-vs[0-9]+")
|
2016-12-19 01:41:21 +01:00
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS
|
|
|
|
-Qunused-arguments
|
2017-06-12 02:17:04 +02:00
|
|
|
-Wno-missing-braces)
|
2016-12-03 17:06:09 +01:00
|
|
|
endif()
|
2016-08-22 15:25:30 +02:00
|
|
|
else()
|
2016-12-19 01:41:21 +01:00
|
|
|
set(DYNARMIC_CXX_FLAGS
|
|
|
|
-Wall
|
|
|
|
-Wextra
|
|
|
|
-Wcast-qual
|
|
|
|
-pedantic
|
|
|
|
-pedantic-errors
|
|
|
|
-Wfatal-errors
|
2017-06-12 02:17:04 +02:00
|
|
|
-Wno-missing-braces)
|
2016-08-22 23:21:00 +02:00
|
|
|
|
2017-02-04 21:31:10 +01:00
|
|
|
if (DYNARMIC_WARNINGS_AS_ERRORS)
|
|
|
|
list(APPEND DYNARMIC_CXX_FLAGS
|
|
|
|
-Werror)
|
|
|
|
endif()
|
2016-07-12 14:25:33 +02:00
|
|
|
endif()
|
2016-07-01 15:01:06 +02:00
|
|
|
|
|
|
|
# Arch detection
|
2016-08-22 15:12:46 +02:00
|
|
|
include(DetectArchitecture)
|
2016-07-01 15:01:06 +02:00
|
|
|
if (MSVC)
|
|
|
|
detect_architecture("_M_AMD64" x86_64)
|
2018-05-09 20:18:23 +02:00
|
|
|
detect_architecture("_M_ARM64" Aarch64)
|
2016-07-01 15:01:06 +02:00
|
|
|
else()
|
|
|
|
detect_architecture("__x86_64__" x86_64)
|
2018-05-09 20:18:23 +02:00
|
|
|
detect_architecture("__aarch64__" Aarch64)
|
2016-07-01 15:01:06 +02:00
|
|
|
endif()
|
|
|
|
if (NOT DEFINED ARCHITECTURE)
|
|
|
|
set(ARCHITECTURE "GENERIC")
|
|
|
|
set(ARCHITECTURE_GENERIC 1)
|
|
|
|
add_definitions(-DARCHITECTURE_GENERIC=1)
|
|
|
|
endif()
|
|
|
|
message(STATUS "Target architecture: ${ARCHITECTURE}")
|
|
|
|
|
|
|
|
# Include Boost
|
2017-12-07 21:28:33 +01:00
|
|
|
if (NOT TARGET boost)
|
|
|
|
if (NOT Boost_INCLUDE_DIRS)
|
|
|
|
find_package(Boost 1.57.0 REQUIRED)
|
2016-07-01 15:01:06 +02:00
|
|
|
endif()
|
2018-02-11 15:57:35 +01:00
|
|
|
add_library(boost INTERFACE)
|
|
|
|
target_include_directories(boost SYSTEM INTERFACE ${Boost_INCLUDE_DIRS})
|
2016-07-01 15:01:06 +02:00
|
|
|
endif()
|
|
|
|
|
2017-02-25 18:31:53 +01:00
|
|
|
# Enable unit-testing.
|
|
|
|
enable_testing(true)
|
2016-07-01 15:01:06 +02:00
|
|
|
|
2016-08-05 02:50:31 +02:00
|
|
|
# Include LLVM
|
|
|
|
if (DYNARMIC_USE_LLVM)
|
|
|
|
find_package(LLVM REQUIRED CONFIG)
|
|
|
|
include_directories(${LLVM_INCLUDE_DIRS})
|
|
|
|
add_definitions(-DDYNARMIC_USE_LLVM ${LLVM_DEFINITIONS})
|
2018-02-18 12:20:43 +01:00
|
|
|
llvm_map_components_to_libnames(llvm_libs aarch64desc aarch64disassembler x86desc x86disassembler)
|
2016-08-05 02:50:31 +02:00
|
|
|
endif()
|
|
|
|
|
2018-01-13 19:04:19 +01:00
|
|
|
if (DYNARMIC_TESTS_USE_UNICORN)
|
2018-01-14 13:58:30 +01:00
|
|
|
find_package(Unicorn REQUIRED)
|
2018-01-13 19:04:19 +01:00
|
|
|
endif()
|
|
|
|
|
2016-08-25 23:21:19 +02:00
|
|
|
# Pull in externals CMakeLists for libs where available
|
|
|
|
add_subdirectory(externals)
|
|
|
|
|
2016-07-01 15:01:06 +02:00
|
|
|
# Dynarmic project files
|
|
|
|
add_subdirectory(src)
|
2016-09-02 13:29:19 +02:00
|
|
|
if (DYNARMIC_TESTS)
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|