cmake: use genex to link with Apple Frameworks

This commit is contained in:
Anonymous Maarten 2024-07-26 18:16:58 +02:00
parent 538adc52d2
commit 37881b3150
2 changed files with 39 additions and 29 deletions

View File

@ -2347,77 +2347,80 @@ elseif(APPLE)
endif()
endif()
# Minimum version for $<LINK_LIBRARY:feature,library-list>
cmake_minimum_required(VERSION 3.24)
# Actually load the frameworks at the end so we don't duplicate include.
if(SDL_FRAMEWORK_COREVIDEO)
find_library(COREMEDIA CoreMedia)
if(COREMEDIA)
sdl_link_dependency(corevideo LINK_OPTIONS "-Wl,-framework,CoreMedia")
sdl_link_dependency(corevideo LIBS "$<LINK_LIBRARY:FRAMEWORK,CoreMedia>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,CoreMedia")
endif()
sdl_link_dependency(corevideo LINK_OPTIONS "-Wl,-framework,CoreVideo")
sdl_link_dependency(corevideo LIBS "$<LINK_LIBRARY:FRAMEWORK,CoreVideo>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,CoreVideo")
endif()
if(SDL_FRAMEWORK_COCOA)
sdl_link_dependency(cocoa LINK_OPTIONS "-Wl,-framework,Cocoa")
sdl_link_dependency(cocoa LIBS "$<LINK_LIBRARY:FRAMEWORK,Cocoa>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,Cocoa")
endif()
if(SDL_FRAMEWORK_IOKIT)
sdl_link_dependency(iokit LINK_OPTIONS "-Wl,-framework,IOKit")
sdl_link_dependency(iokit LIBS "$<LINK_LIBRARY:FRAMEWORK,IOKit>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,IOKit")
endif()
if(SDL_FRAMEWORK_FF)
sdl_link_dependency(ff LINK_OPTIONS "-Wl,-framework,ForceFeedback")
sdl_link_dependency(ff LIBS "$<LINK_LIBRARY:FRAMEWORK,ForceFeedback>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,ForceFeedback")
endif()
if(SDL_FRAMEWORK_CARBON)
sdl_link_dependency(carbon LINK_OPTIONS "-Wl,-framework,Carbon")
sdl_link_dependency(carbon LIBS "$<LINK_LIBRARY:FRAMEWORK,Carbon>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,Carbon")
endif()
if(SDL_FRAMEWORK_COREAUDIO)
sdl_link_dependency(core_audio LINK_OPTIONS "-Wl,-framework,CoreAudio")
sdl_link_dependency(core_audio LIBS "$<LINK_LIBRARY:FRAMEWORK,CoreAudio>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,CoreAudio")
endif()
if(SDL_FRAMEWORK_AUDIOTOOLBOX)
sdl_link_dependency(audio_toolbox LINK_OPTIONS "-Wl,-framework,AudioToolbox")
sdl_link_dependency(audio_toolbox LIBS "$<LINK_LIBRARY:FRAMEWORK,AudioToolbox>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,AudioToolbox")
endif()
if(SDL_FRAMEWORK_AVFOUNDATION)
sdl_link_dependency(av_foundation LINK_OPTIONS "-Wl,-framework,AVFoundation")
sdl_link_dependency(av_foundation LIBS "$<LINK_LIBRARY:FRAMEWORK,AVFoundation>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,AVFoundation")
endif()
if(SDL_FRAMEWORK_COREBLUETOOTH)
sdl_link_dependency(core_bluetooth LINK_OPTIONS "-Wl,-framework,CoreBluetooth")
sdl_link_dependency(core_bluetooth LIBS "$<LINK_LIBRARY:FRAMEWORK,CoreBluetooth>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,CoreBluetooth")
endif()
if(SDL_FRAMEWORK_COREGRAPHICS)
sdl_link_dependency(core_graphics LINK_OPTIONS "-Wl,-framework,CoreGraphics")
sdl_link_dependency(core_graphics LIBS "$<LINK_LIBRARY:FRAMEWORK,CoreGraphics>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,CoreGraphics")
endif()
if(SDL_FRAMEWORK_COREMOTION)
sdl_link_dependency(core_motion LINK_OPTIONS "-Wl,-framework,CoreMotion")
sdl_link_dependency(core_motion LIBS "$<LINK_LIBRARY:FRAMEWORK,CoreMotion>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,CoreMotion")
endif()
if(SDL_FRAMEWORK_FOUNDATION)
sdl_link_dependency(foundation LINK_OPTIONS "-Wl,-framework,Foundation")
sdl_link_dependency(foundation LIBS "$<LINK_LIBRARY:FRAMEWORK,Foundation>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,Foundation")
endif()
if(SDL_FRAMEWORK_GAMECONTROLLER)
find_library(GAMECONTROLLER GameController)
if(GAMECONTROLLER)
sdl_link_dependency(game_controller LINK_OPTIONS "-Wl,-weak_framework,GameController")
sdl_link_dependency(game_controller LIBS "$<LINK_LIBRARY:WEAK_FRAMEWORK,GameController>" PKG_CONFIG_LINK_OPTIONS "-Wl,-weak_framework,GameController")
endif()
endif()
if(SDL_FRAMEWORK_METAL)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
sdl_link_dependency(metal LINK_OPTIONS "-Wl,-framework,Metal")
sdl_link_dependency(metal LIBS "$<LINK_LIBRARY:FRAMEWORK,Metal>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,Metal")
else()
sdl_link_dependency(metal LINK_OPTIONS "-Wl,-weak_framework,Metal")
sdl_link_dependency(metal LIBS "$<LINK_LIBRARY:WEAK_FRAMEWORK,Metal>" PKG_CONFIG_LINK_OPTIONS "-Wl,-weak_framework,Metal")
endif()
endif()
if(SDL_FRAMEWORK_OPENGLES)
sdl_link_dependency(opengles LINK_OPTIONS "-Wl,-framework,OpenGLES")
sdl_link_dependency(opengles LIBS "$<LINK_LIBRARY:FRAMEWORK,OpenGLES>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,OpenGLES")
endif()
if(SDL_FRAMEWORK_QUARTZCORE)
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
sdl_link_dependency(quartz_core LINK_OPTIONS "-Wl,-framework,QuartzCore")
sdl_link_dependency(quartz_core LIBS "$<LINK_LIBRARY:FRAMEWORK,QuartzCore>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,QuartzCore")
else()
sdl_link_dependency(metal LINK_OPTIONS "-Wl,-weak_framework,QuartzCore")
sdl_link_dependency(metal LIBS "$<LINK_LIBRARY:WEAK_FRAMEWORK,QuartzCore>" PKG_CONFIG_LINK_OPTIONS "-Wl,-weak_framework,QuartzCore")
endif()
endif()
if(SDL_FRAMEWORK_UIKIT)
sdl_link_dependency(ui_kit LINK_OPTIONS "-Wl,-framework,UIKit")
sdl_link_dependency(ui_kit LIBS "$<LINK_LIBRARY:FRAMEWORK,UIKit>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,UIKit")
endif()
if(SDL_FRAMEWORK_COREHAPTICS)
find_library(COREHAPTICS CoreHaptics)
if(COREHAPTICS)
sdl_link_dependency(core_haptics LINK_OPTIONS "-Wl,-framework,CoreHaptics")
sdl_link_dependency(core_haptics LIBS "$<LINK_LIBRARY:FRAMEWORK,CoreHaptics>" PKG_CONFIG_LINK_OPTIONS "-Wl,-framework,CoreHaptics")
endif()
endif()
@ -2885,7 +2888,7 @@ if (SDL_DIALOG)
set(HAVE_SDL_DIALOG TRUE)
elseif(MACOS)
sdl_sources(${SDL3_SOURCE_DIR}/src/dialog/cocoa/SDL_cocoadialog.m)
sdl_link_dependency(uniformtypeidentifiers LINK_OPTIONS "-Wl,-weak_framework,UniformTypeIdentifiers")
sdl_link_dependency(uniformtypeidentifiers LIBS "$<LINK_LIBRARY:WEAK_FRAMEWORK,UniformTypeIdentifiers>" PKG_CONFIG_LINK_OPTIONS "-Wl,-weak_framework,UniformTypeIdentifiers")
set(HAVE_SDL_DIALOG TRUE)
endif()
endif()

View File

@ -28,7 +28,7 @@ function(sdl_sources)
set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_SOURCES ${ARGS_SHARED} ${ARGS_STATIC} ${ARGS_UNPARSED_ARGUMENTS})
endfunction()
# Use sdl_generic_link_dependency to describe a private dependency of SDL3. All options are optional.
# Use sdl_generic_link_dependency to describe a private dependency. All options are optional.
# Users should use sdl_link_dependency and sdl_test_link_dependency instead
# - SHARED_TARGETS: shared targets to add this dependency to
# - STATIC_TARGETS: static targets to add this dependency to
@ -36,12 +36,13 @@ endfunction()
# - INCLUDES: the include directories of the dependency
# - PKG_CONFIG_PREFIX: name of the prefix, when using the functions of FindPkgConfig
# - PKG_CONFIG_SPECS: pkg-config spec, used as argument for the functions of FindPkgConfig
# - PKG_CONFIG_LIBS: libs that will only end up in the Libs.private of sdl3.pc
# - PKG_CONFIG_LIBS: libs that will only end up in the Libs.private of the .pc file
# - PKG_CONFIG_LINK_OPTIONS: ldflags that will only end up in the Libs.private of sdl3.pc
# - CMAKE_MODULE: CMake module name of the dependency, used as argument of find_package
# - LIBS: list of libraries to link to
# - LINK_OPTIONS: list of link options
# - LIBS: list of libraries to link to (cmake and pkg-config)
# - LINK_OPTIONS: list of link options (also used in pc file, unless PKG_CONFIG_LINK_OPTION is used)
function(sdl_generic_link_dependency ID)
cmake_parse_arguments(ARGS "" "COLLECTOR" "SHARED_TARGETS;STATIC_TARGETS;INCLUDES;PKG_CONFIG_LIBS;PKG_CONFIG_PREFIX;PKG_CONFIG_SPECS;CMAKE_MODULE;LIBS;LINK_OPTIONS" ${ARGN})
cmake_parse_arguments(ARGS "" "COLLECTOR" "SHARED_TARGETS;STATIC_TARGETS;INCLUDES;PKG_CONFIG_LINK_OPTIONS;PKG_CONFIG_LIBS;PKG_CONFIG_PREFIX;PKG_CONFIG_SPECS;CMAKE_MODULE;LIBS;LINK_OPTIONS" ${ARGN})
foreach(target IN LISTS ARGS_SHARED_TARGETS)
if(TARGET ${target})
target_include_directories(${target} SYSTEM PRIVATE ${ARGS_INCLUDES})
@ -63,6 +64,7 @@ function(sdl_generic_link_dependency ID)
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_PREFIX ${ARGS_PKG_CONFIG_PREFIX})
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_SPECS ${ARGS_PKG_CONFIG_SPECS})
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_LIBS ${ARGS_PKG_CONFIG_LIBS})
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_LINK_OPTIONS ${ARGS_PKG_CONFIG_LINK_OPTIONS})
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_LIBS ${ARGS_LIBS})
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_LINK_OPTIONS ${ARGS_LINK_OPTIONS})
set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE ${ARGS_CMAKE_MODULE})
@ -294,14 +296,19 @@ function(configure_sdl3_pc)
get_property(CMAKE_MODULE TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE)
get_property(PKG_CONFIG_SPECS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_SPECS)
get_property(PKG_CONFIG_LIBS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_LIBS)
get_property(PKG_CONFIG_LDFLAGS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_LINK_OPTIONS)
get_property(LIBS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_LIBS)
get_property(LINK_OPTIONS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_LINK_OPTIONS)
list(APPEND private_requires ${PKG_CONFIG_SPECS})
list(APPEND private_libs ${PKG_CONFIG_LIBS})
if(NOT PKG_CONFIG_SPECS AND NOT CMAKE_MODULE)
list(APPEND private_libs ${LIBS})
if(PKG_CONFIG_SPECS OR PKG_CONFIG_LIBS OR PKG_CONFIG_LDFLAGS)
list(APPEND private_ldflags ${PKG_CONFIG_LDFLAGS})
else()
list(APPEND private_ldflags ${LINK_OPTIONS})
if(NOT CMAKE_MODULE)
list(APPEND private_libs ${LIBS})
endif()
endif()
endforeach()