Allow usage of system SDL2 on macOS

This commit is contained in:
Caleb Xu 2023-05-05 17:17:45 -04:00
parent fea78f93b2
commit 8ef17b1662
No known key found for this signature in database
GPG Key ID: 47E6040D07B8407D

View File

@ -102,6 +102,13 @@ if(ANDROID OR WIN32 OR (UNIX AND NOT ARM_NO_VULKAN))
set(VULKAN ON)
endif()
# Default to bundled SDL2 on macOS, system SDL2 elsewhere.
if(APPLE AND NOT IOS)
set(DEFAULT_USE_SYSTEM_LIBSDL2 OFF)
else()
set(DEFAULT_USE_SYSTEM_LIBSDL2 ON)
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
if(NOT IOS)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/sdl)
@ -157,7 +164,7 @@ option(USE_ARMIPS "Build with armips support in API/debugger" ON)
option(USE_SYSTEM_SNAPPY "Dynamically link against system snappy" ${USE_SYSTEM_SNAPPY})
option(USE_SYSTEM_FFMPEG "Dynamically link against system FFMPEG" ${USE_SYSTEM_FFMPEG})
option(USE_SYSTEM_LIBZIP "Dynamically link against system libzip" ${USE_SYSTEM_LIBZIP})
option(USE_SYSTEM_LIBSDL2 "Dynamically link against system SDL2" ON) # Ignored on Mac
option(USE_SYSTEM_LIBSDL2 "Dynamically link against system SDL2" ${DEFAULT_USE_SYSTEM_LIBSDL2})
option(USE_SYSTEM_LIBPNG "Dynamically link against system libpng" ON)
option(USE_SYSTEM_ZSTD "Dynamically link against system zstd" ${USE_SYSTEM_ZSTD})
option(USE_SYSTEM_MINIUPNPC "Dynamically link against system miniUPnPc" ${USE_SYSTEM_MINIUPNPC})
@ -242,9 +249,13 @@ if(NOT LIBRETRO AND NOT IOS AND NOT MACOSX)
endif()
if(MACOSX AND NOT IOS)
find_library(SDL2Fwk SDL2 REQUIRED PATHS SDL/macOS)
message(STATUS "found SDL2Fwk=${SDL2Fwk}")
add_definitions(-DHAVE_SYSCTLBYNAME)
if(USE_SYSTEM_LIBSDL2)
find_package(SDL2)
else()
find_library(SDL2Fwk SDL2 REQUIRED PATHS SDL/macOS)
message(STATUS "found SDL2Fwk=${SDL2Fwk}")
add_definitions(-DHAVE_SYSCTLBYNAME)
endif()
endif()
include(FindThreads)
@ -1297,7 +1308,12 @@ else()
set_source_files_properties(SDL/PPSSPPAboutViewController.m PROPERTIES COMPILE_FLAGS -fobjc-arc)
set_source_files_properties(Common/Battery/AppleBatteryClient.m PROPERTIES COMPILE_FLAGS -fobjc-arc)
set(nativeExtraLibs ${nativeExtraLibs} ${COCOA_LIBRARY} ${QUARTZ_CORE_LIBRARY} ${IOKIT_LIBRARY})
set(nativeExtraLibs ${nativeExtraLibs} ${SDL2Fwk})
if(USE_SYSTEM_LIBSDL2)
set(nativeExtraLibs ${nativeExtraLibs} SDL2::SDL2)
else()
set(nativeExtraLibs ${nativeExtraLibs} ${SDL2Fwk})
endif()
elseif(USING_EGL)
set(nativeExtraLibs ${nativeExtraLibs} pthread SDL2::SDL2)
else()
@ -2558,7 +2574,7 @@ if(TargetBin)
file(INSTALL "${CMAKE_SOURCE_DIR}/ext/vulkan/macOS/Frameworks/libMoltenVK.dylib" DESTINATION "${CMAKE_BINARY_DIR}/${TargetBin}.app/Contents/Frameworks/")
if(USING_QT_UI)
add_custom_command(TARGET ${TargetBin} POST_BUILD COMMAND /bin/bash "${CMAKE_SOURCE_DIR}/Qt/macbundle.sh" "${CMAKE_BINARY_DIR}/PPSSPPQt.app")
else()
elseif(NOT USE_SYSTEM_LIBSDL2)
add_custom_command(TARGET ${TargetBin} POST_BUILD COMMAND /bin/bash "${CMAKE_SOURCE_DIR}/SDL/macbundle.sh" "${CMAKE_BINARY_DIR}/${TargetBin}.app" "${TargetBin}")
endif()
endif()