From 4ac10c4a9d47e6aea5f05bcf0127cb72c659303f Mon Sep 17 00:00:00 2001 From: Castor215 <132155746+Castor215@users.noreply.github.com> Date: Sun, 22 Oct 2023 00:10:02 +0100 Subject: [PATCH] externals: allow users to use system Zstandard (#7083) --- externals/CMakeLists.txt | 20 ++++++++++++++----- .../cmake-modules/CitraHandleSystemLibs.cmake | 3 +++ src/common/CMakeLists.txt | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index c86981f030..69f4f31078 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -211,11 +211,21 @@ if (ENABLE_LIBUSB AND NOT USE_SYSTEM_LIBUSB) endif() # Zstandard -set(ZSTD_LEGACY_SUPPORT OFF) -set(ZSTD_BUILD_PROGRAMS OFF) -set(ZSTD_BUILD_SHARED OFF) -add_subdirectory(zstd/build/cmake EXCLUDE_FROM_ALL) -target_include_directories(libzstd_static INTERFACE $) +if(USE_SYSTEM_ZSTD) + find_package(zstd REQUIRED) + add_library(zstd INTERFACE) + if(TARGET zstd::libzstd_shared) + message(STATUS "Found system Zstandard") + endif() + target_link_libraries(zstd INTERFACE zstd::libzstd_shared) +else() + set(ZSTD_LEGACY_SUPPORT OFF) + set(ZSTD_BUILD_PROGRAMS OFF) + set(ZSTD_BUILD_SHARED OFF) + add_subdirectory(zstd/build/cmake EXCLUDE_FROM_ALL) + target_include_directories(libzstd_static INTERFACE $) + add_library(zstd ALIAS libzstd_static) +endif() # ENet add_subdirectory(enet) diff --git a/externals/cmake-modules/CitraHandleSystemLibs.cmake b/externals/cmake-modules/CitraHandleSystemLibs.cmake index 4166e201b3..cbb80687d9 100644 --- a/externals/cmake-modules/CitraHandleSystemLibs.cmake +++ b/externals/cmake-modules/CitraHandleSystemLibs.cmake @@ -18,6 +18,7 @@ option(USE_SYSTEM_INIH "Use the system inih (instead of the bundled one)" OFF) option(USE_SYSTEM_FDK_AAC_HEADERS "Use the system fdk-aac headers (instead of the bundled one)" OFF) option(USE_SYSTEM_FFMPEG_HEADERS "Use the system FFmpeg headers (instead of the bundled one)" OFF) option(USE_SYSTEM_GLSLANG "Use the system glslang and SPIR-V libraries (instead of the bundled ones)" OFF) +option(USE_SYSTEM_ZSTD "Use the system Zstandard library (instead of the bundled one)" OFF) # Qt and MoltenVK are handled separately CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_SDL2 "Disable system SDL2" OFF "USE_SYSTEM_LIBS" OFF) @@ -35,6 +36,7 @@ CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_INIH "Disable system inih" OFF "USE_SYSTEM CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_FDK_AAC_HEADERS "Disable system fdk_aac" OFF "USE_SYSTEM_LIBS" OFF) CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_FFMPEG_HEADERS "Disable system ffmpeg" OFF "USE_SYSTEM_LIBS" OFF) CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_GLSLANG "Disable system glslang" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_ZSTD "Disable system Zstandard" OFF "USE_SYSTEM_LIBS" OFF) set(LIB_VAR_LIST SDL2 @@ -52,6 +54,7 @@ set(LIB_VAR_LIST FDK_AAC_HEADERS FFMPEG_HEADERS GLSLANG + ZSTD ) # First, check that USE_SYSTEM_XXX is not used with USE_SYSTEM_LIBS diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index e2ee678355..74a22e6b05 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -174,7 +174,7 @@ endif() create_target_directory_groups(citra_common) target_link_libraries(citra_common PUBLIC fmt library-headers microprofile Boost::boost Boost::serialization Boost::iostreams) -target_link_libraries(citra_common PRIVATE libzstd_static) +target_link_libraries(citra_common PRIVATE zstd) if ("x86_64" IN_LIST ARCHITECTURE) target_link_libraries(citra_common PRIVATE xbyak)