From 11065e99114e95bab4b617fa9b50ceb43019adee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joshua=20Vanda=C3=ABle?= Date: Wed, 24 Dec 2025 03:59:15 +0100 Subject: [PATCH 1/5] CMake: Error out when switching sources for dependencies Currently, configuring from System>Bundled doesn't work, it instead produces cryptic errors. And configuring from Bundled>System wont produce errors, but wont use the system libraries either. This change produces a clear error in both cases. --- CMake/DolphinLibraryTools.cmake | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/CMake/DolphinLibraryTools.cmake b/CMake/DolphinLibraryTools.cmake index f2305d8399..bedba9dcbd 100644 --- a/CMake/DolphinLibraryTools.cmake +++ b/CMake/DolphinLibraryTools.cmake @@ -50,6 +50,17 @@ function(dolphin_add_bundled_library library use_system bundled_path) add_subdirectory(${bundled_path} EXCLUDE_FROM_ALL) endfunction() +function(dolphin_set_library_type library type) + if(DEFINED ${library}_TYPE AND NOT ${${library}_TYPE} STREQUAL "${type}") + message(FATAL_ERROR + "The selection for ${library} changed from '${${library}_TYPE}' to '${type}' after configuration.\n" + "Please delete the build directory (or at least CMakeCache.txt) and reconfigure." + ) + endif() + + set(${library}_TYPE "${type}" CACHE INTERNAL "") +endfunction() + function(dolphin_find_optional_system_library library bundled_path) dolphin_optional_system_library(use_system ${library}) string(TOUPPER ${library} upperlib) @@ -101,11 +112,11 @@ function(dolphin_find_optional_system_library library bundled_path) endif() endif() if(${prefix}_FOUND) + dolphin_set_library_type(${library} "System") message(STATUS "Using system ${library}") - set(${prefix}_TYPE "System" PARENT_SCOPE) else() + dolphin_set_library_type(${library} "Bundled") dolphin_add_bundled_library(${library} ${use_system} ${bundled_path}) - set(${prefix}_TYPE "Bundled" PARENT_SCOPE) endif() endfunction() @@ -119,11 +130,11 @@ function(dolphin_find_optional_system_library_pkgconfig library search alias bun endif() endif() if(${library}_FOUND) + dolphin_set_library_type(${library} "System") message(STATUS "Using system ${library}") dolphin_alias_library(${alias} PkgConfig::${library}) - set(${library}_TYPE "System" PARENT_SCOPE) else() + dolphin_set_library_type(${library} "Bundled") dolphin_add_bundled_library(${library} ${use_system} ${bundled_path}) - set(${library}_TYPE "Bundled" PARENT_SCOPE) endif() endfunction() From 4af06fd487e896e5ad162bea1d53a390f90151c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joshua=20Vanda=C3=ABle?= Date: Wed, 24 Dec 2025 04:59:08 +0100 Subject: [PATCH 2/5] minizip-ng: Properly use libraries from Externals This also fixes the CMake build on Windows, since it would fail to find our target defined in Externals and would fall back to trying to redefine it, which produces an error. --- CMakeLists.txt | 16 ++++++------- Externals/minizip-ng/CMakeLists.txt | 35 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 170b7e0632..b3f27e994f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -658,6 +658,13 @@ if(NOT (WIN32 AND _M_ARM_64)) add_definitions(-DHAS_OPENGL) endif() +if(NOT WIN32) + if(ANDROID) + set(USE_SYSTEM_Iconv OFF) + endif() + dolphin_find_optional_system_library(Iconv Externals/libiconv 1.14) +endif() + dolphin_find_optional_system_library(pugixml Externals/pugixml) dolphin_find_optional_system_library_pkgconfig(ENET libenet>=1.3.18 enet::enet Externals/enet) @@ -718,15 +725,6 @@ dolphin_find_optional_system_library(MBEDTLS Externals/mbedtls 2.28) dolphin_find_optional_system_library(CURL Externals/curl) -if(NOT WIN32) - if(NOT ANDROID) - dolphin_find_optional_system_library(Iconv Externals/libiconv 1.14) - else() - message(STATUS "Using static iconv from Externals") - add_subdirectory(Externals/libiconv EXCLUDE_FROM_ALL) - endif() -endif() - if(NOT ANDROID) dolphin_find_optional_system_library(HIDAPI Externals/hidapi) endif() diff --git a/Externals/minizip-ng/CMakeLists.txt b/Externals/minizip-ng/CMakeLists.txt index adf2611841..9e7d41cbbf 100644 --- a/Externals/minizip-ng/CMakeLists.txt +++ b/Externals/minizip-ng/CMakeLists.txt @@ -3,7 +3,42 @@ set(MZ_BUILD_TESTS OFF) set(MZ_BUILD_UNIT_TESTS OFF) set(MZ_BUILD_FUZZ_TESTS OFF) set(MZ_CODE_COVERAGE OFF) +set(MZ_FETCH_LIBS OFF) +set(MZ_BZIP2 OFF) +set(MZ_PKCRYPT OFF) +set(MZ_WZAES OFF) +set(MZ_OPENSSL OFF) +set(MZ_LIBBSD OFF) set(SKIP_INSTALL_ALL ON) +if(Iconv_TYPE STREQUAL Bundled) + set(CMAKE_DISABLE_FIND_PACKAGE_Iconv TRUE) + set(Iconv_FOUND TRUE) + set(Iconv_LIBRARIES Iconv::Iconv) + get_target_property(Iconv_INCLUDE_DIRS ${Iconv_LIBRARIES} INTERFACE_INCLUDE_DIRECTORIES) +endif() +if(LibLZMA_TYPE STREQUAL Bundled) + set(CMAKE_DISABLE_FIND_PACKAGE_LibLZMA TRUE) + set(LIBLZMA_FOUND TRUE) + set(LIBLZMA_LIBRARIES LibLZMA::LibLZMA) + get_target_property(LIBLZMA_INCLUDE_DIRS ${LIBLZMA_LIBRARIES} INTERFACE_INCLUDE_DIRECTORIES) +endif() +if(ZLIB_TYPE STREQUAL Bundled) + set(CMAKE_DISABLE_FIND_PACKAGE_ZLIB TRUE) + set(ZLIB_FOUND TRUE) + set(ZLIB_LIBRARIES ZLIB::ZLIB) + get_target_property(ZLIB_INCLUDE_DIRS ${ZLIB_LIBRARIES} INTERFACE_INCLUDE_DIRECTORIES) +endif() +if(ZSTD_TYPE STREQUAL Bundled) + set(CMAKE_DISABLE_FIND_PACKAGE_ZSTD TRUE) + set(ZSTD_FOUND TRUE) + set(ZSTD_LIBRARIES zstd::zstd) + get_target_property(ZSTD_INCLUDE_DIRS ${ZSTD_LIBRARIES} INTERFACE_INCLUDE_DIRECTORIES) +endif() + +# minizip-ng otherwise uses system libraries when we provide them above +set(CMAKE_DISABLE_FIND_PACKAGE_PkgConfig TRUE) +set(PKGCONFIG_FOUND FALSE) + add_subdirectory(minizip-ng) dolphin_disable_warnings(minizip-ng) From 184c6ee068ed7de2c03b7c1426c0700bc20f696e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joshua=20Vanda=C3=ABle?= Date: Thu, 1 Jan 2026 22:26:53 +0100 Subject: [PATCH 3/5] cURL: Actually disable ZLIB/ZSTD cURL tries to find ZSTD anyways due to the lack of setting it in CACHE, and for both ZLIB and ZSTD if we had done find_package previously, cURL would still use ZLIB/ZSTD regardless of the set variable. --- Externals/curl/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Externals/curl/CMakeLists.txt b/Externals/curl/CMakeLists.txt index 55f010fb15..a391aab603 100644 --- a/Externals/curl/CMakeLists.txt +++ b/Externals/curl/CMakeLists.txt @@ -13,7 +13,9 @@ set(HTTP_ONLY ON) set(CURL_USE_LIBPSL OFF) set(CURL_USE_LIBSSH2 OFF) set(CURL_ZLIB OFF CACHE BOOL "" FORCE) -set(CURL_ZSTD OFF) +set(CURL_ZSTD OFF CACHE BOOL "" FORCE) +set(ZLIB_FOUND FALSE) # TODO: Remove once we update to cURL >=8.17.1 https://github.com/curl/curl/pull/20147 +set(ZSTD_FOUND FALSE) # TODO: Same as above set(USE_LIBIDN2 OFF) set(USE_NGHTTP2 OFF) From 3cea68c2e59f71a7b1e634fe31e7fd1dba670a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joshua=20Vanda=C3=ABle?= Date: Sat, 3 Jan 2026 12:47:30 +0100 Subject: [PATCH 4/5] LibUSB: Improve library detection Our FindLibUSB.cmake was previously entirely unused unless SDL was being built from Externals, we now rely on it again. It will use PkgConfig if applicable or fall back to looking around on the system, and more importantly it will always create an imported target. --- CMake/FindLibUSB.cmake | 31 ++++++++++++++++++------------- CMakeLists.txt | 4 +--- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CMake/FindLibUSB.cmake b/CMake/FindLibUSB.cmake index 5a6fc7197f..54403b7aec 100644 --- a/CMake/FindLibUSB.cmake +++ b/CMake/FindLibUSB.cmake @@ -11,8 +11,15 @@ if(ANDROID) set(LIBUSB_FOUND FALSE CACHE INTERNAL "libusb-1.0 found") message(STATUS "libusb-1.0 not found.") -elseif (NOT LIBUSB_FOUND) - pkg_check_modules (LIBUSB_PKG libusb-1.0) + return() +endif() + +if(TARGET LibUSB::LibUSB) + return() +endif() + +if(NOT LIBUSB_FOUND) + pkg_check_modules(LIBUSB_PKG libusb-1.0) find_path(LIBUSB_INCLUDE_DIR NAMES libusb.h PATHS @@ -30,21 +37,19 @@ elseif (NOT LIBUSB_FOUND) /usr/local/lib ) - if(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) - set(LIBUSB_FOUND TRUE CACHE INTERNAL "libusb-1.0 found") - message(STATUS "Found libusb-1.0: ${LIBUSB_INCLUDE_DIR}, ${LIBUSB_LIBRARIES}") - else(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) - set(LIBUSB_FOUND FALSE CACHE INTERNAL "libusb-1.0 found") - message(STATUS "libusb-1.0 not found.") - endif(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) - mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES) -endif () -if(LIBUSB_FOUND AND NOT TARGET LibUSB::LibUSB) +endif() + + +if(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) add_library(LibUSB::LibUSB UNKNOWN IMPORTED) set_target_properties(LibUSB::LibUSB PROPERTIES IMPORTED_LOCATION "${LIBUSB_LIBRARIES}" INTERFACE_INCLUDE_DIRECTORIES "${LIBUSB_INCLUDE_DIR}" ) + set(LIBUSB_FOUND TRUE CACHE INTERNAL "libusb-1.0 found") + message(STATUS "Found libusb-1.0: ${LIBUSB_INCLUDE_DIR}, ${LIBUSB_LIBRARIES}") +else() + set(LIBUSB_FOUND FALSE CACHE INTERNAL "libusb-1.0 found") + message(STATUS "libusb-1.0 not found.") endif() - diff --git a/CMakeLists.txt b/CMakeLists.txt index b3f27e994f..de9446014d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -708,9 +708,7 @@ if(ENABLE_CUBEB) endif() if(NOT ANDROID) - dolphin_find_optional_system_library_pkgconfig( - LibUSB libusb-1.0 LibUSB::LibUSB Externals/libusb - ) + dolphin_find_optional_system_library(LibUSB Externals/libusb) add_definitions(-D__LIBUSB__) endif() From c6411a29526df99d7baa6ed6b26441fb0ab14d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joshua=20Vanda=C3=ABle?= Date: Fri, 2 Jan 2026 14:40:24 +0100 Subject: [PATCH 5/5] SDL: Use bundled LibUSB when desirable Previously, SDL would `find_package(libusb)` which would actually overwrite the user preference in the case where both USE_SYSTEM_LIBUSB and USE_SYSTEM_SDL were OFF. This coincidentally also allows SDL to use libusb on Windows. --- CMakeLists.txt | 8 ++++---- Externals/SDL/CMakeLists.txt | 5 +++++ Externals/libusb/CMakeLists.txt | 13 ++++++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de9446014d..38135abda9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -582,10 +582,6 @@ if(UNIX) add_definitions(-DUSE_MEMORYWATCHER=1) endif() -if(ENABLE_SDL) - dolphin_find_optional_system_library(SDL3 Externals/SDL 3.2.0) -endif() - if(ENABLE_ANALYTICS) message(STATUS "Enabling analytics collection (subject to end-user opt-in)") add_definitions(-DUSE_ANALYTICS=1) @@ -712,6 +708,10 @@ if(NOT ANDROID) add_definitions(-D__LIBUSB__) endif() +if(ENABLE_SDL) + dolphin_find_optional_system_library(SDL3 Externals/SDL 3.2.0) +endif() + dolphin_find_optional_system_library(SFML Externals/SFML 3.0 COMPONENTS Network System) if(USE_UPNP) diff --git a/Externals/SDL/CMakeLists.txt b/Externals/SDL/CMakeLists.txt index 0316360241..6bdd630101 100644 --- a/Externals/SDL/CMakeLists.txt +++ b/Externals/SDL/CMakeLists.txt @@ -20,6 +20,11 @@ if(CCACHE_BIN) set(CCACHE_BINARY ${CCACHE_BIN}) endif() +if(LibUSB_TYPE STREQUAL Bundled) + set(LibUSB_FOUND TRUE) + set(SDL_HIDAPI_LIBUSB_SHARED OFF) +endif() + add_subdirectory(SDL) if (TARGET SDL3) diff --git a/Externals/libusb/CMakeLists.txt b/Externals/libusb/CMakeLists.txt index dafb563f72..ffd6d42781 100644 --- a/Externals/libusb/CMakeLists.txt +++ b/Externals/libusb/CMakeLists.txt @@ -125,4 +125,15 @@ check_include_files(sys/timerfd.h HAVE_TIMERFD) check_include_files(unistd.h HAVE_UNISTD_H) configure_file(config.h.in config.h) -add_library(LibUSB::LibUSB ALIAS usb) + +# We don't create an ALIAS here so that dependencies (SDL) that try_compile libusb +# don't fail due to LibUSB::LibUSB being an alias target +add_library(LibUSB::LibUSB INTERFACE IMPORTED GLOBAL) +target_link_libraries(LibUSB::LibUSB + INTERFACE + usb +) +target_include_directories(LibUSB::LibUSB + INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/libusb/libusb +)