chore(cpn): improve SDL2 bundling and add SDL3 support for macOS builds (#7549)
Co-authored-by: Sergey Yugoman <sergey.yugoman@armenotech.com> Co-authored-by: Peter Feerick <5500713+pfeerick@users.noreply.github.com>
This commit is contained in:
co-authored by
Sergey Yugoman
Peter Feerick
parent
cffcbc42a8
commit
fcdf92d35b
@@ -570,12 +570,109 @@ elseif(APPLE)
|
||||
# Run macdeployqt
|
||||
install(SCRIPT ${qt_deploy_companion} COMPONENT Runtime)
|
||||
|
||||
# Bundle SDL2
|
||||
# Bundle SDL2 (copy the real dylib; IMPORTED_RUNTIME_ARTIFACTS keeps
|
||||
# Homebrew symlinks and breaks the app inside a .dmg). Homebrew's
|
||||
# sdl2-compat also loads SDL3 from @loader_path/libSDL3.dylib at runtime.
|
||||
if(TARGET SDL2::SDL2)
|
||||
install(IMPORTED_RUNTIME_ARTIFACTS SDL2::SDL2
|
||||
FRAMEWORK DESTINATION "${companion_app_dir}/Contents/Frameworks"
|
||||
LIBRARY DESTINATION "${companion_app_dir}/Contents/Frameworks"
|
||||
COMPONENT Runtime)
|
||||
get_target_property(_sdl2_location SDL2::SDL2 IMPORTED_LOCATION)
|
||||
if(NOT _sdl2_location)
|
||||
get_target_property(_sdl2_location SDL2::SDL2 IMPORTED_LOCATION_RELEASE)
|
||||
endif()
|
||||
if(_sdl2_location AND _sdl2_location MATCHES "\\.framework(/|$)")
|
||||
# Genuine upstream SDL2.framework (CI's setup-sdl2.sh, or a manual framework
|
||||
# install): no SDL3 dlopen shim to worry about, and IMPORTED_RUNTIME_ARTIFACTS
|
||||
# copies frameworks correctly — it's only the Homebrew dylib case below whose
|
||||
# symlinks it mangles. This is what CI has shipped all along.
|
||||
message(STATUS "Bundling SDL2 framework: ${_sdl2_location}")
|
||||
install(IMPORTED_RUNTIME_ARTIFACTS SDL2::SDL2
|
||||
FRAMEWORK DESTINATION "${companion_app_dir}/Contents/Frameworks"
|
||||
LIBRARY DESTINATION "${companion_app_dir}/Contents/Frameworks"
|
||||
COMPONENT Runtime)
|
||||
elseif(_sdl2_location)
|
||||
message(STATUS "Bundling SDL2 library: ${_sdl2_location}")
|
||||
get_filename_component(_sdl2_real "${_sdl2_location}" REALPATH)
|
||||
get_filename_component(_sdl2_name "${_sdl2_location}" NAME)
|
||||
install(FILES "${_sdl2_real}"
|
||||
DESTINATION "${companion_app_dir}/Contents/Frameworks"
|
||||
RENAME "${_sdl2_name}"
|
||||
COMPONENT Runtime)
|
||||
|
||||
set(_sdl3_real "")
|
||||
find_package(SDL3 CONFIG QUIET)
|
||||
if(TARGET SDL3::SDL3-shared)
|
||||
get_target_property(_sdl3_location SDL3::SDL3-shared IMPORTED_LOCATION_RELEASE)
|
||||
if(NOT _sdl3_location)
|
||||
get_target_property(_sdl3_location SDL3::SDL3-shared IMPORTED_LOCATION)
|
||||
endif()
|
||||
if(_sdl3_location)
|
||||
get_filename_component(_sdl3_real "${_sdl3_location}" REALPATH)
|
||||
endif()
|
||||
endif()
|
||||
if(NOT _sdl3_real)
|
||||
set(_sdl3_hints "")
|
||||
if(DEFINED ENV{HOMEBREW_PREFIX})
|
||||
list(APPEND _sdl3_hints
|
||||
"$ENV{HOMEBREW_PREFIX}/opt/sdl3/lib"
|
||||
"$ENV{HOMEBREW_PREFIX}/lib")
|
||||
endif()
|
||||
find_program(_brew_EXECUTABLE brew)
|
||||
if(_brew_EXECUTABLE)
|
||||
execute_process(
|
||||
COMMAND "${_brew_EXECUTABLE}" --prefix sdl3
|
||||
OUTPUT_VARIABLE _brew_sdl3_prefix
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE _brew_sdl3_result
|
||||
)
|
||||
if(_brew_sdl3_result EQUAL 0 AND _brew_sdl3_prefix)
|
||||
list(APPEND _sdl3_hints "${_brew_sdl3_prefix}/lib")
|
||||
endif()
|
||||
endif()
|
||||
find_library(_sdl3_library
|
||||
NAMES SDL3.0 SDL3
|
||||
HINTS ${_sdl3_hints}
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
if(NOT _sdl3_library)
|
||||
find_library(_sdl3_library NAMES SDL3.0 SDL3)
|
||||
endif()
|
||||
if(_sdl3_library)
|
||||
get_filename_component(_sdl3_real "${_sdl3_library}" REALPATH)
|
||||
endif()
|
||||
endif()
|
||||
if(_sdl3_real)
|
||||
install(FILES "${_sdl3_real}"
|
||||
DESTINATION "${companion_app_dir}/Contents/Frameworks"
|
||||
RENAME "libSDL3.dylib"
|
||||
COMPONENT Runtime)
|
||||
else()
|
||||
message(WARNING "SDL3 not found; packaged Companion may crash if linked against sdl2-compat")
|
||||
endif()
|
||||
|
||||
install(CODE "
|
||||
set(_fw \"\${CMAKE_INSTALL_PREFIX}/${companion_app_dir}/Contents/Frameworks\")
|
||||
execute_process(
|
||||
COMMAND install_name_tool -id \"@executable_path/../Frameworks/${_sdl2_name}\" \"\${_fw}/${_sdl2_name}\"
|
||||
RESULT_VARIABLE _sdl2_id_result
|
||||
ERROR_VARIABLE _sdl2_id_error
|
||||
)
|
||||
if(NOT _sdl2_id_result EQUAL 0)
|
||||
message(FATAL_ERROR \"install_name_tool failed for ${_sdl2_name}: \${_sdl2_id_error}\")
|
||||
endif()
|
||||
if(EXISTS \"\${_fw}/libSDL3.dylib\")
|
||||
execute_process(
|
||||
COMMAND install_name_tool -id \"@executable_path/../Frameworks/libSDL3.dylib\" \"\${_fw}/libSDL3.dylib\"
|
||||
RESULT_VARIABLE _sdl3_id_result
|
||||
ERROR_VARIABLE _sdl3_id_error
|
||||
)
|
||||
if(NOT _sdl3_id_result EQUAL 0)
|
||||
message(FATAL_ERROR \"install_name_tool failed for libSDL3.dylib: \${_sdl3_id_error}\")
|
||||
endif()
|
||||
endif()
|
||||
" COMPONENT Runtime)
|
||||
else()
|
||||
message(WARNING "SDL2::SDL2 has no IMPORTED_LOCATION; SDL2 will not be bundled")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Re-sign bundle after all contents are installed
|
||||
|
||||
Reference in New Issue
Block a user