Hi there!
I’m having some trouble building SDL2 with Vulkan support for iOS (and I think macOS as well?). My current setup is as follows:
macOS Mojave
SIP disabled (i.e. DYLD_LIBRARY_PATH
and such is available when using env
)
VulkanSDK installed (brew cask install vulkan-sdk
)
The following environment variables are set:
export VULKAN_SDK=/usr/local/Caskroom/vulkan-sdk/1.1.82.1/macOS
export VK_ICD_FILENAMES=$VULKAN_SDK/etc/vulkan/icd.d/MoltenVK_icd.json
export DYLD_LIBRARY_PATH=$VULKAN_SDK/lib
export VK_LAYER_PATH=$VULKAN_SDK/etc/vulkan/explicit_layer.d
export CFLAGS="-I/usr/local/Caskroom/vulkan-sdk/1.1.82.1/macOS/include"
export LDFLAGS="-L/usr/local/Caskroom/vulkan-sdk/1.1.82.1/macOS/lib"
I have tried a number of different variations with the above flags, but nothing seems to work. CMake itself has no problems finding Vulkan when using find_package(Vulkan)
.
I have tried building using both the iosbuild.sh
script and the bundled Xcode project. I have also tried building (for macOS) using the CMake build system, and I can’t get it to recognize that I have the Vulkan SDK installed either (always VIDEO_VULKAN (Wanted: ON): OFF
).
So I guess my question is, how are you supposed to build SDL2 with Vulkan support for iOS? I’ve tried everything I’ve found when searching around and reading the docs, and I’m starting to run of ideas here… I would really appreciate some help please.
So a quick update, after a couple of hours of testing stuff I think I have found a workaround.
First of, I changed the following lines in SDL_config_iphoneos.h
:
#if !TARGET_OS_SIMULATOR && !TARGET_CPU_ARM && ((__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 90000))
#define SDL_PLATFORM_SUPPORTS_METAL 1
#else
#define SDL_PLATFORM_SUPPORTS_METAL 0
#endif
to
#if !TARGET_OS_SIMULATOR && !TARGET_CPU_ARM && ((__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 90000))
#define SDL_PLATFORM_SUPPORTS_METAL 1
#else
#error "Broken build, need Metal in order to support Vulkan"
#define SDL_PLATFORM_SUPPORTS_METAL 0
#endif
This way I quickly get compile errors whenever SDL is built without Vulkan support. After this I tried changing various settings in the configure scripts when building with iosbuild.sh
and various settings in the xcode project when building with SDL.xcodeproj
.
The combination I finally got working was to build with the Xcode project (SDL.xcodeproj
), with the following changes:
- Change
iOS Deployment Target
to iOS 12.0
- Change
tvOS Deployment Target
to tvOS 12.0
- Build the
libSDL-iOS
target, the All-iOS
target gave compile errors
- Select
Generic iOS Device
as target platform
The output libSDL2.a
ends up in a build folder in ~/Library/Developer/Xcode/DerivedData/
, for me it was: ~/Library/Developer/Xcode/DerivedData/SDL-fxroinjqtfjbdnepvpfxwwxxeubu/Build/Products/Release-iphoneos
.
I feel like what I have done here is kinda a huge hack, and it would still be nice with some clarification on how you are supposed to do this.