2022-08-22 20:21:23 +00:00
|
|
|
cmake_minimum_required(VERSION 3.21.1)
|
|
|
|
|
2022-08-29 05:19:48 +00:00
|
|
|
option(ENABLE_VCPKG "Enable the vcpkg package manager" ON)
|
2022-10-23 14:58:28 +00:00
|
|
|
option(MACOS_BUNDLE "The executable when built on macOS will be created as an application bundle" OFF)
|
2022-08-22 20:21:23 +00:00
|
|
|
|
2024-08-26 09:43:38 +00:00
|
|
|
# used by CI script to set version:
|
|
|
|
set(EMULATOR_VERSION_MAJOR "0" CACHE STRING "")
|
|
|
|
set(EMULATOR_VERSION_MINOR "0" CACHE STRING "")
|
|
|
|
set(EMULATOR_VERSION_PATCH "0" CACHE STRING "")
|
|
|
|
|
|
|
|
execute_process(
|
|
|
|
COMMAND git log --format=%h -1
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
|
|
|
OUTPUT_VARIABLE GIT_HASH
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
add_definitions(-DEMULATOR_HASH=${GIT_HASH})
|
2022-08-31 10:04:09 +00:00
|
|
|
|
2022-08-29 05:19:48 +00:00
|
|
|
if (ENABLE_VCPKG)
|
2024-08-07 00:50:24 +00:00
|
|
|
# check if vcpkg is shallow and unshallow it if necessary
|
|
|
|
execute_process(
|
|
|
|
COMMAND git rev-parse --is-shallow-repository
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/dependencies/vcpkg
|
|
|
|
OUTPUT_VARIABLE is_vcpkg_shallow
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
|
|
|
if(is_vcpkg_shallow STREQUAL "true")
|
|
|
|
message(STATUS "vcpkg is shallow. Unshallowing it now...")
|
|
|
|
execute_process(
|
|
|
|
COMMAND git fetch --unshallow
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/dependencies/vcpkg"
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
OUTPUT_VARIABLE output
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-04-13 11:42:09 +00:00
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_LIST_DIR}/dependencies/vcpkg_overlay_ports_linux")
|
2024-01-16 01:46:56 +00:00
|
|
|
elseif(APPLE)
|
|
|
|
set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_LIST_DIR}/dependencies/vcpkg_overlay_ports_mac")
|
2023-04-13 11:42:09 +00:00
|
|
|
else()
|
|
|
|
set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_LIST_DIR}/dependencies/vcpkg_overlay_ports")
|
|
|
|
endif()
|
2022-08-29 05:19:48 +00:00
|
|
|
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/vcpkg/scripts/buildsystems/vcpkg.cmake"
|
|
|
|
CACHE STRING "Vcpkg toolchain file")
|
|
|
|
# Set this so that all the various find_package() calls don't need an explicit
|
|
|
|
# CONFIG option
|
|
|
|
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
|
|
|
|
if (WIN32)
|
|
|
|
set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "")
|
|
|
|
endif()
|
2022-08-22 20:21:23 +00:00
|
|
|
endif()
|
|
|
|
|
2022-10-28 14:57:14 +00:00
|
|
|
project(Cemu VERSION 2.0.0)
|
2022-08-29 05:19:48 +00:00
|
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
|
|
|
|
2022-08-22 20:21:23 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
2022-09-24 06:43:27 +00:00
|
|
|
add_compile_definitions($<$<CONFIG:Debug>:CEMU_DEBUG_ASSERT>) # if build type is debug, set CEMU_DEBUG_ASSERT
|
2022-08-26 15:56:19 +00:00
|
|
|
|
2024-08-26 09:43:38 +00:00
|
|
|
add_definitions(-DEMULATOR_VERSION_MAJOR=${EMULATOR_VERSION_MAJOR})
|
|
|
|
add_definitions(-DEMULATOR_VERSION_MINOR=${EMULATOR_VERSION_MINOR})
|
|
|
|
add_definitions(-DEMULATOR_VERSION_PATCH=${EMULATOR_VERSION_PATCH})
|
|
|
|
|
2022-09-01 12:46:56 +00:00
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
|
2022-09-24 06:43:27 +00:00
|
|
|
# enable link time optimization for release builds
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO ON)
|
|
|
|
|
2022-08-24 06:32:04 +00:00
|
|
|
if (MSVC)
|
2022-09-01 12:46:56 +00:00
|
|
|
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT CemuBin)
|
|
|
|
# floating point model: precise, fiber safe optimizations
|
2022-09-04 21:15:40 +00:00
|
|
|
add_compile_options(/EHsc /fp:precise)
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
|
|
# Speeds up static linking (especially helpful in incremental compilation)
|
|
|
|
if((CMAKE_LINKER MATCHES ".*lld-link.*") AND (CMAKE_AR MATCHES ".*llvm-lib.*"))
|
|
|
|
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY STATIC_LIBRARY_OPTIONS /llvmlibthin)
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
add_compile_options(/GT)
|
|
|
|
endif()
|
2022-09-24 06:43:27 +00:00
|
|
|
# enable additional optimization flags for release builds
|
|
|
|
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:/Oi>) # enable intrinsic functions
|
|
|
|
add_compile_options($<$<CONFIG:Release,RelWithDebInfo>:/Ot>) # favor speed
|
2022-08-24 06:32:04 +00:00
|
|
|
endif()
|
2022-08-22 20:21:23 +00:00
|
|
|
|
2022-09-18 12:39:00 +00:00
|
|
|
if (APPLE)
|
|
|
|
enable_language(OBJC OBJCXX)
|
2024-08-28 09:06:49 +00:00
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "12.0")
|
2022-09-18 12:39:00 +00:00
|
|
|
endif()
|
|
|
|
|
2022-12-15 07:44:14 +00:00
|
|
|
if (UNIX AND NOT APPLE)
|
|
|
|
option(ENABLE_WAYLAND "Build with Wayland support" ON)
|
2023-05-11 05:19:44 +00:00
|
|
|
option(ENABLE_FERAL_GAMEMODE "Enables Feral Interactive GameMode Support" ON)
|
2022-12-15 07:44:14 +00:00
|
|
|
endif()
|
|
|
|
|
2022-08-22 20:21:23 +00:00
|
|
|
option(ENABLE_OPENGL "Enables the OpenGL backend" ON)
|
|
|
|
option(ENABLE_VULKAN "Enables the Vulkan backend" ON)
|
|
|
|
option(ENABLE_DISCORD_RPC "Enables the Discord Rich Presence feature" ON)
|
|
|
|
|
2023-05-11 05:19:44 +00:00
|
|
|
|
2022-08-22 20:21:23 +00:00
|
|
|
# input backends
|
2022-08-24 06:32:04 +00:00
|
|
|
if (WIN32)
|
2022-09-01 12:46:56 +00:00
|
|
|
option(ENABLE_XINPUT "Enables the usage of XInput" ON)
|
|
|
|
option(ENABLE_DIRECTINPUT "Enables the usage of DirectInput" ON)
|
|
|
|
add_compile_definitions(HAS_DIRECTINPUT)
|
2022-08-22 20:21:23 +00:00
|
|
|
endif()
|
2023-12-06 01:33:29 +00:00
|
|
|
|
|
|
|
option(ENABLE_HIDAPI "Build with HIDAPI" ON)
|
2022-08-22 20:21:23 +00:00
|
|
|
option(ENABLE_SDL "Enables the SDLController backend" ON)
|
|
|
|
|
|
|
|
# audio backends
|
2022-08-24 06:32:04 +00:00
|
|
|
if (WIN32)
|
2022-09-01 12:46:56 +00:00
|
|
|
option(ENABLE_DIRECTAUDIO "Enables the directaudio backend" ON)
|
|
|
|
option(ENABLE_XAUDIO "Enables the xaudio backend" ON)
|
2022-08-22 20:21:23 +00:00
|
|
|
endif()
|
|
|
|
option(ENABLE_CUBEB "Enabled cubeb backend" ON)
|
|
|
|
|
2023-09-18 23:27:40 +00:00
|
|
|
# usb hid backends
|
|
|
|
if (WIN32)
|
|
|
|
option(ENABLE_NSYSHID_WINDOWS_HID "Enables the native Windows HID backend for nsyshid" ON)
|
|
|
|
endif ()
|
|
|
|
# libusb and windows hid backends shouldn't be active at the same time; otherwise we'd see all devices twice!
|
|
|
|
if (NOT ENABLE_NSYSHID_WINDOWS_HID)
|
|
|
|
option(ENABLE_NSYSHID_LIBUSB "Enables the libusb backend for nsyshid" ON)
|
|
|
|
else ()
|
|
|
|
set(ENABLE_NSYSHID_LIBUSB OFF CACHE BOOL "" FORCE)
|
|
|
|
endif ()
|
|
|
|
if (ENABLE_NSYSHID_WINDOWS_HID)
|
|
|
|
add_compile_definitions(NSYSHID_ENABLE_BACKEND_WINDOWS_HID)
|
|
|
|
endif ()
|
|
|
|
if (ENABLE_NSYSHID_LIBUSB)
|
|
|
|
add_compile_definitions(NSYSHID_ENABLE_BACKEND_LIBUSB)
|
|
|
|
endif ()
|
|
|
|
|
2022-08-22 20:21:23 +00:00
|
|
|
option(ENABLE_WXWIDGETS "Build with wxWidgets UI (Currently required)" ON)
|
|
|
|
|
2022-08-29 05:19:48 +00:00
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG true)
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
find_package(SDL2 REQUIRED)
|
|
|
|
find_package(CURL REQUIRED)
|
|
|
|
find_package(pugixml REQUIRED)
|
|
|
|
find_package(RapidJSON REQUIRED)
|
2022-08-22 20:21:23 +00:00
|
|
|
find_package(Boost COMPONENTS program_options filesystem nowide REQUIRED)
|
|
|
|
find_package(libzip REQUIRED)
|
|
|
|
find_package(glslang REQUIRED)
|
|
|
|
find_package(ZLIB REQUIRED)
|
2022-08-29 05:19:48 +00:00
|
|
|
find_package(zstd MODULE REQUIRED) # MODULE so that zstd::zstd is available
|
|
|
|
find_package(OpenSSL COMPONENTS Crypto SSL REQUIRED)
|
|
|
|
find_package(glm REQUIRED)
|
2023-10-02 16:52:54 +00:00
|
|
|
find_package(fmt 9 REQUIRED)
|
2022-08-29 05:19:48 +00:00
|
|
|
find_package(PNG REQUIRED)
|
|
|
|
|
|
|
|
# glslang versions older than 11.11.0 define targets without a namespace
|
|
|
|
if (NOT TARGET glslang::SPIRV AND TARGET SPIRV)
|
|
|
|
add_library(glslang::SPIRV ALIAS SPIRV)
|
|
|
|
endif()
|
|
|
|
|
2022-08-30 17:02:56 +00:00
|
|
|
if (UNIX AND NOT APPLE)
|
2022-08-29 05:19:48 +00:00
|
|
|
find_package(X11 REQUIRED)
|
2022-12-15 07:44:14 +00:00
|
|
|
if (ENABLE_WAYLAND)
|
2023-05-28 00:04:24 +00:00
|
|
|
find_package(Wayland REQUIRED Client)
|
|
|
|
find_package(WaylandScanner REQUIRED)
|
|
|
|
find_package(WaylandProtocols 1.15 REQUIRED)
|
|
|
|
|
|
|
|
ecm_add_wayland_client_protocol(WAYLAND_PROTOCOL_SRCS
|
|
|
|
PROTOCOL "${WaylandProtocols_DATADIR}/stable/viewporter/viewporter.xml"
|
|
|
|
BASENAME viewporter)
|
|
|
|
add_library(CemuWaylandProtocols STATIC ${WAYLAND_PROTOCOL_SRCS})
|
|
|
|
target_include_directories(CemuWaylandProtocols PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
|
2022-12-15 07:44:14 +00:00
|
|
|
add_compile_definitions(HAS_WAYLAND)
|
|
|
|
endif()
|
2022-11-24 11:29:29 +00:00
|
|
|
find_package(GTK3 REQUIRED)
|
2023-05-11 05:19:44 +00:00
|
|
|
|
2022-08-29 05:19:48 +00:00
|
|
|
endif()
|
2022-08-22 20:21:23 +00:00
|
|
|
|
2022-08-24 06:32:04 +00:00
|
|
|
if (ENABLE_VULKAN)
|
2022-09-01 12:46:56 +00:00
|
|
|
include_directories("dependencies/Vulkan-Headers/include")
|
2022-08-22 20:21:23 +00:00
|
|
|
endif()
|
2022-08-24 06:32:04 +00:00
|
|
|
|
|
|
|
if (ENABLE_OPENGL)
|
2022-09-01 12:46:56 +00:00
|
|
|
find_package(OpenGL REQUIRED)
|
2022-08-22 20:21:23 +00:00
|
|
|
endif()
|
2022-08-24 06:32:04 +00:00
|
|
|
|
|
|
|
if (ENABLE_DISCORD_RPC)
|
2022-09-01 12:46:56 +00:00
|
|
|
add_compile_definitions(ENABLE_DISCORD_RPC)
|
|
|
|
add_subdirectory(dependencies/discord-rpc EXCLUDE_FROM_ALL)
|
|
|
|
target_include_directories(discord-rpc INTERFACE ./dependencies/discord-rpc/include)
|
2022-08-22 20:21:23 +00:00
|
|
|
endif()
|
|
|
|
|
2023-08-15 07:37:37 +00:00
|
|
|
if (ENABLE_HIDAPI)
|
|
|
|
find_package(hidapi REQUIRED)
|
|
|
|
set(ENABLE_WIIMOTE ON)
|
|
|
|
add_compile_definitions(HAS_HIDAPI)
|
|
|
|
endif ()
|
|
|
|
|
2023-05-11 05:19:44 +00:00
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
if(ENABLE_FERAL_GAMEMODE)
|
|
|
|
add_compile_definitions(ENABLE_FERAL_GAMEMODE)
|
|
|
|
add_subdirectory(dependencies/gamemode EXCLUDE_FROM_ALL)
|
|
|
|
target_include_directories(gamemode INTERFACE ./dependencies/gamemode/lib)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2022-08-24 06:32:04 +00:00
|
|
|
if (ENABLE_WXWIDGETS)
|
2022-08-29 05:19:48 +00:00
|
|
|
find_package(wxWidgets 3.2 REQUIRED COMPONENTS base core gl propgrid xrc)
|
2022-08-22 20:21:23 +00:00
|
|
|
endif()
|
|
|
|
|
2022-08-24 06:32:04 +00:00
|
|
|
if (ENABLE_CUBEB)
|
2023-03-13 02:43:13 +00:00
|
|
|
if (NOT ENABLE_VCPKG)
|
2022-08-29 05:19:48 +00:00
|
|
|
find_package(cubeb)
|
2023-03-13 02:43:13 +00:00
|
|
|
endif()
|
2022-08-29 05:19:48 +00:00
|
|
|
if (NOT cubeb_FOUND)
|
|
|
|
option(BUILD_TESTS "" OFF)
|
|
|
|
option(BUILD_TOOLS "" OFF)
|
|
|
|
option(BUNDLE_SPEEX "" OFF)
|
|
|
|
set(USE_WINMM OFF CACHE BOOL "")
|
2024-09-17 00:00:26 +00:00
|
|
|
add_subdirectory("dependencies/cubeb" EXCLUDE_FROM_ALL SYSTEM)
|
2022-08-29 05:19:48 +00:00
|
|
|
set_property(TARGET cubeb PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
|
|
add_library(cubeb::cubeb ALIAS cubeb)
|
|
|
|
endif()
|
|
|
|
add_compile_definitions("HAS_CUBEB=1")
|
2022-08-22 20:21:23 +00:00
|
|
|
endif()
|
|
|
|
|
2022-09-03 08:34:47 +00:00
|
|
|
add_subdirectory("dependencies/ih264d" EXCLUDE_FROM_ALL)
|
2022-08-29 05:19:48 +00:00
|
|
|
|
|
|
|
find_package(ZArchive)
|
|
|
|
if (NOT ZArchive_FOUND)
|
2022-09-03 08:34:47 +00:00
|
|
|
add_subdirectory("dependencies/ZArchive" EXCLUDE_FROM_ALL)
|
2022-08-29 05:19:48 +00:00
|
|
|
endif()
|
2022-08-22 20:21:23 +00:00
|
|
|
|
2022-08-29 05:19:48 +00:00
|
|
|
add_subdirectory(src)
|