diff --git a/Xcode/SDL/pkg-support/resources/CMake/SDL3Config.cmake b/Xcode/SDL/pkg-support/resources/CMake/SDL3Config.cmake index 784d27dbb018c..796166535e15c 100644 --- a/Xcode/SDL/pkg-support/resources/CMake/SDL3Config.cmake +++ b/Xcode/SDL/pkg-support/resources/CMake/SDL3Config.cmake @@ -1,8 +1,9 @@ # SDL3 CMake configuration file: -# This file is meant to be placed in Resources/CMake of a SDL3 framework +# This file is meant to be placed in Resources/CMake of a SDL3 framework for macOS, +# or in the CMake directory of a SDL3 framework for iOS / tvOS / visionOS. # INTERFACE_LINK_OPTIONS needs CMake 3.12 -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.12...4.0) include(FeatureSummary) set_package_properties(SDL3 PROPERTIES @@ -31,16 +32,31 @@ endmacro() set(SDL3_FOUND TRUE) -# Compute the installation prefix relative to this file. -set(_sdl3_framework_path "${CMAKE_CURRENT_LIST_DIR}") # > /SDL3.framework/Resources/CMake/ -get_filename_component(_sdl3_framework_path "${_sdl3_framework_path}" REALPATH) # > /SDL3.framework/Versions/Current/Resources/CMake -get_filename_component(_sdl3_framework_path "${_sdl3_framework_path}" REALPATH) # > /SDL3.framework/Versions/A/Resources/CMake/ -get_filename_component(_sdl3_framework_path "${_sdl3_framework_path}" PATH) # > /SDL3.framework/Versions/A/Resources/ -get_filename_component(_sdl3_framework_path "${_sdl3_framework_path}" PATH) # > /SDL3.framework/Versions/A/ -get_filename_component(_sdl3_framework_path "${_sdl3_framework_path}" PATH) # > /SDL3.framework/Versions/ -get_filename_component(_sdl3_framework_path "${_sdl3_framework_path}" PATH) # > /SDL3.framework/ -get_filename_component(_sdl3_framework_parent_path "${_sdl3_framework_path}" PATH) # > / +# Compute the installation prefix relative to this file: +# search upwards for the .framework directory +set(_current_path "${CMAKE_CURRENT_LIST_DIR}") +get_filename_component(_current_path "${_current_path}" REALPATH) +set(_sdl3_framework_path "") +while(NOT _sdl3_framework_path) + if(IS_DIRECTORY "${_current_path}" AND "${_current_path}" MATCHES "/SDL3\\.framework$") + set(_sdl3_framework_path "${_current_path}") + break() + endif() + get_filename_component(_next_current_path "${_current_path}" DIRECTORY) + if("${_current_path}" STREQUAL "${_next_current_path}") + break() + endif() + set(_current_path "${_next_current_path}") +endwhile() +unset(_current_path) +unset(_next_current_path) + +if(NOT _sdl3_framework_path) + message(FATAL_ERROR "Could not find SDL3.framework root from ${CMAKE_CURRENT_LIST_DIR}") +endif() + +get_filename_component(_sdl3_framework_parent_path "${_sdl3_framework_path}" PATH) # All targets are created, even when some might not be requested though COMPONENTS. # This is done for compatibility with CMake generated SDL3-target.cmake files. diff --git a/Xcode/SDL/pkg-support/resources/CMake/SDL3ConfigVersion.cmake b/Xcode/SDL/pkg-support/resources/CMake/SDL3ConfigVersion.cmake index 74329c438b81c..77188b7f42c01 100644 --- a/Xcode/SDL/pkg-support/resources/CMake/SDL3ConfigVersion.cmake +++ b/Xcode/SDL/pkg-support/resources/CMake/SDL3ConfigVersion.cmake @@ -1,16 +1,26 @@ # based on the files generated by CMake's write_basic_package_version_file # SDL CMake version configuration file: -# This file is meant to be placed in Resources/CMake of a SDL3 framework +# This file is meant to be placed in Resources/CMake of a SDL3 framework for macOS, +# or in the CMake directory of a SDL3 framework for iOS / tvOS / visionOS. -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.12...4.0) -if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../Headers/SDL_version.h") - message(AUTHOR_WARNING "Could not find SDL_version.h. This script is meant to be placed in the Resources/CMake directory of SDL2.framework") +# Find SDL_version.h +set(_sdl_version_h_path "") +if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../Headers/SDL_version.h") + set(_sdl_version_h_path "${CMAKE_CURRENT_LIST_DIR}/../../Headers/SDL_version.h") +elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../Headers/SDL_version.h") + set(_sdl_version_h_path "${CMAKE_CURRENT_LIST_DIR}/../Headers/SDL_version.h") +endif() + +if(NOT _sdl_version_h_path) + message(AUTHOR_WARNING "Could not find SDL_version.h. This script is meant to be placed in the Resources/CMake directory or the CMake directory of SDL3.framework.") + set(PACKAGE_VERSION_UNSUITABLE TRUE) return() endif() -file(READ "${CMAKE_CURRENT_LIST_DIR}/../../Headers/SDL_version.h" _sdl_version_h) +file(READ "${_sdl_version_h_path}" _sdl_version_h) string(REGEX MATCH "#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)" _sdl_major_re "${_sdl_version_h}") set(_sdl_major "${CMAKE_MATCH_1}") string(REGEX MATCH "#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)" _sdl_minor_re "${_sdl_version_h}") @@ -24,6 +34,7 @@ else() return() endif() +unset(_sdl_version_h_path) unset(_sdl_major_re) unset(_sdl_major) unset(_sdl_minor_re)