[cmake] small optimizations + fix sdl2 download for src pack

Signed-off-by: crueter <crueter@eden-emu.dev>
This commit is contained in:
crueter 2025-08-21 19:22:05 -04:00
parent 0fb98d7487
commit fc6641e581
3 changed files with 68 additions and 95 deletions

View file

@ -44,23 +44,18 @@ if (PLATFORM_FREEBSD)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
endif()
# Check if SDL2::SDL2 target exists; if not, create an alias
if (TARGET SDL2::SDL2-static)
add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static)
elseif (TARGET SDL2::SDL2-shared)
add_library(SDL2::SDL2 ALIAS SDL2::SDL2-shared)
endif()
# Set bundled sdl2/qt as dependent options.
# On Linux system SDL2 is likely to be lacking HIDAPI support which have drawbacks but is needed for SDL motion
CMAKE_DEPENDENT_OPTION(ENABLE_SDL2 "Enable the SDL2 frontend" ON "NOT ANDROID" OFF)
set(EXT_DEFAULT ON)
if (PLATFORM_FREEBSD)
CMAKE_DEPENDENT_OPTION(YUZU_USE_EXTERNAL_SDL2 "Compile external SDL2" OFF "ENABLE_SDL2;NOT MSVC" OFF)
else()
CMAKE_DEPENDENT_OPTION(YUZU_USE_EXTERNAL_SDL2 "Compile external SDL2" ON "ENABLE_SDL2;NOT MSVC" OFF)
set(EXT_DEFAULT OFF)
endif()
CMAKE_DEPENDENT_OPTION(YUZU_USE_EXTERNAL_SDL2 "Compile external SDL2" ${EXT_DEFAULT} "ENABLE_SDL2;NOT MSVC" OFF)
cmake_dependent_option(ENABLE_LIBUSB "Enable the use of LibUSB" ON "NOT ANDROID" OFF)
option(ENABLE_OPENGL "Enable OpenGL" ON)
@ -77,29 +72,10 @@ option(YUZU_USE_CPM "Use CPM to fetch Eden dependencies if needed" ON)
option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON)
option(ENABLE_WIFI_SCAN "Enable WiFi scanning" OFF)
if (PLATFORM_FREEBSD)
option(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled FFmpeg" OFF)
else()
option(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled FFmpeg" ON)
endif()
if (PLATFORM_FREEBSD)
option(YUZU_USE_EXTERNAL_VULKAN_HEADERS "Use Vulkan-Headers from externals" OFF)
else()
option(YUZU_USE_EXTERNAL_VULKAN_HEADERS "Use Vulkan-Headers from externals" ON)
endif()
if (PLATFORM_FREEBSD)
option(YUZU_USE_EXTERNAL_VULKAN_UTILITY_LIBRARIES "Use Vulkan-Utility-Libraries from externals" OFF)
else()
option(YUZU_USE_EXTERNAL_VULKAN_UTILITY_LIBRARIES "Use Vulkan-Utility-Libraries from externals" ON)
endif()
if (PLATFORM_FREEBSD)
option(YUZU_USE_EXTERNAL_VULKAN_SPIRV_TOOLS "Use SPIRV-Tools from externals" OFF)
else()
option(YUZU_USE_EXTERNAL_VULKAN_SPIRV_TOOLS "Use SPIRV-Tools from externals" ON)
endif()
option(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled FFmpeg" ${EXT_DEFAULT})
option(YUZU_USE_EXTERNAL_VULKAN_HEADERS "Use Vulkan-Headers from externals" ${EXT_DEFAULT})
option(YUZU_USE_EXTERNAL_VULKAN_UTILITY_LIBRARIES "Use Vulkan-Utility-Libraries from externals" ${EXT_DEFAULT})
option(YUZU_USE_EXTERNAL_VULKAN_SPIRV_TOOLS "Use SPIRV-Tools from externals" ${EXT_DEFAULT})
option(YUZU_USE_QT_MULTIMEDIA "Use QtMultimedia for Camera" OFF)
@ -115,11 +91,7 @@ option(ENABLE_MICROPROFILE "Enables microprofile capabilities" OFF)
option(YUZU_TESTS "Compile tests" "${BUILD_TESTING}")
if (PLATFORM_FREEBSD)
option(YUZU_USE_PRECOMPILED_HEADERS "Use precompiled headers" OFF)
else()
option(YUZU_USE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
endif()
option(YUZU_USE_PRECOMPILED_HEADERS "Use precompiled headers" ${EXT_DEFAULT})
option(YUZU_DOWNLOAD_ANDROID_VVL "Download validation layer binary for android" ON)
@ -676,8 +648,50 @@ if (NOT YUZU_USE_EXTERNAL_VULKAN_SPIRV_TOOLS)
endif()
# find SDL2 exports a bunch of variables that are needed, so its easier to do this outside of the YUZU_find_package
# TODO(crueter): combine this all with CPM.
if (ENABLE_SDL2)
# this was hard to get right, but ultimately I decided to make it so that FORCE_DOWNLOAD_SDL2 also downloads the
# external one. Really silly behavior imo but in the interest of getting something out there I'm leaving it for now
if (YUZU_USE_EXTERNAL_SDL2 OR FORCE_DOWNLOAD_SDL2)
message(STATUS "Using SDL2 from externals.")
if (NOT WIN32)
# Yuzu itself needs: Atomic Audio Events Joystick Haptic Sensor Threads Timers
# Since 2.0.18 Atomic+Threads required for HIDAPI/libusb (see https://github.com/libsdl-org/SDL/issues/5095)
# Yuzu-cmd also needs: Video (depends on Loadso/Dlopen)
# CPUinfo also required for SDL Audio, at least until 2.28.0 (see https://github.com/libsdl-org/SDL/issues/7809)
set(SDL_UNUSED_SUBSYSTEMS
File Filesystem
Locale Power Render)
foreach(_SUB ${SDL_UNUSED_SUBSYSTEMS})
string(TOUPPER ${_SUB} _OPT)
set(SDL_${_OPT} OFF)
endforeach()
set(HIDAPI ON)
endif()
if (APPLE)
set(SDL_FILE ON)
endif()
if ("${YUZU_SYSTEM_PROFILE}" STREQUAL "steamdeck")
set(SDL_HASH cc016b0046)
set(SDL_PIPEWIRE OFF) # build errors out with this on
set(SDL_SHA512SUM 34d5ef58da6a4f9efa6689c82f67badcbd741f5a4f562a9c2c30828fa839830fb07681c5dc6a7851520e261c8405a416ac0a2c2513b51984fb3b4fa4dcb3e20b)
else()
set(SDL_HASH 54772f345a)
set(SDL_SHA512SUM 2a68a0e01c390043aa9d9df63d8a20a52076c88bb460ac4e0f33194ca7d9bc8fadbbcc04e7506872ac4b6354a73fbc267c036f82200da59465789b87c7d9e3a4)
endif()
AddPackage(
NAME SDL2
REPO "libsdl-org/SDL"
SHA ${SDL_HASH}
HASH ${SDL_SHA512SUM}
KEY ${YUZU_SYSTEM_PROFILE}
BUNDLED_PACKAGE ON
)
endif()
if (YUZU_USE_BUNDLED_SDL2)
message(STATUS "Using bundled SDL2")
AddCIPackage(
@ -688,9 +702,8 @@ if (ENABLE_SDL2)
MIN_VERSION 2.26.4
CMAKE_FILENAME sdl2
FORCE_DOWNLOAD ${FORCE_DOWNLOAD_SDL2}
TARGET "SDL2::SDL2"
)
elseif (YUZU_USE_EXTERNAL_SDL2)
message(STATUS "Using SDL2 from externals.")
endif()
if (YUZU_USE_BUNDLED_SDL2 OR NOT YUZU_USE_EXTERNAL_SDL2)

View file

@ -286,6 +286,7 @@ function(AddCIPackage)
MIN_VERSION
DISABLED_PLATFORMS
CMAKE_FILENAME
TARGET
)
cmake_parse_arguments(PKG_ARGS "" "${oneValueArgs}" "" ${ARGN})
@ -400,6 +401,7 @@ function(AddCIPackage)
endif()
if (DEFINED ARTIFACT_DIR)
if (NOT DEFINED PKG_ARGS_TARGET OR NOT TARGET "${PKG_ARGS_TARGET}")
include(${ARTIFACT_DIR}/${ARTIFACT_CMAKE}.cmake)
# Overrides find package
@ -409,10 +411,11 @@ function(AddCIPackage)
)
set_property(GLOBAL APPEND PROPERTY CPM_PACKAGE_NAMES ${ARTIFACT_NAME})
set_property(GLOBAL APPEND PROPERTY CPM_PACKAGE_URLS "https://github.com/${ARTIFACT_REPO}")
set_property(GLOBAL APPEND PROPERTY CPM_PACKAGE_URLS "https://github.com/${ARTIFACT_REPO}") # TODO(crueter) other hosts?
set_property(GLOBAL APPEND PROPERTY CPM_PACKAGE_SHAS ${ARTIFACT_VERSION})
set(${ARTIFACT_PACKAGE}_ADDED TRUE PARENT_SCOPE)
endif()
else()
find_package(${ARTIFACT_PACKAGE} ${ARTIFACT_MIN_VERSION} REQUIRED)
endif()

View file

@ -32,7 +32,7 @@ endif()
# Xbyak (also used by Dynarmic, so needs to be added first)
if (ARCHITECTURE_x86 OR ARCHITECTURE_x86_64)
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
if (PLATFORM_SUN)
# Fix regset.h collisions
set(XBYAK_HASH 51f507b0b3)
set(XBYAK_SHA512SUM 4a29a3c2f97f7d5adf667a21a008be03c951fb6696b0d7ba27e7e4afa037bc76eb5e059bb84860e01baf741d4d3ac851b840cd54c99d038812fbe0f1fa6d38a4)
@ -94,49 +94,6 @@ if (ENABLE_LIBUSB AND NOT TARGET libusb::usb)
add_subdirectory(libusb)
endif()
# SDL2
if (YUZU_USE_EXTERNAL_SDL2 OR FORCE_DOWNLOAD_SDL2)
if (NOT WIN32)
# Yuzu itself needs: Atomic Audio Events Joystick Haptic Sensor Threads Timers
# Since 2.0.18 Atomic+Threads required for HIDAPI/libusb (see https://github.com/libsdl-org/SDL/issues/5095)
# Yuzu-cmd also needs: Video (depends on Loadso/Dlopen)
# CPUinfo also required for SDL Audio, at least until 2.28.0 (see https://github.com/libsdl-org/SDL/issues/7809)
set(SDL_UNUSED_SUBSYSTEMS
File Filesystem
Locale Power Render)
foreach(_SUB ${SDL_UNUSED_SUBSYSTEMS})
string(TOUPPER ${_SUB} _OPT)
set(SDL_${_OPT} OFF)
endforeach()
set(HIDAPI ON)
endif()
if (APPLE)
set(SDL_FILE ON)
endif()
if ("${YUZU_SYSTEM_PROFILE}" STREQUAL "steamdeck")
set(SDL_HASH cc016b0046)
set(SDL_PIPEWIRE OFF) # build errors out with this on
set(SDL_SHA512SUM 34d5ef58da6a4f9efa6689c82f67badcbd741f5a4f562a9c2c30828fa839830fb07681c5dc6a7851520e261c8405a416ac0a2c2513b51984fb3b4fa4dcb3e20b)
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
set(SDL_HASH d310b5679f)
set(SDL_SHA512SUM cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e)
else()
set(SDL_HASH 2e4c12cd2c)
set(SDL_SHA512SUM d95af47f469a312876f8ab361074a1e7b8083db19935a102d9c6e5887ace6008e64475a8c54b00164b40cad86492bb1b2366084efdd0b2555e5fea6d9c5da80e)
endif()
AddPackage(
NAME SDL2
REPO "libsdl-org/SDL"
SHA ${SDL_HASH}
HASH ${SDL_SHA512SUM}
KEY ${YUZU_SYSTEM_PROFILE}
BUNDLED_PACKAGE ON
)
endif()
# Sirit
# TODO(crueter): spirv-tools doesn't work w/ system
set(SPIRV_WERROR OFF)