CMake: Tidy up build system

And fix Windows CMake... who knows how long for.
This commit is contained in:
Stenzek 2024-04-20 20:26:53 +10:00
parent a88ee93b4d
commit 8867bb129a
No known key found for this signature in database
14 changed files with 288 additions and 253 deletions

View file

@ -5,6 +5,17 @@ project(duckstation C CXX)
cmake_policy(SET CMP0069 NEW) cmake_policy(SET CMP0069 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "DuckStation does not support in-tree builds. Please make a build directory that is not the source"
"directory and generate your CMake project there using either `cmake -B build_directory` or by "
"running cmake from the build directory.")
endif()
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug|Devel|MinSizeRel|RelWithDebInfo|Release")
message(STATUS "CMAKE_BUILD_TYPE not set, defaulting to Release.")
set(CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "CMake Version: ${CMAKE_VERSION}") message(STATUS "CMake Version: ${CMAKE_VERSION}")
message(STATUS "CMake System Name: ${CMAKE_SYSTEM_NAME}") message(STATUS "CMake System Name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}") message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
@ -13,58 +24,19 @@ message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules/") set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules/")
include(DuckStationUtils) include(DuckStationUtils)
# Platform detection. # Detect system attributes.
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") detect_operating_system()
set(LINUX TRUE) detect_compiler()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") detect_architecture()
set(FREEBSD TRUE) detect_page_size()
endif()
# Renderer options.
option(ENABLE_OPENGL "Build with OpenGL renderer" ON)
option(ENABLE_VULKAN "Build with Vulkan renderer" ON)
# 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)
set(ENABLE_SDL2 ON)
if(LINUX OR FREEBSD)
option(ENABLE_X11 "Support X11 window system" ON)
option(ENABLE_WAYLAND "Support Wayland window system" ON)
endif()
if(APPLE)
option(SKIP_POSTPROCESS_BUNDLE "Disable bundle post-processing, including Qt additions" OFF)
endif()
endif()
# Everything except Windows/Mac use EGL.
if(ENABLE_OPENGL AND (LINUX OR FREEBSD OR ANDROID))
set(ENABLE_EGL TRUE)
endif()
if(ENABLE_X11)
find_package(X11 REQUIRED)
if (NOT X11_Xrandr_FOUND)
message(FATAL_ERROR "XRandR extension is required")
endif()
endif()
if(ENABLE_WAYLAND)
message(STATUS "Wayland support enabled")
endif()
# Build options. Depends on system attributes.
include(DuckStationBuildOptions)
# Set _DEBUG macro for Debug builds. # Set _DEBUG macro for Debug builds.
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
# Release build optimizations for MSVC. # Release build optimizations for MSVC.
if(MSVC) if(MSVC)
add_definitions("/D_CRT_SECURE_NO_WARNINGS") add_definitions("/D_CRT_SECURE_NO_WARNINGS")
@ -88,101 +60,16 @@ if(MSVC)
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF /OPT:ICF") set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF /OPT:ICF")
endif() endif()
# Default symbol visibility to hidden, that way we don't go through the PLT for intra-library calls.
if(ANDROID)
cmake_policy(SET CMP0063 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-semantic-interposition")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-semantic-interposition")
endif()
# Warning disables. # Warning disables.
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(COMPILER_CLANG OR COMPILER_CLANG_CL OR COMPILER_GCC)
include(CheckCXXFlag) include(CheckCXXFlag)
check_cxx_flag(-Wall COMPILER_SUPPORTS_WALL) check_cxx_flag(-Wall COMPILER_SUPPORTS_WALL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch") check_cxx_flag(-Wno-class-memaccess COMPILER_SUPPORTS_MEMACCESS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch") check_cxx_flag(-Wno-invalid-offsetof COMPILER_SUPPORTS_OFFSETOF)
if(NOT ANDROID) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch")
check_cxx_flag(-Wno-class-memaccess COMPILER_SUPPORTS_MEMACCESS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch")
check_cxx_flag(-Wno-invalid-offsetof COMPILER_SUPPORTS_OFFSETOF)
endif()
endif() endif()
# Detect processor type.
if(APPLE AND NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
# Universal binaries.
if("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES)
set(CPU_ARCH_X64 TRUE)
message(STATUS "Building x86_64 MacOS binaries.")
endif()
if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
set(CPU_ARCH_ARM64 TRUE)
message(STATUS "Building ARM64 MacOS binaries.")
endif()
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64" OR
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CPU_ARCH_X64 TRUE)
message(STATUS "Building x86_64 binaries.")
else()
# Cross-compiling 32-bit build. 32-bit hosts are not supported.
set(CPU_ARCH_X86 TRUE)
message(FATAL_ERROR "Building x86_32 binaries is not supported.")
endif()
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386" OR
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
set(CPU_ARCH_X86 TRUE)
message(FATAL_ERROR "Building x86_32 binaries is not supported.")
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # Might have an A64 kernel, e.g. Raspbian.
set(CPU_ARCH_ARM64 TRUE)
message(STATUS "Building ARM64 binaries.")
else()
set(CPU_ARCH_ARM32 TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm -march=armv7-a")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm -march=armv7-a")
message(STATUS "Building ARM32 binaries on ARM64.")
endif()
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a" OR
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
set(CPU_ARCH_ARM32 TRUE)
message(STATUS "Building ARM32 binaries.")
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.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm -march=armv7-a")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm -march=armv7-a")
endif()
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "riscv64")
set(CPU_ARCH_RISCV64 TRUE)
message(STATUS "Building RISC-V 64 binaries.")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finline-atomics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finline-atomics")
# Still need this, apparently.
link_libraries("-latomic")
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
# Frame pointers generate an annoying amount of code on leaf functions.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer")
endif()
else()
message(FATAL_ERROR "Unknown system processor: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
# Detect page size if needed.
detect_page_size()
# We don't need exceptions, disable them to save a bit of code size. # We don't need exceptions, disable them to save a bit of code size.
if(MSVC) if(MSVC)
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
@ -193,29 +80,15 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
endif() endif()
# Write binaries to a seperate directory. # Write binaries to a seperate directory.
if(WIN32) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/${CPU_ARCH}")
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
endif()
# Needed for Linux - put shared libraries in the binary directory.
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
# Enable threads everywhere.
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Enable large file support on Linux 32-bit platforms. # 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(CMAKE_SIZEOF_VOID_P EQUAL 4)
if((LINUX OR FREEBSD) AND (CPU_ARCH_X86 OR CPU_ARCH_ARM32))
add_definitions("-D_FILE_OFFSET_BITS=64") add_definitions("-D_FILE_OFFSET_BITS=64")
endif() endif()
# Optional unit tests.
if(BUILD_TESTS) if(BUILD_TESTS)
enable_testing() enable_testing()
endif() endif()
@ -232,6 +105,5 @@ include(DuckStationDependencies)
add_subdirectory(dep) add_subdirectory(dep)
add_subdirectory(src) add_subdirectory(src)
if(ANDROID) # Output build summary.
add_subdirectory(android/app/src/cpp) include(DuckStationBuildSummary)
endif()

View file

@ -0,0 +1,15 @@
# Renderer options.
option(ENABLE_OPENGL "Build with OpenGL renderer" ON)
option(ENABLE_VULKAN "Build with Vulkan renderer" ON)
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)
if(LINUX OR BSD)
option(ENABLE_X11 "Support X11 window system" ON)
option(ENABLE_WAYLAND "Support Wayland window system" ON)
endif()
if(APPLE)
option(SKIP_POSTPROCESS_BUNDLE "Disable bundle post-processing, including Qt additions" OFF)
endif()

View file

@ -0,0 +1,45 @@
if(ENABLE_OPENGL)
message(STATUS "Building with OpenGL support.")
endif()
if(ENABLE_VULKAN)
message(STATUS "Building with Vulkan support.")
endif()
if(ENABLE_X11)
message(STATUS "Building with X11 support.")
endif()
if(ENABLE_WAYLAND)
message(STATUS "Building with Wayland support.")
endif()
if(BUILD_QT_FRONTEND)
message(STATUS "Building Qt frontend.")
endif()
if(BUILD_NOGUI_FRONTEND)
message(STATUS "Building NoGUI frontend.")
endif()
if(BUILD_REGTEST)
message(STATUS "Building RegTest frontend.")
endif()
if(BUILD_TESTS)
message(STATUS "Building unit tests.")
endif()
if(NOT IS_SUPPORTED_COMPILER)
message(WARNING "
*************** UNSUPPORTED CONFIGURATION ***************
You are not compiling DuckStation with a supported compiler.
It may not even build successfully.
DuckStation only supports the Clang and MSVC compilers.
No support will be provided, continue at your own risk.
*********************************************************")
endif()
if(WIN32)
message(WARNING "
*************** UNSUPPORTED CONFIGURATION ***************
You are compiling DuckStation with CMake on Windows.
It may not even build successfully.
DuckStation only supports MSBuild on Windows.
No support will be provided, continue at your own risk.
*********************************************************")
endif()

View file

@ -1,39 +1,53 @@
if(ENABLE_SDL2) # From PCSX2: On macOS, Mono.framework contains an ancient version of libpng. We don't want that.
find_package(SDL2 2.30.2 REQUIRED) # Avoid it by telling cmake to avoid finding frameworks while we search for libpng.
if(APPLE)
set(FIND_FRAMEWORK_BACKUP ${CMAKE_FIND_FRAMEWORK})
set(CMAKE_FIND_FRAMEWORK NEVER)
endif() endif()
if(NOT WIN32 AND NOT ANDROID)
# From PCSX2: On macOS, Mono.framework contains an ancient version of libpng. We don't want that.
# Avoid it by telling cmake to avoid finding frameworks while we search for libpng.
if(APPLE)
set(FIND_FRAMEWORK_BACKUP ${CMAKE_FIND_FRAMEWORK})
set(CMAKE_FIND_FRAMEWORK NEVER)
endif()
find_package(Zstd 1.5.5 REQUIRED) # Enable threads everywhere.
find_package(WebP REQUIRED) # v1.3.2, spews an error on Linux because no pkg-config. set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(ZLIB REQUIRED) # 1.3, but Mac currently doesn't use it. find_package(Threads REQUIRED)
find_package(PNG 1.6.40 REQUIRED)
find_package(JPEG REQUIRED) # No version because flatpak uses libjpeg-turbo. find_package(SDL2 2.30.2 REQUIRED)
find_package(Zstd 1.5.5 REQUIRED)
find_package(WebP REQUIRED) # v1.3.2, spews an error on Linux because no pkg-config.
find_package(ZLIB REQUIRED) # 1.3, but Mac currently doesn't use it.
find_package(PNG 1.6.40 REQUIRED)
find_package(JPEG REQUIRED) # No version because flatpak uses libjpeg-turbo.
find_package(Freetype 2.13.1 REQUIRED)
if(NOT WIN32)
find_package(CURL REQUIRED) find_package(CURL REQUIRED)
find_package(Freetype 2.13.1 REQUIRED) endif()
if(ENABLE_VULKAN OR APPLE) if(ENABLE_X11)
find_package(Shaderc REQUIRED) find_package(X11 REQUIRED)
endif() if (NOT X11_Xrandr_FOUND)
message(FATAL_ERROR "XRandR extension is required")
if(APPLE)
# SPIRV-Cross is currently only used on MacOS.
find_package(spirv_cross_c_shared REQUIRED)
set(CMAKE_FIND_FRAMEWORK ${FIND_FRAMEWORK_BACKUP})
endif() endif()
endif() endif()
if(LINUX AND NOT ANDROID)
if(ENABLE_VULKAN OR APPLE)
find_package(Shaderc REQUIRED)
endif()
if(APPLE)
# SPIRV-Cross is currently only used on MacOS.
find_package(spirv_cross_c_shared REQUIRED)
endif()
if(LINUX)
find_package(UDEV REQUIRED) find_package(UDEV REQUIRED)
endif() endif()
if(UNIX AND NOT APPLE)
if(NOT WIN32 AND NOT APPLE)
find_package(Libbacktrace) find_package(Libbacktrace)
if(NOT LIBBACKTRACE_FOUND) if(NOT LIBBACKTRACE_FOUND)
message(WARNING "libbacktrace not found, crashes will not produce backtraces.") message(WARNING "libbacktrace not found, crashes will not produce backtraces.")
endif() endif()
endif() endif()
if(APPLE)
set(CMAKE_FIND_FRAMEWORK ${FIND_FRAMEWORK_BACKUP})
endif()

View file

@ -6,13 +6,105 @@ function(disable_compiler_warnings_for_target target)
endif() endif()
endfunction() endfunction()
function(detect_operating_system)
message(STATUS "CMake Version: ${CMAKE_VERSION}")
message(STATUS "CMake System Name: ${CMAKE_SYSTEM_NAME}")
# LINUX wasn't added until CMake 3.25.
if (CMAKE_VERSION VERSION_LESS 3.25.0 AND CMAKE_SYSTEM_NAME MATCHES "Linux")
# Have to make it visible in this scope as well for below.
set(LINUX TRUE PARENT_SCOPE)
set(LINUX TRUE)
endif()
if(WIN32)
message(STATUS "Building for Windows.")
elseif(APPLE AND NOT IOS)
message(STATUS "Building for MacOS.")
elseif(LINUX)
message(STATUS "Building for Linux.")
elseif(BSD)
message(STATUS "Building for *BSD.")
else()
message(FATAL_ERROR "Unsupported platform.")
endif()
endfunction()
function(detect_compiler)
if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(COMPILER_CLANG_CL TRUE PARENT_SCOPE)
set(IS_SUPPORTED_COMPILER TRUE PARENT_SCOPE)
message(STATUS "Building with Clang-CL.")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(COMPILER_CLANG TRUE PARENT_SCOPE)
set(IS_SUPPORTED_COMPILER TRUE PARENT_SCOPE)
message(STATUS "Building with Clang/LLVM.")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(COMPILER_GCC TRUE PARENT_SCOPE)
set(IS_SUPPORTED_COMPILER FALSE PARENT_SCOPE)
message(STATUS "Building with GNU GCC.")
elseif(MSVC)
set(IS_SUPPORTED_COMPILER TRUE PARENT_SCOPE)
message(STATUS "Building with MSVC.")
else()
message(FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
endfunction()
function(detect_architecture)
if(APPLE AND NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
# Universal binaries.
if("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES)
message(STATUS "Building x86_64 MacOS binaries.")
set(CPU_ARCH_X64 TRUE PARENT_SCOPE)
endif()
if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
message(STATUS "Building ARM64 MacOS binaries.")
set(CPU_ARCH_ARM64 TRUE PARENT_SCOPE)
endif()
elseif(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64" OR
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64") AND
CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "Building x86_64 binaries.")
set(CPU_ARCH_X64 TRUE PARENT_SCOPE)
elseif(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64") AND
CMAKE_SIZEOF_VOID_P EQUAL 8) # Might have an A64 kernel, e.g. Raspbian.
message(STATUS "Building ARM64 binaries.")
set(CPU_ARCH_ARM64 TRUE PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a" OR
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l" OR
(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
AND CMAKE_SIZEOF_VOID_P EQUAL 4))
message(STATUS "Building ARM32 binaries.")
set(CPU_ARCH_ARM32 TRUE PARENT_SCOPE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm -march=armv7-a" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -marm -march=armv7-a" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "riscv64")
message(STATUS "Building RISC-V 64 binaries.")
set(CPU_ARCH_RISCV64 TRUE PARENT_SCOPE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finline-atomics" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finline-atomics" PARENT_SCOPE)
# Still need this, apparently.
link_libraries("-latomic")
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
# Frame pointers generate an annoying amount of code on leaf functions.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer" PARENT_SCOPE)
endif()
else()
message(FATAL_ERROR "Unknown system processor: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
endfunction()
function(detect_page_size) function(detect_page_size)
# This is only needed for ARM64, or if the user hasn't overridden it explicitly. # This is only needed for ARM64, or if the user hasn't overridden it explicitly.
if(NOT CPU_ARCH_ARM64 OR HOST_PAGE_SIZE) if(NOT CPU_ARCH_ARM64 OR HOST_PAGE_SIZE)
return() return()
endif() endif()
if(NOT LINUX OR ANDROID) if(NOT LINUX)
# For universal Apple builds, we use preprocessor macros to determine page size. # For universal Apple builds, we use preprocessor macros to determine page size.
# Similar for Windows, except it's always 4KB. # Similar for Windows, except it's always 4KB.
return() return()

View file

@ -27,23 +27,17 @@ add_subdirectory(rcheevos EXCLUDE_FROM_ALL)
disable_compiler_warnings_for_target(rcheevos) disable_compiler_warnings_for_target(rcheevos)
add_subdirectory(rapidyaml EXCLUDE_FROM_ALL) add_subdirectory(rapidyaml EXCLUDE_FROM_ALL)
disable_compiler_warnings_for_target(rapidyaml) disable_compiler_warnings_for_target(rapidyaml)
add_subdirectory(cubeb EXCLUDE_FROM_ALL)
if(ENABLE_CUBEB) disable_compiler_warnings_for_target(cubeb)
add_subdirectory(cubeb EXCLUDE_FROM_ALL) disable_compiler_warnings_for_target(speex)
disable_compiler_warnings_for_target(cubeb) add_subdirectory(discord-rpc EXCLUDE_FROM_ALL)
disable_compiler_warnings_for_target(speex) disable_compiler_warnings_for_target(discord-rpc)
endif()
if(ENABLE_OPENGL) if(ENABLE_OPENGL)
add_subdirectory(glad EXCLUDE_FROM_ALL) add_subdirectory(glad EXCLUDE_FROM_ALL)
disable_compiler_warnings_for_target(glad) disable_compiler_warnings_for_target(glad)
endif() endif()
if(ENABLE_DISCORD_PRESENCE)
add_subdirectory(discord-rpc EXCLUDE_FROM_ALL)
disable_compiler_warnings_for_target(discord-rpc)
endif()
if(CPU_ARCH_X64) if(CPU_ARCH_X64)
add_subdirectory(xbyak EXCLUDE_FROM_ALL) add_subdirectory(xbyak EXCLUDE_FROM_ALL)
add_subdirectory(zydis EXCLUDE_FROM_ALL) add_subdirectory(zydis EXCLUDE_FROM_ALL)

View file

@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.1 FATAL_ERROR) CMAKE_MINIMUM_REQUIRED(VERSION 3.5 FATAL_ERROR)
# ---[ Project and semantic versioning. # ---[ Project and semantic versioning.
PROJECT(clog C CXX) PROJECT(clog C CXX)

View file

@ -20,11 +20,9 @@ if(WIN32)
src/wgl.c src/wgl.c
) )
else() else()
if(ENABLE_EGL) target_sources(glad PRIVATE
target_sources(glad PRIVATE include/EGL/eglplatform.h
include/EGL/eglplatform.h include/glad/egl.h
include/glad/egl.h src/egl.c
src/egl.c )
)
endif()
endif() endif()

View file

@ -27,6 +27,4 @@ target_include_directories(reshadefx INTERFACE
) )
# reshadefx is not C++20-compatible. # reshadefx is not C++20-compatible.
set(CMAKE_CXX_STANDARD 17) set_property(TARGET reshadefx PROPERTY CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

View file

@ -1,13 +1,15 @@
add_library(WinPixEventRuntime::WinPixEventRuntime UNKNOWN IMPORTED GLOBAL) add_library(WinPixEventRuntime::WinPixEventRuntime SHARED IMPORTED GLOBAL)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64") if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
set_target_properties(WinPixEventRuntime::WinPixEventRuntime PROPERTIES set_target_properties(WinPixEventRuntime::WinPixEventRuntime PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/libarm64/WinPixEventRuntime.lib" IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/binarm64/WinPixEventRuntime.dll"
IMPORTED_IMPLIB "${CMAKE_CURRENT_SOURCE_DIR}/libarm64/WinPixEventRuntime.lib"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include" INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include"
) )
else() else()
set_target_properties(WinPixEventRuntime::WinPixEventRuntime PROPERTIES set_target_properties(WinPixEventRuntime::WinPixEventRuntime PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lib64/WinPixEventRuntime.lib" IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/bin64/WinPixEventRuntime.dll"
IMPORTED_IMPLIB "${CMAKE_CURRENT_SOURCE_DIR}/lib64/WinPixEventRuntime.lib"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include" INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include"
) )
endif() endif()

View file

@ -24,6 +24,7 @@
{ {
"name": "duckstation", "name": "duckstation",
"buildsystem": "cmake-ninja", "buildsystem": "cmake-ninja",
"builddir": true,
"no-make-install": true, "no-make-install": true,
"build-options": { "build-options": {
"strip": false, "strip": false,
@ -48,10 +49,10 @@
} }
], ],
"post-install": [ "post-install": [
"cp -a \"${FLATPAK_BUILDER_BUILDDIR}/bin\" ${FLATPAK_DEST}", "cp -a bin \"${FLATPAK_DEST}\"",
"install -Dm644 scripts/org.duckstation.DuckStation.png ${FLATPAK_DEST}/share/icons/hicolor/512x512/apps/org.duckstation.DuckStation.png", "install -Dm644 \"${FLATPAK_BUILDER_BUILDDIR}/scripts/org.duckstation.DuckStation.png\" \"${FLATPAK_DEST}/share/icons/hicolor/512x512/apps/org.duckstation.DuckStation.png\"",
"install -Dm644 scripts/org.duckstation.DuckStation.desktop ${FLATPAK_DEST}/share/applications/org.duckstation.DuckStation.desktop", "install -Dm644 \"${FLATPAK_BUILDER_BUILDDIR}/scripts/org.duckstation.DuckStation.desktop\" \"${FLATPAK_DEST}/share/applications/org.duckstation.DuckStation.desktop\"",
"install -Dm644 scripts/flatpak/org.duckstation.DuckStation.metainfo.xml ${FLATPAK_DEST}/share/metainfo/org.duckstation.DuckStation.metainfo.xml" "install -Dm644 \"${FLATPAK_BUILDER_BUILDDIR}/scripts/flatpak/org.duckstation.DuckStation.metainfo.xml\" \"${FLATPAK_DEST}/share/metainfo/org.duckstation.DuckStation.metainfo.xml\""
] ]
} }
] ]

View file

@ -146,7 +146,7 @@ if(CPU_ARCH_X64)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_link_libraries(core PRIVATE zydis) target_link_libraries(core PRIVATE zydis)
endif() endif()
message("Building x64 recompiler") message(STATUS "Building x64 recompiler.")
endif() endif()
if(CPU_ARCH_ARM32) if(CPU_ARCH_ARM32)
target_compile_definitions(core PUBLIC "ENABLE_RECOMPILER=1" "ENABLE_NEWREC=1") target_compile_definitions(core PUBLIC "ENABLE_RECOMPILER=1" "ENABLE_NEWREC=1")
@ -156,7 +156,7 @@ if(CPU_ARCH_ARM32)
cpu_newrec_compiler_aarch32.h cpu_newrec_compiler_aarch32.h
) )
target_link_libraries(core PUBLIC vixl) target_link_libraries(core PUBLIC vixl)
message("Building AArch32 recompiler") message(STATUS "Building AArch32 recompiler.")
endif() endif()
if(CPU_ARCH_ARM64) if(CPU_ARCH_ARM64)
target_compile_definitions(core PUBLIC "ENABLE_RECOMPILER=1" "ENABLE_NEWREC=1" "ENABLE_MMAP_FASTMEM=1") target_compile_definitions(core PUBLIC "ENABLE_RECOMPILER=1" "ENABLE_NEWREC=1" "ENABLE_MMAP_FASTMEM=1")
@ -166,7 +166,7 @@ if(CPU_ARCH_ARM64)
cpu_newrec_compiler_aarch64.h cpu_newrec_compiler_aarch64.h
) )
target_link_libraries(core PUBLIC vixl) target_link_libraries(core PUBLIC vixl)
message("Building AArch64 recompiler") message(STATUS "Building AArch64 recompiler.")
endif() endif()
if(CPU_ARCH_RISCV64) if(CPU_ARCH_RISCV64)
target_compile_definitions(core PUBLIC "ENABLE_NEWREC=1" "ENABLE_MMAP_FASTMEM=1") target_compile_definitions(core PUBLIC "ENABLE_NEWREC=1" "ENABLE_MMAP_FASTMEM=1")
@ -175,10 +175,10 @@ if(CPU_ARCH_RISCV64)
cpu_newrec_compiler_riscv64.h cpu_newrec_compiler_riscv64.h
) )
target_link_libraries(core PUBLIC biscuit::biscuit riscv-disas) target_link_libraries(core PUBLIC biscuit::biscuit riscv-disas)
message("Building RISC-V 64-bit recompiler") message(STATUS "Building RISC-V 64-bit recompiler.")
endif() endif()
if(ENABLE_DISCORD_PRESENCE) if(NOT ANDROID)
target_compile_definitions(core PUBLIC -DENABLE_DISCORD_PRESENCE=1) target_compile_definitions(core PUBLIC -DENABLE_DISCORD_PRESENCE=1)
target_link_libraries(core PRIVATE discord-rpc) target_link_libraries(core PRIVATE discord-rpc)
endif() endif()

View file

@ -195,14 +195,31 @@ if(WIN32)
"${WINDEPLOYQT_EXE}" --libdir="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" "${WINDEPLOYQT_EXE}" --libdir="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
--plugindir="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/QtPlugins" --plugindir="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/QtPlugins"
$<IF:$<CONFIG:Debug>,--debug,--release> $<IF:$<CONFIG:Debug>,--debug,--release>
--no-translations
--no-compiler-runtime --no-compiler-runtime
--no-system-d3d-compiler
--no-system-dxc-compiler
--no-translations
"$<TARGET_FILE:duckstation-qt>" "$<TARGET_FILE:duckstation-qt>"
) )
add_custom_command(TARGET duckstation-qt POST_BUILD add_custom_command(TARGET duckstation-qt POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/qt.conf.win" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/qt.conf" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/qt.conf.win" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/qt.conf"
) )
#set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/translations") #set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/translations")
set(DEPS_TO_COPY freetype.dll harfbuzz.dll libjpeg.dll libpng16.dll libsharpyuv.dll libwebp.dll SDL2.dll shaderc_shared.dll zlib1.dll zstd.dll)
foreach(DEP ${DEPS_TO_COPY})
list(APPEND DEP_BINS "${CMAKE_PREFIX_PATH}/bin/${DEP}")
endforeach()
add_custom_command(TARGET duckstation-qt POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEP_BINS} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
get_property(WINPIXEVENTRUNTIME_DLL TARGET WinPixEventRuntime::WinPixEventRuntime PROPERTY IMPORTED_LOCATION)
message(STATUS WP "${WINPIXEVENTRUNTIME_DLL}")
add_custom_command(TARGET duckstation-qt POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${WINPIXEVENTRUNTIME_DLL}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
)
endif()
elseif(APPLE) elseif(APPLE)
# Don't generate a bundle for XCode, it makes code signing fail... # Don't generate a bundle for XCode, it makes code signing fail...
if(NOT CMAKE_GENERATOR MATCHES "Xcode") if(NOT CMAKE_GENERATOR MATCHES "Xcode")
@ -226,21 +243,21 @@ elseif(APPLE)
# Copy icon into the bundle # Copy icon into the bundle
target_sources(duckstation-qt PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/DuckStation.icns") target_sources(duckstation-qt PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/DuckStation.icns")
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/DuckStation.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources) set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/DuckStation.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
endif()
# Translation setup # Translation setup.
qt_add_lrelease(duckstation-qt TS_FILES ${TS_FILES} QM_FILES_OUTPUT_VARIABLE QM_FILES) qt_add_lrelease(duckstation-qt TS_FILES ${TS_FILES} QM_FILES_OUTPUT_VARIABLE QM_FILES)
foreach (QM_FILE IN LISTS QM_FILES) if(NOT APPLE)
target_sources(duckstation-qt PRIVATE ${QM_FILE})
set_source_files_properties(${QM_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/translations)
endforeach()
copy_base_translations(duckstation-qt)
else()
qt_add_lrelease(duckstation-qt TS_FILES ${TS_FILES} QM_FILES_OUTPUT_VARIABLE QM_FILES)
set(QM_OUTPUT_DIR "$<TARGET_FILE_DIR:duckstation-qt>/translations") set(QM_OUTPUT_DIR "$<TARGET_FILE_DIR:duckstation-qt>/translations")
add_custom_command(TARGET duckstation-qt POST_BUILD COMMAND "${CMAKE_COMMAND}" -E make_directory "${QM_OUTPUT_DIR}") add_custom_command(TARGET duckstation-qt POST_BUILD COMMAND "${CMAKE_COMMAND}" -E make_directory "${QM_OUTPUT_DIR}")
foreach (QM_FILE IN LISTS QM_FILES) foreach (QM_FILE IN LISTS QM_FILES)
get_filename_component(QM_FILE_NAME ${QM_FILE} NAME) get_filename_component(QM_FILE_NAME ${QM_FILE} NAME)
add_custom_command(TARGET duckstation-qt POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${QM_FILE}" "${QM_OUTPUT_DIR}/${QM_FILE_NAME}") add_custom_command(TARGET duckstation-qt POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${QM_FILE}" "${QM_OUTPUT_DIR}/${QM_FILE_NAME}")
endforeach() endforeach()
copy_base_translations(duckstation-qt) else()
foreach (QM_FILE IN LISTS QM_FILES)
target_sources(duckstation-qt PRIVATE ${QM_FILE})
set_source_files_properties(${QM_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/translations)
endforeach()
endif() endif()
copy_base_translations(duckstation-qt)

View file

@ -78,14 +78,6 @@ target_include_directories(util PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
target_link_libraries(util PUBLIC common simpleini imgui) target_link_libraries(util PUBLIC common simpleini imgui)
target_link_libraries(util PRIVATE libchdr JPEG::JPEG PNG::PNG WebP::libwebp ZLIB::ZLIB soundtouch xxhash Zstd::Zstd reshadefx) target_link_libraries(util PRIVATE libchdr JPEG::JPEG PNG::PNG WebP::libwebp ZLIB::ZLIB soundtouch xxhash Zstd::Zstd reshadefx)
if(ENABLE_CUBEB)
target_sources(util PRIVATE
cubeb_audio_stream.cpp
)
target_compile_definitions(util PUBLIC "ENABLE_CUBEB=1")
target_link_libraries(util PRIVATE cubeb)
endif()
if(ENABLE_X11) if(ENABLE_X11)
target_compile_definitions(util PRIVATE "-DENABLE_X11=1") target_compile_definitions(util PRIVATE "-DENABLE_X11=1")
target_link_libraries(util PRIVATE X11::X11 X11::Xrandr) target_link_libraries(util PRIVATE X11::X11 X11::Xrandr)
@ -180,26 +172,21 @@ if(ENABLE_VULKAN OR APPLE)
target_link_libraries(util PUBLIC Shaderc::shaderc_shared) target_link_libraries(util PUBLIC Shaderc::shaderc_shared)
endif() endif()
if(ENABLE_SDL2) if(NOT ANDROID)
target_sources(util PRIVATE target_sources(util PRIVATE
cubeb_audio_stream.cpp
sdl_audio_stream.cpp sdl_audio_stream.cpp
sdl_input_source.cpp sdl_input_source.cpp
sdl_input_source.h sdl_input_source.h
) )
target_compile_definitions(util PUBLIC "ENABLE_SDL2=1") target_compile_definitions(util PUBLIC
target_link_libraries(util PUBLIC SDL2::SDL2) "ENABLE_CUBEB=1"
"ENABLE_SDL2=1"
# Copy bundled SDL2 to output on Windows. )
if(WIN32) target_link_libraries(util PUBLIC
# Copy SDL2 DLL to binary directory. cubeb
if(CMAKE_BUILD_TYPE STREQUAL "Debug") SDL2::SDL2
get_property(SDL2_DLL_PATH TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_DEBUG) )
else()
get_property(SDL2_DLL_PATH TARGET SDL2::SDL2 PROPERTY IMPORTED_LOCATION_RELEASE)
endif()
add_custom_command(TARGET util POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SDL2_DLL_PATH}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/SDL2.dll")
endif()
endif() endif()
if(WIN32) if(WIN32)