2021-01-30 11:55:24 +00:00
|
|
|
cmake_minimum_required(VERSION 3.10)
|
2019-10-04 03:54:09 +00:00
|
|
|
project(duckstation C CXX)
|
2019-09-09 07:01:26 +00:00
|
|
|
|
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}")
|
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/")
|
|
|
|
|
2020-05-07 12:48:13 +00:00
|
|
|
# Platform detection.
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
|
|
|
set(LINUX TRUE)
|
|
|
|
set(SUPPORTS_X11 TRUE)
|
2020-07-07 11:40:55 +00:00
|
|
|
set(SUPPORTS_WAYLAND TRUE)
|
2021-03-07 08:35:46 +00:00
|
|
|
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
|
|
|
|
set(FREEBSD TRUE)
|
|
|
|
set(SUPPORTS_X11 TRUE)
|
2020-05-07 12:48:13 +00:00
|
|
|
endif()
|
|
|
|
|
2020-10-31 04:29:11 +00:00
|
|
|
# Set minimum OS version for macOS. 10.14 should work.
|
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14.0" CACHE STRING "")
|
2020-05-07 12:48:13 +00:00
|
|
|
|
|
|
|
# Global options.
|
2019-12-31 06:17:17 +00:00
|
|
|
if(NOT ANDROID)
|
2021-01-30 11:55:24 +00:00
|
|
|
option(BUILD_NOGUI_FRONTEND "Build the NoGUI frontend" ON)
|
2019-12-31 06:17:17 +00:00
|
|
|
option(BUILD_QT_FRONTEND "Build the Qt frontend" ON)
|
2020-04-30 15:01:53 +00:00
|
|
|
option(ENABLE_DISCORD_PRESENCE "Build with Discord Rich Presence support" ON)
|
2021-02-28 09:04:40 +00:00
|
|
|
option(ENABLE_CHEEVOS "Build with RetroAchievements support" ON)
|
2020-04-07 02:12:26 +00:00
|
|
|
option(USE_SDL2 "Link with SDL2 for controller support" ON)
|
2019-12-31 06:17:17 +00:00
|
|
|
endif()
|
|
|
|
|
2019-11-23 08:55:13 +00:00
|
|
|
|
2020-05-07 12:48:13 +00:00
|
|
|
# OpenGL context creation methods.
|
|
|
|
if(SUPPORTS_X11)
|
|
|
|
option(USE_X11 "Support X11 window system" ON)
|
|
|
|
endif()
|
2020-07-07 11:40:55 +00:00
|
|
|
if(SUPPORTS_WAYLAND)
|
|
|
|
option(USE_WAYLAND "Support Wayland window system" OFF)
|
|
|
|
endif()
|
2021-03-07 08:35:46 +00:00
|
|
|
if((LINUX OR FREEBSD) OR ANDROID)
|
2020-05-07 12:48:13 +00:00
|
|
|
option(USE_EGL "Support EGL OpenGL context creation" ON)
|
|
|
|
endif()
|
2021-03-07 08:35:46 +00:00
|
|
|
if((LINUX OR FREEBSD) AND NOT ANDROID)
|
2021-02-13 16:51:26 +00:00
|
|
|
option(USE_DRMKMS "Support DRM/KMS OpenGL contexts" OFF)
|
|
|
|
option(USE_FBDEV "Support FBDev OpenGL contexts" OFF)
|
2021-02-27 10:53:00 +00:00
|
|
|
option(USE_EVDEV "Support EVDev controller interface" ON)
|
2021-01-30 16:25:05 +00:00
|
|
|
endif()
|
2020-05-07 12:48:13 +00:00
|
|
|
|
2020-09-23 09:48:06 +00:00
|
|
|
# Force EGL when using Wayland
|
|
|
|
if(USE_WAYLAND)
|
|
|
|
set(USE_EGL ON)
|
|
|
|
endif()
|
|
|
|
|
2021-01-07 15:11:19 +00:00
|
|
|
if(ANDROID)
|
2021-01-30 11:55:24 +00:00
|
|
|
if(BUILD_NOGUI_FRONTEND)
|
|
|
|
message(WARNING "Building for Android, disabling NoGUI frontend")
|
2021-02-27 10:53:00 +00:00
|
|
|
set(BUILD_NOGUI_FRONTEND OFF)
|
2021-01-30 11:55:24 +00:00
|
|
|
endif()
|
2020-05-23 07:44:43 +00:00
|
|
|
if(BUILD_QT_FRONTEND)
|
2021-01-10 14:59:00 +00:00
|
|
|
message(WARNING "Building for Android, disabling Qt frontend")
|
2020-05-23 07:44:43 +00:00
|
|
|
set(BUILD_QT_FRONTEND OFF)
|
|
|
|
endif()
|
|
|
|
if(ENABLE_DISCORD_PRESENCE)
|
2021-01-10 14:59:00 +00:00
|
|
|
message("Building for Android, disabling Discord Presence support")
|
2020-05-23 07:44:43 +00:00
|
|
|
set(ENABLE_DISCORD_PRESENCE OFF)
|
|
|
|
endif()
|
|
|
|
if(USE_SDL2)
|
2021-01-10 14:59:00 +00:00
|
|
|
message("Building for Android, disabling SDL2 support")
|
2020-05-23 07:44:43 +00:00
|
|
|
set(USE_SDL2 OFF)
|
|
|
|
endif()
|
|
|
|
if(USE_X11)
|
|
|
|
set(USE_X11 OFF)
|
|
|
|
endif()
|
2020-09-23 09:48:06 +00:00
|
|
|
if(USE_WAYLAND)
|
|
|
|
set(USE_WAYLAND OFF)
|
|
|
|
endif()
|
2021-03-13 11:14:05 +00:00
|
|
|
|
|
|
|
# Cheevos are always on.
|
|
|
|
set(ENABLE_CHEEVOS ON)
|
2020-05-23 07:44:43 +00:00
|
|
|
endif()
|
|
|
|
|
2020-05-07 12:48:13 +00:00
|
|
|
|
2019-09-09 07:01:26 +00:00
|
|
|
# Common include/library directories on Windows.
|
2021-02-27 10:53:00 +00:00
|
|
|
if(WIN32 AND USE_SDL2)
|
2020-02-28 07:00:12 +00:00
|
|
|
set(SDL2_FOUND TRUE)
|
2020-02-15 08:40:21 +00:00
|
|
|
set(SDL2_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/include")
|
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
|
|
|
set(SDL2_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/lib64/SDL2.lib")
|
|
|
|
set(SDL2MAIN_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/lib64/SDL2main.lib")
|
2020-05-16 03:10:31 +00:00
|
|
|
set(SDL2_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/bin64/SDL2.dll")
|
2020-07-27 16:09:58 +00:00
|
|
|
set(Qt5_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/qt/5.15.0/msvc2017_64/lib/cmake/Qt5")
|
2019-09-09 07:01:26 +00:00
|
|
|
else()
|
2020-02-15 08:40:21 +00:00
|
|
|
set(SDL2_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/lib32/SDL2.lib")
|
|
|
|
set(SDL2MAIN_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/lib32/SDL2main.lib")
|
2020-05-16 03:10:31 +00:00
|
|
|
set(SDL2_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/sdl2/bin32/SDL2.dll")
|
2020-07-27 16:09:58 +00:00
|
|
|
set(Qt5_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dep/msvc/qt/5.15.0/msvc2017_32/lib/cmake/Qt5")
|
2019-09-09 07:01:26 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2019-11-23 08:55:13 +00:00
|
|
|
# Required libraries.
|
2019-11-27 15:55:33 +00:00
|
|
|
if(NOT ANDROID)
|
2021-03-25 03:32:27 +00:00
|
|
|
if(NOT WIN32 AND USE_SDL2)
|
2019-12-31 06:17:17 +00:00
|
|
|
find_package(SDL2 REQUIRED)
|
|
|
|
endif()
|
|
|
|
if(BUILD_QT_FRONTEND)
|
2020-07-28 09:16:12 +00:00
|
|
|
find_package(Qt5 COMPONENTS Core Gui Widgets Network LinguistTools REQUIRED)
|
2019-12-31 06:17:17 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-05-07 12:48:13 +00:00
|
|
|
if(USE_EGL)
|
2019-11-28 14:17:24 +00:00
|
|
|
find_package(EGL REQUIRED)
|
2019-11-27 15:55:33 +00:00
|
|
|
endif()
|
2020-05-07 12:48:13 +00:00
|
|
|
if(USE_X11)
|
|
|
|
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()
|
2020-07-07 11:40:55 +00:00
|
|
|
if(USE_WAYLAND)
|
|
|
|
find_package(ECM REQUIRED NO_MODULE)
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${ECM_MODULE_PATH}")
|
|
|
|
find_package(Wayland REQUIRED Egl)
|
|
|
|
message(STATUS "Wayland support enabled")
|
|
|
|
endif()
|
2021-02-13 16:51:26 +00:00
|
|
|
if(USE_DRMKMS AND USE_FBDEV)
|
|
|
|
message(FATAL_ERROR "Only one of DRM/KMS and FBDev can be enabled")
|
|
|
|
endif()
|
2021-01-30 16:25:05 +00:00
|
|
|
if(USE_DRMKMS)
|
|
|
|
find_package(GBM REQUIRED)
|
|
|
|
find_package(Libdrm REQUIRED)
|
|
|
|
message(STATUS "DRM/KMS support enabled")
|
|
|
|
endif()
|
2021-02-13 16:51:26 +00:00
|
|
|
if(USE_FBDEV)
|
|
|
|
message(STATUS "FBDev Support enabled")
|
|
|
|
endif()
|
2021-02-27 10:53:00 +00:00
|
|
|
if(USE_EVDEV)
|
|
|
|
message(STATUS "EVDev Support enabled")
|
|
|
|
find_package(LIBEVDEV REQUIRED)
|
|
|
|
endif()
|
2021-02-28 09:01:16 +00:00
|
|
|
if(ENABLE_CHEEVOS)
|
|
|
|
message(STATUS "RetroAchievements support enabled")
|
2021-03-13 11:14:05 +00:00
|
|
|
if(NOT WIN32 AND NOT ANDROID)
|
2021-02-28 09:01:16 +00:00
|
|
|
find_package(CURL REQUIRED)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
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}}")
|
|
|
|
|
2020-08-14 14:04:38 +00:00
|
|
|
# Enable intrinsic functions, disable minimal rebuild, UTF-8 source.
|
|
|
|
set(${config} "${${config}} /Oi /Gm- /utf-8")
|
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")
|
2020-07-07 08:54:11 +00:00
|
|
|
|
|
|
|
# Enable LTO/LTCG on Release builds.
|
|
|
|
if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
|
2021-01-30 11:55:24 +00:00
|
|
|
cmake_policy(SET CMP0069 NEW)
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
check_ipo_supported(RESULT IPO_IS_SUPPORTED)
|
|
|
|
if(IPO_IS_SUPPORTED)
|
|
|
|
message(STATUS "Enabling LTCG/IPO.")
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
|
2020-09-25 12:00:53 +00:00
|
|
|
else()
|
2021-01-30 11:55:24 +00:00
|
|
|
message(WARNING "LTCG/IPO is not supported, this will make the build slightly slower.")
|
2020-09-25 12:00:53 +00:00
|
|
|
endif()
|
2020-07-07 08:54:11 +00:00
|
|
|
endif()
|
2019-09-09 07:01:26 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
# Detect C++ version support.
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
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.
|
|
|
|
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
|
|
|
|
set(CPU_ARCH "x64")
|
|
|
|
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
|
|
|
|
# MSVC x86/x64
|
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
|
|
|
set(CPU_ARCH "x64")
|
|
|
|
else()
|
|
|
|
set(CPU_ARCH "x86")
|
|
|
|
endif()
|
|
|
|
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386" OR
|
|
|
|
${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
|
|
|
|
set(CPU_ARCH "x86")
|
|
|
|
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
|
|
|
|
set(CPU_ARCH "aarch64")
|
2020-11-20 15:52:13 +00:00
|
|
|
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l")
|
|
|
|
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()
|
2019-09-09 07:01:26 +00:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unknown system processor: " ${CMAKE_SYSTEM_PROCESSOR})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2020-05-16 03:10:31 +00:00
|
|
|
# Write binaries to a seperate directory.
|
2021-01-07 15:11:19 +00:00
|
|
|
if(WIN32)
|
2020-07-07 08:37:03 +00:00
|
|
|
# For Windows, use the source directory, except for libretro.
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
# Recursively include the source tree.
|
|
|
|
enable_testing()
|
|
|
|
add_subdirectory(dep)
|
|
|
|
add_subdirectory(src)
|
2019-11-27 15:55:33 +00:00
|
|
|
|
2021-01-07 15:11:19 +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()
|