yuzu-emu
/
yuzu
Archived
1
0
Fork 0

Merge pull request #6833 from abouvier/unbundle

cmake: prefer system libraries
This commit is contained in:
liamwhite 2022-12-05 12:26:09 -05:00 committed by GitHub
commit 3b19f741bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 209 additions and 86 deletions

View File

@ -43,8 +43,6 @@ option(ENABLE_CUBEB "Enables the cubeb audio backend" ON)
option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF)
option(YUZU_USE_BUNDLED_OPUS "Compile bundled opus" ON)
option(YUZU_TESTS "Compile tests" ON)
option(YUZU_USE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
@ -201,24 +199,39 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
# System imported libraries
# =======================================================================
find_package(fmt 8.0.1 REQUIRED CONFIG)
find_package(nlohmann_json 3.8 REQUIRED CONFIG)
find_package(enet 1.3)
find_package(fmt 9 REQUIRED)
find_package(inih)
find_package(lz4 1.8 REQUIRED)
find_package(nlohmann_json 3.8 REQUIRED)
find_package(Opus 1.3)
find_package(Vulkan 1.3.213)
find_package(ZLIB 1.2 REQUIRED)
find_package(zstd 1.5 REQUIRED)
# Search for config-only package first (for vcpkg), then try non-config
find_package(zstd 1.5 CONFIG)
if (NOT zstd_FOUND)
find_package(zstd 1.5 REQUIRED)
if (ARCHITECTURE_x86 OR ARCHITECTURE_x86_64)
find_package(xbyak 6)
endif()
# lz4 1.8 is required, but vcpkg's lz4-config.cmake does not have version info
find_package(lz4 CONFIG)
if (NOT lz4_FOUND)
find_package(lz4 1.8 REQUIRED)
if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
find_package(dynarmic 6.2.4)
endif()
if (ENABLE_CUBEB)
find_package(cubeb)
endif()
if (USE_DISCORD_PRESENCE)
find_package(DiscordRPC)
endif()
if (ENABLE_WEB_SERVICE)
find_package(cpp-jwt 1.4)
find_package(httplib 0.11)
endif()
if (YUZU_TESTS)
find_package(Catch2 2.13.7 REQUIRED CONFIG)
find_package(Catch2 2.13.7 REQUIRED)
endif()
find_package(Boost 1.73.0 COMPONENTS context)

View File

@ -6,15 +6,16 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/externals/find-modules")
include(DownloadExternals)
# xbyak
if (ARCHITECTURE_x86 OR ARCHITECTURE_x86_64)
if ((ARCHITECTURE_x86 OR ARCHITECTURE_x86_64) AND NOT TARGET xbyak::xbyak)
add_subdirectory(xbyak EXCLUDE_FROM_ALL)
endif()
# Dynarmic
if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
if ((ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64) AND NOT TARGET dynarmic::dynarmic)
set(DYNARMIC_NO_BUNDLED_FMT ON)
set(DYNARMIC_IGNORE_ASSERTS ON CACHE BOOL "" FORCE)
add_subdirectory(dynarmic)
add_subdirectory(dynarmic EXCLUDE_FROM_ALL)
add_library(dynarmic::dynarmic ALIAS dynarmic)
endif()
# getopt
@ -26,7 +27,9 @@ endif()
add_subdirectory(glad)
# inih
add_subdirectory(inih)
if (NOT TARGET inih::INIReader)
add_subdirectory(inih)
endif()
# mbedtls
add_subdirectory(mbedtls EXCLUDE_FROM_ALL)
@ -72,25 +75,30 @@ if (YUZU_USE_EXTERNAL_SDL2)
endif()
# ENet
add_subdirectory(enet)
target_include_directories(enet INTERFACE ./enet/include)
if (NOT TARGET enet::enet)
add_subdirectory(enet EXCLUDE_FROM_ALL)
target_include_directories(enet INTERFACE ./enet/include)
add_library(enet::enet ALIAS enet)
endif()
# Cubeb
if(ENABLE_CUBEB)
if (ENABLE_CUBEB AND NOT TARGET cubeb::cubeb)
set(BUILD_TESTS OFF CACHE BOOL "")
add_subdirectory(cubeb EXCLUDE_FROM_ALL)
add_library(cubeb::cubeb ALIAS cubeb)
endif()
# DiscordRPC
if (USE_DISCORD_PRESENCE)
if (USE_DISCORD_PRESENCE AND NOT TARGET DiscordRPC::discord-rpc)
add_subdirectory(discord-rpc EXCLUDE_FROM_ALL)
target_include_directories(discord-rpc INTERFACE ./discord-rpc/include)
add_library(DiscordRPC::discord-rpc ALIAS discord-rpc)
endif()
# Sirit
add_subdirectory(sirit)
add_subdirectory(sirit EXCLUDE_FROM_ALL)
if (ENABLE_WEB_SERVICE)
if (ENABLE_WEB_SERVICE AND NOT TARGET httplib::httplib)
if (NOT WIN32)
find_package(OpenSSL 1.1)
if (OPENSSL_FOUND)
@ -118,18 +126,20 @@ if (ENABLE_WEB_SERVICE)
if (WIN32)
target_link_libraries(httplib INTERFACE crypt32 cryptui ws2_32)
endif()
add_library(httplib::httplib ALIAS httplib)
endif()
# cpp-jwt
# cpp-jwt
if (ENABLE_WEB_SERVICE AND NOT TARGET cpp-jwt::cpp-jwt)
add_library(cpp-jwt INTERFACE)
target_include_directories(cpp-jwt INTERFACE ./cpp-jwt/include)
target_compile_definitions(cpp-jwt INTERFACE CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
add_library(cpp-jwt::cpp-jwt ALIAS cpp-jwt)
endif()
# Opus
if (YUZU_USE_BUNDLED_OPUS)
if (NOT TARGET Opus::opus)
add_subdirectory(opus EXCLUDE_FROM_ALL)
else()
find_package(Opus 1.3 REQUIRED)
endif()
# FFMpeg
@ -140,3 +150,8 @@ if (YUZU_USE_BUNDLED_FFMPEG)
set(FFmpeg_LIBRARIES "${FFmpeg_LIBRARIES}" PARENT_SCOPE)
set(FFmpeg_INCLUDE_DIR "${FFmpeg_INCLUDE_DIR}" PARENT_SCOPE)
endif()
# Vulkan-Headers
if (NOT TARGET Vulkan::Headers)
add_subdirectory(Vulkan-Headers EXCLUDE_FROM_ALL)
endif()

View File

@ -0,0 +1,27 @@
# SPDX-FileCopyrightText: 2022 Alexandre Bouvier <contact@amb.tf>
#
# SPDX-License-Identifier: GPL-3.0-or-later
find_path(DiscordRPC_INCLUDE_DIR discord_rpc.h)
find_library(DiscordRPC_LIBRARY discord-rpc)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(DiscordRPC
REQUIRED_VARS
DiscordRPC_LIBRARY
DiscordRPC_INCLUDE_DIR
)
if (DiscordRPC_FOUND AND NOT TARGET DiscordRPC::discord-rpc)
add_library(DiscordRPC::discord-rpc UNKNOWN IMPORTED)
set_target_properties(DiscordRPC::discord-rpc PROPERTIES
IMPORTED_LOCATION "${DiscordRPC_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${DiscordRPC_INCLUDE_DIR}"
)
endif()
mark_as_advanced(
DiscordRPC_INCLUDE_DIR
DiscordRPC_LIBRARY
)

17
externals/find-modules/Findenet.cmake vendored Normal file
View File

@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2022 Alexandre Bouvier <contact@amb.tf>
#
# SPDX-License-Identifier: GPL-3.0-or-later
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_search_module(ENET QUIET IMPORTED_TARGET GLOBAL libenet)
if (ENET_FOUND)
add_library(enet::enet ALIAS PkgConfig::ENET)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(enet
REQUIRED_VARS ENET_LINK_LIBRARIES
VERSION_VAR ENET_VERSION
)

View File

@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 2022 Andrea Pappacoda <andrea@pappacoda.it>
#
# SPDX-License-Identifier: GPL-2.0-or-later
include(FindPackageHandleStandardArgs)
find_package(httplib QUIET CONFIG)
if (httplib_FOUND)
find_package_handle_standard_args(httplib CONFIG_MODE)
else()
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_search_module(HTTPLIB QUIET IMPORTED_TARGET GLOBAL cpp-httplib)
if (HTTPLIB_FOUND)
add_library(httplib::httplib ALIAS PkgConfig::HTTPLIB)
endif()
endif()
find_package_handle_standard_args(httplib
REQUIRED_VARS HTTPLIB_INCLUDEDIR
VERSION_VAR HTTPLIB_VERSION
)
endif()

17
externals/find-modules/Findinih.cmake vendored Normal file
View File

@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2022 Alexandre Bouvier <contact@amb.tf>
#
# SPDX-License-Identifier: GPL-3.0-or-later
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_search_module(INIREADER QUIET IMPORTED_TARGET GLOBAL INIReader)
if (INIREADER_FOUND)
add_library(inih::INIReader ALIAS PkgConfig::INIREADER)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(inih
REQUIRED_VARS INIREADER_LINK_LIBRARIES
VERSION_VAR INIREADER_VERSION
)

View File

@ -1,19 +1,30 @@
# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_search_module(liblz4 IMPORTED_TARGET GLOBAL liblz4)
if (liblz4_FOUND)
add_library(lz4::lz4 ALIAS PkgConfig::liblz4)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(lz4
REQUIRED_VARS
liblz4_LINK_LIBRARIES
liblz4_FOUND
VERSION_VAR liblz4_VERSION
)
find_package(lz4 QUIET CONFIG)
if (lz4_FOUND)
find_package_handle_standard_args(lz4 CONFIG_MODE)
if (NOT TARGET lz4::lz4)
if (TARGET LZ4::lz4_shared)
set_target_properties(LZ4::lz4_shared PROPERTIES IMPORTED_GLOBAL TRUE)
add_library(lz4::lz4 ALIAS LZ4::lz4_shared)
else()
set_target_properties(LZ4::lz4_static PROPERTIES IMPORTED_GLOBAL TRUE)
add_library(lz4::lz4 ALIAS LZ4::lz4_static)
endif()
endif()
else()
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_search_module(liblz4 QUIET IMPORTED_TARGET GLOBAL liblz4)
if (liblz4_FOUND)
add_library(lz4::lz4 ALIAS PkgConfig::liblz4)
endif()
endif()
find_package_handle_standard_args(lz4
REQUIRED_VARS liblz4_LINK_LIBRARIES
VERSION_VAR liblz4_VERSION
)
endif()

View File

@ -1,19 +1,30 @@
# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_search_module(libzstd IMPORTED_TARGET GLOBAL libzstd)
if (libzstd_FOUND)
add_library(zstd::zstd ALIAS PkgConfig::libzstd)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(zstd
REQUIRED_VARS
libzstd_LINK_LIBRARIES
libzstd_FOUND
VERSION_VAR libzstd_VERSION
)
find_package(zstd QUIET CONFIG)
if (zstd_FOUND)
find_package_handle_standard_args(zstd CONFIG_MODE)
if (NOT TARGET zstd::zstd)
if (TARGET zstd::libzstd_shared)
set_target_properties(zstd::libzstd_shared PROPERTIES IMPORTED_GLOBAL TRUE)
add_library(zstd::zstd ALIAS zstd::libzstd_shared)
else()
set_target_properties(zstd::libzstd_static PROPERTIES IMPORTED_GLOBAL TRUE)
add_library(zstd::zstd ALIAS zstd::libzstd_static)
endif()
endif()
else()
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_search_module(libzstd QUIET IMPORTED_TARGET GLOBAL libzstd)
if (libzstd_FOUND)
add_library(zstd::zstd ALIAS PkgConfig::libzstd)
endif()
endif()
find_package_handle_standard_args(zstd
REQUIRED_VARS libzstd_LINK_LIBRARIES
VERSION_VAR libzstd_VERSION
)
endif()

View File

@ -9,4 +9,5 @@ add_library(inih
)
create_target_directory_groups(inih)
target_include_directories(inih INTERFACE .)
target_include_directories(inih INTERFACE inih/cpp)
add_library(inih::INIReader ALIAS inih)

View File

@ -219,11 +219,11 @@ endif()
target_link_libraries(audio_core PUBLIC common core)
if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
target_link_libraries(audio_core PRIVATE dynarmic)
target_link_libraries(audio_core PRIVATE dynarmic::dynarmic)
endif()
if(ENABLE_CUBEB)
target_link_libraries(audio_core PRIVATE cubeb)
target_link_libraries(audio_core PRIVATE cubeb::cubeb)
target_compile_definitions(audio_core PRIVATE -DHAVE_CUBEB=1)
endif()
if(ENABLE_SDL2)

View File

@ -149,7 +149,7 @@ if(ARCHITECTURE_x86_64)
x64/xbyak_abi.h
x64/xbyak_util.h
)
target_link_libraries(common PRIVATE xbyak)
target_link_libraries(common PRIVATE xbyak::xbyak)
endif()
if (MSVC)
@ -174,17 +174,7 @@ endif()
create_target_directory_groups(common)
target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile Threads::Threads)
if (TARGET lz4::lz4)
target_link_libraries(common PRIVATE lz4::lz4)
else()
target_link_libraries(common PRIVATE LZ4::lz4_shared)
endif()
if (TARGET zstd::zstd)
target_link_libraries(common PRIVATE zstd::zstd)
else()
target_link_libraries(common PRIVATE
$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)
endif()
target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd)
if (YUZU_USE_PRECOMPILED_HEADERS)
target_precompile_headers(common PRIVATE precompiled_headers.h)

View File

@ -824,7 +824,7 @@ if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
hle/service/jit/jit.cpp
hle/service/jit/jit.h
)
target_link_libraries(core PRIVATE dynarmic)
target_link_libraries(core PRIVATE dynarmic::dynarmic)
endif()
if (YUZU_USE_PRECOMPILED_HEADERS)

View File

@ -19,7 +19,7 @@ add_library(network STATIC
create_target_directory_groups(network)
target_link_libraries(network PRIVATE common enet Boost::boost)
target_link_libraries(network PRIVATE common enet::enet Boost::boost)
if (ENABLE_WEB_SERVICE)
target_compile_definitions(network PRIVATE -DENABLE_WEB_SERVICE)
target_link_libraries(network PRIVATE web_service)

View File

@ -264,8 +264,7 @@ target_link_options(video_core PRIVATE ${FFmpeg_LDFLAGS})
add_dependencies(video_core host_shaders)
target_include_directories(video_core PRIVATE ${HOST_SHADERS_INCLUDE})
target_include_directories(video_core PRIVATE sirit ../../externals/Vulkan-Headers/include)
target_link_libraries(video_core PRIVATE sirit)
target_link_libraries(video_core PRIVATE sirit Vulkan::Headers)
if (ENABLE_NSIGHT_AFTERMATH)
if (NOT DEFINED ENV{NSIGHT_AFTERMATH_SDK})
@ -305,11 +304,11 @@ if (ARCHITECTURE_x86_64)
macro/macro_jit_x64.cpp
macro/macro_jit_x64.h
)
target_link_libraries(video_core PUBLIC xbyak)
target_link_libraries(video_core PUBLIC xbyak::xbyak)
endif()
if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
target_link_libraries(video_core PRIVATE dynarmic)
target_link_libraries(video_core PRIVATE dynarmic::dynarmic)
endif()
if (YUZU_USE_PRECOMPILED_HEADERS)

View File

@ -17,7 +17,7 @@ add_library(web_service STATIC
)
create_target_directory_groups(web_service)
target_link_libraries(web_service PRIVATE common network nlohmann_json::nlohmann_json httplib cpp-jwt)
target_link_libraries(web_service PRIVATE common network nlohmann_json::nlohmann_json httplib::httplib cpp-jwt::cpp-jwt)
if (YUZU_USE_PRECOMPILED_HEADERS)
target_precompile_headers(web_service PRIVATE precompiled_headers.h)

View File

@ -318,7 +318,7 @@ target_link_libraries(yuzu PRIVATE common core input_common network video_core)
target_link_libraries(yuzu PRIVATE Boost::boost glad Qt${QT_MAJOR_VERSION}::Widgets)
target_link_libraries(yuzu PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads)
target_include_directories(yuzu PRIVATE ../../externals/Vulkan-Headers/include)
target_link_libraries(yuzu PRIVATE Vulkan::Headers)
if (NOT WIN32)
target_include_directories(yuzu PRIVATE ${Qt${QT_MAJOR_VERSION}Gui_PRIVATE_INCLUDE_DIRS})
endif()
@ -354,7 +354,7 @@ if (USE_DISCORD_PRESENCE)
discord_impl.cpp
discord_impl.h
)
target_link_libraries(yuzu PRIVATE discord-rpc)
target_link_libraries(yuzu PRIVATE DiscordRPC::discord-rpc)
target_compile_definitions(yuzu PRIVATE -DUSE_DISCORD_PRESENCE)
endif()
@ -411,7 +411,7 @@ if (NOT APPLE)
endif()
if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
target_link_libraries(yuzu PRIVATE dynarmic)
target_link_libraries(yuzu PRIVATE dynarmic::dynarmic)
endif()
if (YUZU_USE_PRECOMPILED_HEADERS)

View File

@ -34,7 +34,7 @@ add_executable(yuzu-cmd
create_target_directory_groups(yuzu-cmd)
target_link_libraries(yuzu-cmd PRIVATE common core input_common)
target_link_libraries(yuzu-cmd PRIVATE inih glad)
target_link_libraries(yuzu-cmd PRIVATE inih::INIReader glad)
if (MSVC)
target_link_libraries(yuzu-cmd PRIVATE getopt)
endif()
@ -43,7 +43,7 @@ target_link_libraries(yuzu-cmd PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads)
create_resource("../../dist/yuzu.bmp" "yuzu_cmd/yuzu_icon.h" "yuzu_icon")
target_include_directories(yuzu-cmd PRIVATE ${RESOURCES_DIR})
target_include_directories(yuzu-cmd PRIVATE ../../externals/Vulkan-Headers/include)
target_link_libraries(yuzu-cmd PRIVATE Vulkan::Headers)
if (YUZU_USE_EXTERNAL_SDL2)
target_link_libraries(yuzu-cmd PRIVATE SDL2-static)

View File

@ -15,7 +15,7 @@
#pragma clang diagnostic pop
#endif
#include <inih/cpp/INIReader.h>
#include <INIReader.h>
#include "common/fs/file.h"
#include "common/fs/fs.h"
#include "common/fs/path_util.h"