mirror of https://github.com/PCSX2/pcsx2.git
Optionally use system libs (#6094)
* CMake: Make zstd and libzip optionally use system-installed versions * CMake: Make SDL2 optionally use system version * CMake: Disable crypto support in bundled libzip * CMake: Fix bundled SDL build on macOS
This commit is contained in:
parent
cad85d76a5
commit
1afb248e4d
|
@ -92,7 +92,7 @@ jobs:
|
|||
run: .github/workflows/scripts/macos/build-dependencies.sh
|
||||
|
||||
- name: Generate CMake Files
|
||||
run: cmake -DCMAKE_PREFIX_PATH="$HOME/deps" -DCMAKE_BUILD_TYPE=Release -DUSE_OPENGL=OFF -DDISABLE_ADVANCE_SIMD=ON -DLTO_PCSX2_CORE=ON -B build .
|
||||
run: cmake -DCMAKE_PREFIX_PATH="$HOME/deps" -DCMAKE_BUILD_TYPE=Release -DUSE_OPENGL=OFF -DDISABLE_ADVANCE_SIMD=ON -DLTO_PCSX2_CORE=ON -DUSE_SYSTEM_LIBS=OFF -DUSE_SYSTEM_SDL2=ON -B build .
|
||||
|
||||
- name: Build PCSX2
|
||||
working-directory: build
|
||||
|
|
|
@ -27,6 +27,7 @@ cmake \
|
|||
-DOpenGL_GL_PREFERENCE="LEGACY" \
|
||||
-DOPENGL_opengl_LIBRARY="" \
|
||||
-DXDG_STD=TRUE \
|
||||
-DUSE_SYSTEM_ZSTD=FALSE \
|
||||
$ADDITIONAL_CMAKE_ARGS \
|
||||
-GNinja \
|
||||
-B build
|
||||
|
|
|
@ -5,6 +5,7 @@ set(ENABLE_COMMONCRYPTO OFF CACHE BOOL "")
|
|||
set(ENABLE_GNUTLS OFF CACHE BOOL "")
|
||||
set(ENABLE_MBEDTLS OFF CACHE BOOL "")
|
||||
set(ENABLE_WINDOWS_CRYPTO OFF CACHE BOOL "")
|
||||
set(ENABLE_OPENSSL OFF CACHE BOOL "")
|
||||
set(ENABLE_BZIP2 OFF CACHE BOOL "")
|
||||
set(ENABLE_LZMA OFF CACHE BOOL "")
|
||||
set(ENABLE_ZSTD ON CACHE BOOL "")
|
||||
|
|
|
@ -17,7 +17,7 @@ set(SDL_LIBSAMPLERATE OFF CACHE BOOL "")
|
|||
set(SDL_X11 OFF CACHE BOOL "")
|
||||
set(SDL_WAYLAND OFF CACHE BOOL "")
|
||||
set(SDL_RPI OFF CACHE BOOL "")
|
||||
set(SDL_COCOA OFF CACHE BOOL "")
|
||||
set(SDL_COCOA ON CACHE BOOL "")
|
||||
set(SDL_DIRECTX OFF CACHE BOOL "")
|
||||
set(SDL_WASAPI OFF CACHE BOOL "")
|
||||
set(SDL_RENDER_D3D OFF CACHE BOOL "")
|
||||
|
@ -33,7 +33,7 @@ set(SDL_STATIC ON CACHE BOOL "")
|
|||
# Subsystems
|
||||
set(SDL_ATOMIC ON CACHE BOOL "")
|
||||
set(SDL_AUDIO OFF CACHE BOOL "")
|
||||
set(SDL_VIDEO OFF CACHE BOOL "")
|
||||
set(SDL_VIDEO ON CACHE BOOL "")
|
||||
set(SDL_RENDER OFF CACHE BOOL "")
|
||||
set(SDL_EVENTS ON CACHE BOOL "")
|
||||
set(SDL_JOYSTICK ON CACHE BOOL "")
|
||||
|
|
|
@ -17,7 +17,12 @@ set(PCSX2_DEFS "")
|
|||
#-------------------------------------------------------------------------------
|
||||
option(DISABLE_BUILD_DATE "Disable including the binary compile date")
|
||||
option(ENABLE_TESTS "Enables building the unit tests" ON)
|
||||
option(USE_SYSTEM_YAML "Uses a system version of yaml, if found")
|
||||
set(USE_SYSTEM_LIBS "AUTO" CACHE STRING "Use system libraries instead of bundled libraries. ON - Always use system and fail if unavailable, OFF - Always use bundled, AUTO - Use system if available, otherwise use bundled. Default is AUTO")
|
||||
optional_system_library(fmt)
|
||||
optional_system_library(ryml)
|
||||
optional_system_library(zstd)
|
||||
optional_system_library(libzip)
|
||||
optional_system_library(SDL2)
|
||||
option(LTO_PCSX2_CORE "Enable LTO/IPO/LTCG on the subset of pcsx2 that benefits most from it but not anything else")
|
||||
|
||||
if(WIN32)
|
||||
|
|
|
@ -155,8 +155,10 @@ endfunction()
|
|||
# like add_library(new ALIAS old) but avoids add_library cannot create ALIAS target "new" because target "old" is imported but not globally visible. on older cmake
|
||||
function(alias_library new old)
|
||||
string(REPLACE "::" "" library_no_namespace ${old})
|
||||
add_library(_alias_${library_no_namespace} INTERFACE)
|
||||
target_link_libraries(_alias_${library_no_namespace} INTERFACE ${old})
|
||||
if (NOT TARGET _alias_${library_no_namespace})
|
||||
add_library(_alias_${library_no_namespace} INTERFACE)
|
||||
target_link_libraries(_alias_${library_no_namespace} INTERFACE ${old})
|
||||
endif()
|
||||
add_library(${new} ALIAS _alias_${library_no_namespace})
|
||||
endfunction()
|
||||
|
||||
|
@ -193,3 +195,37 @@ function(source_groups_from_vcxproj_filters file)
|
|||
source_group("${group}" FILES "${parent}/${path}")
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(optional_system_library library)
|
||||
string(TOUPPER ${library} upperlib)
|
||||
set(USE_SYSTEM_${upperlib} "" CACHE STRING "Use system ${library} instead of bundled. ON - Always use system and fail if unavailable, OFF - Always use bundled, AUTO - Use system if available, otherwise use bundled, blank - Delegate to USE_SYSTEM_LIBS. Default is blank.")
|
||||
if ("${USE_SYSTEM_${upperlib}}" STREQUAL "")
|
||||
set(RESOLVED_USE_SYSTEM_${upperlib} ${USE_SYSTEM_LIBS} PARENT_SCOPE)
|
||||
else()
|
||||
set(RESOLVED_USE_SYSTEM_${upperlib} ${USE_SYSTEM_${upperlib}} PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(find_optional_system_library library bundled_path)
|
||||
string(TOUPPER ${library} upperlib)
|
||||
if (RESOLVED_USE_SYSTEM_${upperlib})
|
||||
find_package(${library} ${ARGN} QUIET)
|
||||
if ((NOT ${library}_FOUND) AND (NOT ${RESOLVED_USE_SYSTEM_${upperlib}} STREQUAL "AUTO"))
|
||||
find_package(${library} ${ARGN}) # For the message
|
||||
message(FATAL_ERROR "No system ${library} was found. Please install it or set USE_SYSTEM_${upperlib} to AUTO.")
|
||||
endif()
|
||||
endif()
|
||||
if (${library}_FOUND)
|
||||
message("Found ${library}: ${${library}_VERSION}")
|
||||
set(${library}_TYPE "System" PARENT_SCOPE)
|
||||
else()
|
||||
if (${RESOLVED_USE_SYSTEM_${upperlib}} STREQUAL "AUTO")
|
||||
message("No system ${library} was found. Using bundled.")
|
||||
endif()
|
||||
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${bundled_path}/CMakeLists.txt")
|
||||
message(FATAL_ERROR "No bundled ${library} was found. Did you forget to checkout submodules?")
|
||||
endif()
|
||||
add_subdirectory(${bundled_path} EXCLUDE_FROM_ALL)
|
||||
set(${library}_TYPE "Bundled" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
|
|
@ -145,7 +145,7 @@ else()
|
|||
check_lib(SAMPLERATE samplerate samplerate.h)
|
||||
|
||||
if(NOT QT_BUILD)
|
||||
check_lib(SDL2 SDL2 SDL.h PATH_SUFFIXES SDL2)
|
||||
find_optional_system_library(SDL2 3rdparty/sdl2 2.0.12)
|
||||
endif()
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
|
@ -205,39 +205,14 @@ if((GCC_VERSION VERSION_EQUAL "9.0" OR GCC_VERSION VERSION_GREATER "9.0") AND GC
|
|||
This text being in a compile log in an open issue may cause it to be closed.")
|
||||
endif()
|
||||
|
||||
find_package(fmt "7.1.3" QUIET)
|
||||
if(NOT fmt_FOUND)
|
||||
if(EXISTS "${CMAKE_SOURCE_DIR}/3rdparty/fmt/fmt/CMakeLists.txt")
|
||||
message(STATUS "No system fmt was found. Using bundled")
|
||||
add_subdirectory(3rdparty/fmt/fmt)
|
||||
else()
|
||||
message(FATAL_ERROR "No system or bundled fmt was found")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Found fmt: ${fmt_VERSION}")
|
||||
find_optional_system_library(fmt 3rdparty/fmt/fmt 7.1.3)
|
||||
find_optional_system_library(ryml 3rdparty/rapidyaml/rapidyaml 0.4.0)
|
||||
find_optional_system_library(zstd 3rdparty/zstd 1.4.5)
|
||||
if (${zstd_TYPE} STREQUAL System)
|
||||
alias_library(Zstd::Zstd zstd::libzstd_shared)
|
||||
alias_library(pcsx2-zstd zstd::libzstd_shared)
|
||||
endif()
|
||||
|
||||
if(USE_SYSTEM_YAML)
|
||||
find_package(ryml REQUIRED)
|
||||
if(NOT ryml_FOUND)
|
||||
message(STATUS "No system rapidyaml was found, using the submodule in the 3rdparty directory")
|
||||
set(USE_SYSTEM_YAML OFF)
|
||||
else()
|
||||
message(STATUS "Found rapidyaml: ${rapidyaml_VERSION}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT USE_SYSTEM_YAML)
|
||||
if(EXISTS "${CMAKE_SOURCE_DIR}/3rdparty/rapidyaml/rapidyaml/CMakeLists.txt")
|
||||
message(STATUS "Using bundled rapidyaml")
|
||||
add_subdirectory(3rdparty/rapidyaml/rapidyaml EXCLUDE_FROM_ALL)
|
||||
else()
|
||||
message(FATAL_ERROR "No bundled rapidyaml was found")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# We could use a system version of zstd, but is it going to be recent enough?
|
||||
add_subdirectory(3rdparty/zstd EXCLUDE_FROM_ALL)
|
||||
find_optional_system_library(libzip 3rdparty/libzip 1.8.0)
|
||||
|
||||
if(QT_BUILD)
|
||||
# Default to bundled Qt6 for Windows.
|
||||
|
@ -249,7 +224,7 @@ if(QT_BUILD)
|
|||
find_package(Qt6 COMPONENTS CoreTools Core GuiTools Gui WidgetsTools Widgets Network LinguistTools REQUIRED)
|
||||
|
||||
# We use the bundled (latest) SDL version for Qt.
|
||||
add_subdirectory(3rdparty/sdl2 EXCLUDE_FROM_ALL)
|
||||
find_optional_system_library(SDL2 3rdparty/sdl2 2.0.22)
|
||||
endif()
|
||||
|
||||
add_subdirectory(3rdparty/lzma EXCLUDE_FROM_ALL)
|
||||
|
@ -266,7 +241,6 @@ endif()
|
|||
|
||||
add_subdirectory(3rdparty/simpleini EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(3rdparty/imgui EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(3rdparty/libzip EXCLUDE_FROM_ALL)
|
||||
|
||||
if(USE_OPENGL)
|
||||
add_subdirectory(3rdparty/glad EXCLUDE_FROM_ALL)
|
||||
|
|
|
@ -70,13 +70,13 @@ if(XDG_STD)
|
|||
target_compile_definitions(PCSX2_FLAGS INTERFACE XDG_STD)
|
||||
endif()
|
||||
|
||||
if(TARGET PkgConfig::SDL2 OR QT_BUILD)
|
||||
if(TARGET SDL2::SDL2 OR TARGET SDL2::SDL2-static)
|
||||
target_compile_definitions(PCSX2_FLAGS INTERFACE SDL_BUILD)
|
||||
if (QT_BUILD)
|
||||
if ("${SDL2_TYPE}" STREQUAL Bundled)
|
||||
# Use our in-tree SDL build.
|
||||
target_link_libraries(PCSX2_FLAGS INTERFACE SDL2::SDL2-static)
|
||||
else()
|
||||
target_link_libraries(PCSX2_FLAGS INTERFACE PkgConfig::SDL2)
|
||||
target_link_libraries(PCSX2_FLAGS INTERFACE SDL2::SDL2)
|
||||
endif()
|
||||
if(PCSX2_CORE)
|
||||
target_sources(PCSX2 PRIVATE
|
||||
|
@ -1602,7 +1602,7 @@ target_link_libraries(PCSX2_FLAGS INTERFACE
|
|||
fmt::fmt
|
||||
ryml
|
||||
chdr-static
|
||||
zip
|
||||
libzip::zip
|
||||
wxWidgets::all
|
||||
ZLIB::ZLIB
|
||||
PkgConfig::SOUNDTOUCH
|
||||
|
|
Loading…
Reference in New Issue