2022-08-24 09:12:38 +00:00
|
|
|
cmake_minimum_required(VERSION 3.16)
|
2019-10-04 03:54:09 +00:00
|
|
|
project(duckstation C CXX)
|
2019-09-09 07:01:26 +00:00
|
|
|
|
2023-01-30 13:21:52 +00:00
|
|
|
# Policy settings.
|
|
|
|
cmake_policy(SET CMP0069 NEW)
|
|
|
|
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
|
|
|
|
|
2020-07-13 15:26:43 +00:00
|
|
|
message("CMake Version: ${CMAKE_VERSION}")
|
2021-03-07 08:35:46 +00:00
|
|
|
message("CMake System Name: ${CMAKE_SYSTEM_NAME}")
|
2022-08-22 09:32:15 +00:00
|
|
|
message("Build Type: ${CMAKE_BUILD_TYPE}")
|
2020-07-12 16:57:04 +00:00
|
|
|
|
2019-11-23 08:55:13 +00:00
|
|
|
# Pull in modules.
|
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules/")
|
2023-09-30 05:39:52 +00:00
|
|
|
include(DuckStationUtils)
|
2019-11-23 08:55:13 +00:00
|
|
|
|
2020-05-07 12:48:13 +00:00
|
|
|
# Platform detection.
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
|
|
|
set(LINUX TRUE)
|
2021-03-07 08:35:46 +00:00
|
|
|
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
|
|
|
|
set(FREEBSD TRUE)
|
2020-05-07 12:48:13 +00:00
|
|
|
endif()
|
|
|
|
|
2023-09-16 04:39:13 +00:00
|
|
|
# Renderer options.
|
2023-09-02 05:34:03 +00:00
|
|
|
option(ENABLE_OPENGL "Build with OpenGL renderer" ON)
|
|
|
|
option(ENABLE_VULKAN "Build with Vulkan renderer" ON)
|
2020-05-07 12:48:13 +00:00
|
|
|
|
2023-09-16 04:39:13 +00:00
|
|
|
# Global options.
|
|
|
|
if(NOT ANDROID)
|
|
|
|
option(BUILD_NOGUI_FRONTEND "Build the NoGUI frontend" OFF)
|
|
|
|
option(BUILD_QT_FRONTEND "Build the Qt frontend" ON)
|
|
|
|
option(BUILD_REGTEST "Build regression test runner" OFF)
|
|
|
|
option(BUILD_TESTS "Build unit tests" OFF)
|
|
|
|
|
|
|
|
set(ENABLE_CUBEB ON)
|
|
|
|
set(ENABLE_DISCORD_PRESENCE ON)
|
2023-09-17 02:28:11 +00:00
|
|
|
set(ENABLE_SDL2 ON)
|
2023-09-16 04:39:13 +00:00
|
|
|
|
|
|
|
if(LINUX OR FREEBSD)
|
2023-09-17 02:28:11 +00:00
|
|
|
option(ENABLE_X11 "Support X11 window system" ON)
|
|
|
|
option(ENABLE_WAYLAND "Support Wayland window system" ON)
|
2023-09-16 04:39:13 +00:00
|
|
|
endif()
|
|
|
|
if(APPLE)
|
|
|
|
option(SKIP_POSTPROCESS_BUNDLE "Disable bundle post-processing, including Qt additions" OFF)
|
2022-09-22 13:11:11 +00:00
|
|
|
endif()
|
2019-09-09 07:01:26 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2019-11-23 08:55:13 +00:00
|
|
|
# Required libraries.
|
2023-09-17 02:28:11 +00:00
|
|
|
if(ENABLE_SDL2)
|
2023-09-02 05:34:03 +00:00
|
|
|
find_package(SDL2 2.28.2 REQUIRED)
|
|
|
|
endif()
|
|
|
|
if(NOT WIN32 AND NOT ANDROID)
|
|
|
|
find_package(CURL REQUIRED)
|
2023-09-16 04:39:13 +00:00
|
|
|
if(NOT APPLE)
|
|
|
|
find_package(Libbacktrace)
|
|
|
|
if(NOT LIBBACKTRACE_FOUND)
|
|
|
|
message(WARNING "libbacktrace not found, crashes will not produce backtraces.")
|
|
|
|
endif()
|
2023-09-05 10:33:54 +00:00
|
|
|
endif()
|
2019-12-31 06:17:17 +00:00
|
|
|
endif()
|
2023-09-02 05:34:03 +00:00
|
|
|
if(BUILD_QT_FRONTEND)
|
2023-09-02 06:54:51 +00:00
|
|
|
find_package(Qt6 6.5.1 COMPONENTS Core Gui Widgets Network LinguistTools REQUIRED)
|
2023-09-02 05:34:03 +00:00
|
|
|
endif()
|
|
|
|
|
2019-12-31 06:17:17 +00:00
|
|
|
|
2023-09-05 10:35:38 +00:00
|
|
|
# Everything except Windows/Mac use EGL.
|
|
|
|
if(ENABLE_OPENGL AND (LINUX OR FREEBSD OR ANDROID))
|
2019-11-28 14:17:24 +00:00
|
|
|
find_package(EGL REQUIRED)
|
2023-09-17 02:28:11 +00:00
|
|
|
set(ENABLE_EGL TRUE)
|
2019-11-27 15:55:33 +00:00
|
|
|
endif()
|
2023-09-05 10:35:38 +00:00
|
|
|
|
|
|
|
|
2023-09-17 02:28:11 +00:00
|
|
|
if(ENABLE_X11)
|
2020-05-07 12:48:13 +00:00
|
|
|
find_package(X11 REQUIRED)
|
2021-04-02 14:55:09 +00:00
|
|
|
if (NOT X11_Xrandr_FOUND)
|
|
|
|
message(FATAL_ERROR "XRandR extension is required")
|
|
|
|
endif()
|
2020-05-07 12:48:13 +00:00
|
|
|
endif()
|
2023-09-17 02:28:11 +00:00
|
|
|
if(ENABLE_WAYLAND)
|
2020-07-07 11:40:55 +00:00
|
|
|
message(STATUS "Wayland support enabled")
|
|
|
|
endif()
|
2021-02-28 09:01:16 +00:00
|
|
|
|
2019-11-23 08:55:13 +00:00
|
|
|
|
2019-09-09 07:01:26 +00:00
|
|
|
# Set _DEBUG macro for Debug builds.
|
|
|
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
|
|
|
|
|
|
|
|
|
|
|
|
# Release build optimizations for MSVC.
|
|
|
|
if(MSVC)
|
|
|
|
add_definitions("/D_CRT_SECURE_NO_WARNINGS")
|
|
|
|
foreach(config CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
|
|
# Set warning level 3 instead of 4.
|
|
|
|
string(REPLACE "/W3" "/W4" ${config} "${${config}}")
|
|
|
|
|
2021-05-10 03:59:52 +00:00
|
|
|
# Enable intrinsic functions, disable minimal rebuild, UTF-8 source, set __cplusplus version.
|
|
|
|
set(${config} "${${config}} /Oi /Gm- /utf-8 /Zc:__cplusplus")
|
2019-09-09 07:01:26 +00:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# RelWithDebInfo is set to Ob1 instead of Ob2.
|
|
|
|
string(REPLACE "/Ob1" "/Ob2" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
|
|
|
|
string(REPLACE "/Ob1" "/Ob2" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
|
|
|
|
|
|
|
|
# Disable incremental linking in RelWithDebInfo.
|
|
|
|
string(REPLACE "/INCREMENTAL" "/INCREMENTAL:NO" CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
|
|
|
|
|
|
|
|
# COMDAT folding/remove unused functions.
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /OPT:REF /OPT:ICF")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF /OPT:ICF")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2021-06-04 03:14:22 +00:00
|
|
|
# Default symbol visibility to hidden, that way we don't go through the PLT for intra-library calls.
|
2022-03-27 07:16:21 +00:00
|
|
|
if(ANDROID)
|
2023-01-30 13:21:52 +00:00
|
|
|
cmake_policy(SET CMP0063 NEW)
|
|
|
|
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)
|
2021-06-04 06:49:27 +00:00
|
|
|
set(CMAKE_C_VISIBILITY_PRESET hidden)
|
|
|
|
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
2023-01-30 13:21:52 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-semantic-interposition")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-semantic-interposition")
|
2021-06-04 03:14:22 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2023-09-05 10:57:18 +00:00
|
|
|
# Warning disables.
|
2019-09-09 07:01:26 +00:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2020-02-12 19:20:11 +00:00
|
|
|
include(CheckCXXFlag)
|
|
|
|
check_cxx_flag(-Wall COMPILER_SUPPORTS_WALL)
|
2019-09-09 07:01:26 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch")
|
2019-11-27 15:55:33 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch")
|
|
|
|
if(NOT ANDROID)
|
2020-02-12 19:20:11 +00:00
|
|
|
check_cxx_flag(-Wno-class-memaccess COMPILER_SUPPORTS_MEMACCESS)
|
|
|
|
check_cxx_flag(-Wno-invalid-offsetof COMPILER_SUPPORTS_OFFSETOF)
|
2019-11-27 15:55:33 +00:00
|
|
|
endif()
|
2019-09-09 07:01:26 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
# Detect processor type.
|
2022-07-31 06:39:09 +00:00
|
|
|
if("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64")
|
|
|
|
# Cross-compile on macos.
|
|
|
|
set(CPU_ARCH "aarch64")
|
|
|
|
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64" OR
|
|
|
|
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
|
2019-09-09 07:01:26 +00:00
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
|
|
|
set(CPU_ARCH "x64")
|
|
|
|
else()
|
2021-05-26 03:25:13 +00:00
|
|
|
# Cross-compiling 32-bit build. 32-bit hosts are not supported.
|
2019-09-09 07:01:26 +00:00
|
|
|
set(CPU_ARCH "x86")
|
|
|
|
endif()
|
2022-07-31 06:39:09 +00:00
|
|
|
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386" OR
|
|
|
|
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
|
2019-09-09 07:01:26 +00:00
|
|
|
set(CPU_ARCH "x86")
|
2022-07-31 06:39:09 +00:00
|
|
|
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
|
2023-10-02 11:34:34 +00:00
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # Might have an A64 kernel, e.g. Raspbian.
|
|
|
|
set(CPU_ARCH "aarch64")
|
|
|
|
else()
|
|
|
|
set(CPU_ARCH "aarch32")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm -march=armv7-a")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm -march=armv7-a")
|
|
|
|
endif()
|
2022-07-31 06:39:09 +00:00
|
|
|
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a" OR
|
|
|
|
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
|
2020-11-20 15:52:13 +00:00
|
|
|
set(CPU_ARCH "aarch32")
|
2020-11-21 12:44:35 +00:00
|
|
|
if(ANDROID)
|
|
|
|
# Force ARM mode, since apparently ANDROID_ARM_MODE isn't working..
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm")
|
|
|
|
else()
|
|
|
|
# Enable NEON.
|
2020-11-22 03:57:05 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm -march=armv7-a")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm -march=armv7-a")
|
2020-11-21 12:44:35 +00:00
|
|
|
endif()
|
2023-08-15 13:12:21 +00:00
|
|
|
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "riscv64")
|
|
|
|
set(CPU_ARCH "riscv64")
|
2023-10-03 14:39:18 +00:00
|
|
|
|
|
|
|
# Not done for us. Or we should inline atomics?
|
|
|
|
link_libraries("-latomic")
|
2019-09-09 07:01:26 +00:00
|
|
|
else()
|
2022-07-31 06:39:09 +00:00
|
|
|
message(FATAL_ERROR "Unknown system processor: ${CMAKE_SYSTEM_PROCESSOR}")
|
2019-09-09 07:01:26 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2023-01-30 13:21:52 +00:00
|
|
|
# We don't need exceptions, disable them to save a bit of code size.
|
2023-09-02 03:41:41 +00:00
|
|
|
if(MSVC)
|
|
|
|
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
string(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
2023-01-30 13:21:52 +00:00
|
|
|
|
2023-09-02 03:41:41 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_HAS_EXCEPTIONS=0 /permissive-")
|
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
|
|
|
|
endif()
|
2023-01-30 13:21:52 +00:00
|
|
|
|
2023-09-23 12:19:11 +00:00
|
|
|
|
2020-05-16 03:10:31 +00:00
|
|
|
# Write binaries to a seperate directory.
|
2022-03-27 07:16:21 +00:00
|
|
|
if(WIN32)
|
2020-05-16 03:10:31 +00:00
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/${CPU_ARCH}")
|
|
|
|
else()
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
|
|
|
|
endif()
|
|
|
|
|
2020-07-05 02:58:04 +00:00
|
|
|
# Needed for Linux - put shared libraries in the binary directory.
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
|
|
|
|
|
2020-05-16 03:10:31 +00:00
|
|
|
|
2019-09-09 07:01:26 +00:00
|
|
|
# Enable threads everywhere.
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
|
|
|
|
2021-04-07 08:28:06 +00:00
|
|
|
# Enable large file support on Linux 32-bit platforms.
|
|
|
|
# Android is deliberately ommitted here as it didn't support 64-bit ops on files until Android 7/N.
|
|
|
|
if((LINUX OR FREEBSD) AND (${CPU_ARCH} STREQUAL "x86" OR ${CPU_ARCH} STREQUAL "aarch32"))
|
|
|
|
add_definitions("-D_FILE_OFFSET_BITS=64")
|
|
|
|
endif()
|
|
|
|
|
2023-09-02 06:54:51 +00:00
|
|
|
if(BUILD_TESTS)
|
|
|
|
enable_testing()
|
|
|
|
endif()
|
2021-04-07 08:28:06 +00:00
|
|
|
|
2023-09-23 12:19:11 +00:00
|
|
|
# Prevent fmt from being built with exceptions, or being thrown at call sites.
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFMT_EXCEPTIONS=0")
|
|
|
|
|
2023-09-05 10:57:18 +00:00
|
|
|
# Use C++17 for building dependencies (some aren't C++20-aware, e.g. reshadefx).
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
2019-09-09 07:01:26 +00:00
|
|
|
# Recursively include the source tree.
|
|
|
|
add_subdirectory(dep)
|
2023-09-05 10:57:18 +00:00
|
|
|
|
|
|
|
# Use C++20 for building the main libraries.
|
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
2019-09-09 07:01:26 +00:00
|
|
|
add_subdirectory(src)
|
2019-11-27 15:55:33 +00:00
|
|
|
|
2022-03-27 07:16:21 +00:00
|
|
|
if(ANDROID)
|
2019-11-27 15:55:33 +00:00
|
|
|
add_subdirectory(android/app/src/cpp)
|
2019-12-31 06:17:17 +00:00
|
|
|
endif()
|