···11+22+Building SDL2_gpu for iOS
33+-------------------------
44+55+Building for iOS takes a little extra effort. As of writing, CMake does not include explicit support for the iOS toolchain, so we have to use a toolchain file to specify the correct programs for CMake to use.
66+77+SDL_gpu includes a version of the ios-cmake toolchain file.
88+99+The FindSDL2.cmake script also does not handle locating the appropriate binaries for iOS (the default SDL framework does not include iOS).
1010+1111+You will need to build the SDL2 library for iOS first.
1212+1313+1414+Here's an example command line invokation of CMake for SDL_gpu. You may need to adjust the paths yourself.
1515+1616+mkdir ios-build
1717+cd ios-build
1818+cmake -DCMAKE_TOOLCHAIN_FILE=../scripts/ios-cmake/toolchain/iOS.cmake -DCMAKE_IOS_SDK_ROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk -DSDL2_LIBRARY=../../SDL2/lib/ios/libSDL2.a -DSDL2_INCLUDE_DIR=../../SDL2/include/SDL2 .. -G "Xcode"
1919+2020+The settings in CMakeLists.txt will automatically pick the OpenGL ES renderers for you. It will also disable building of the demos and tools.
2121+2222+If you do not get a message saying that the iOS default settings are being used, then the path to ios-cmake may be incorrect. You will have to delete the CMake cache files before trying again.
+143
scripts/ios-cmake/HOWTO.txt
···11+#summary Guide to the ios-cmake project
22+33+44+55+== Introduction ==
66+77+88+99+This project provides a simple iOS toolchain file that may be used with CMake to build libraries.
1010+1111+1212+1313+1414+1515+== Contents ==
1616+1717+1818+1919+ * [#Toolchain_file]
2020+2121+ * [#Sample_library]
2222+2323+ * [#Sample_application]
2424+2525+2626+2727+2828+2929+==Toolchain_file==
3030+3131+3232+3333+The toolchain is located in at toolchain/iOS.cmake location. Using the toolchain is quite straightforward. It only requires you to call CMake with:
3434+3535+3636+3737+{{{
3838+3939+cmake -DCMAKE_TOOLCHAIN_FILE=path/to/iOS.cmake -GXcode
4040+4141+}}}
4242+4343+4444+4545+*NOTE:* Since this toolchain by default builds both arm6 and arm7 fat libraries and applications, you need to use the Xcode generator. Makefiles currently do not work.
4646+4747+4848+4949+The iOS.cmake file only has a few different options, all of which are documented in the file itself.
5050+5151+5252+5353+5454+5555+===IOS_PLATFORM===
5656+5757+5858+5959+*Values:* OS (default) or SIMULATOR
6060+6161+6262+6363+This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders
6464+6565+ * OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.
6666+6767+ * SIMULATOR - used to build for the Simulator platforms, which have an x86 arch.
6868+6969+7070+7171+===CMAKE_IOS_DEVELOPER_ROOT===
7272+7373+7474+7575+*Values:* automatic(default) or /path/to/platform/ eveloper folder
7676+7777+7878+7979+By default this location is automatically chosen based on the IOS_PLATFORM value above. If set manually, it will override the default location and force the user of a particular Developer Platform
8080+8181+8282+8383+===CMAKE_IOS_SDK_ROOT===
8484+8585+8686+8787+*Values:* automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
8888+8989+9090+9191+By default this location is automatically chosen based on the CMAKE_IOS_DEVELOPER_ROOT value. In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path. If set manually, this will force the use of a specific SDK version
9292+9393+9494+9595+9696+9797+==Sample_library==
9898+9999+100100+101101+The iOS.cmake toolchain is great for building libraries.
102102+103103+104104+105105+A sample library is located in the samples/hello-lib location. It creates a small static sample library. You can build the library in the standard CMake way using a build subdirectory:
106106+107107+108108+109109+{{{
110110+111111+1. mkdir build.ios
112112+113113+2. cd build.ios
114114+115115+3. cmake -DCMAKE_TOOLCHAIN_FILE=../../../toolchains/iOS.cmake -GXcode ..
116116+117117+4a. Open XCode and build the install target or
118118+119119+4b. Simply type: xcodebuild -target install -configuration Debug
120120+121121+}}}
122122+123123+124124+125125+This will place the library and header file into the samples/hello-app folder.
126126+127127+128128+129129+130130+131131+==Sample_application==
132132+133133+134134+135135+The sample application is located in samples/hello-app. This application uses the library and headers from the hello-lib project which are automatically installed if you built the install target.
136136+137137+138138+139139+Simply open the included Xcode project and build the application for whichever platform you created the build-lib target for (OS or SIMULATOR). Note that you will need to sign the application to deploy it to a device.
140140+141141+142142+143143+*NOTE:* Building an iOS executable application strictly using cmake is not a great idea. There are a large number of options that need to be setup within XCode before a project can simply be deployed onto a device. The whole signing process is a good example. For this reason, we do not attempt to build the hello-app sample using cmake.
+5
scripts/ios-cmake/README.txt
···11+This project provides a simple iOS toolchain file that may be used with CMake to build libraries and setup applications. A couple of sample projects are included.
22+33+The iOS toolchain file was developed during the porting of the toadlet engine to iOS platforms. It is also used in that project.
44+55+See the included HOWTO.txt file for details.
···11+//
22+// Prefix header for all source files of the 'HelloApp' target in the 'HelloApp' project
33+//
44+55+#import <Availability.h>
66+77+#ifndef __IPHONE_3_0
88+#warning "This project uses features only available in iPhone SDK 3.0 and later."
99+#endif
1010+1111+#ifdef __OBJC__
1212+ #import <UIKit/UIKit.h>
1313+ #import <Foundation/Foundation.h>
1414+#endif
···11+# This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake
22+# files which are included with CMake 2.8.4
33+# It has been altered for iOS development
44+55+# Options:
66+#
77+# IOS_PLATFORM = OS (default) or SIMULATOR
88+# This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders
99+# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.
1010+# SIMULATOR - used to build for the Simulator platforms, which have an x86 arch.
1111+#
1212+# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder
1313+# By default this location is automatcially chosen based on the IOS_PLATFORM value above.
1414+# If set manually, it will override the default location and force the user of a particular Developer Platform
1515+#
1616+# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
1717+# By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
1818+# In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path.
1919+# If set manually, this will force the use of a specific SDK version
2020+2121+# Standard settings
2222+set (CMAKE_SYSTEM_NAME Darwin)
2323+set (CMAKE_SYSTEM_VERSION 1 )
2424+set (UNIX True)
2525+set (APPLE True)
2626+set (IOS True)
2727+2828+# Force the compilers to gcc for iOS
2929+include (CMakeForceCompiler)
3030+CMAKE_FORCE_C_COMPILER (gcc gcc)
3131+CMAKE_FORCE_CXX_COMPILER (g++ g++)
3232+3333+# Skip the platform compiler checks for cross compiling
3434+set (CMAKE_CXX_COMPILER_WORKS TRUE)
3535+set (CMAKE_C_COMPILER_WORKS TRUE)
3636+3737+# All iOS/Darwin specific settings - some may be redundant
3838+set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
3939+set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
4040+set (CMAKE_SHARED_MODULE_PREFIX "lib")
4141+set (CMAKE_SHARED_MODULE_SUFFIX ".so")
4242+set (CMAKE_MODULE_EXISTS 1)
4343+set (CMAKE_DL_LIBS "")
4444+4545+set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
4646+set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
4747+set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
4848+set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
4949+5050+# Hidden visibilty is required for cxx on iOS
5151+set (CMAKE_C_FLAGS "")
5252+set (CMAKE_CXX_FLAGS "-headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden")
5353+5454+set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
5555+set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
5656+5757+set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
5858+set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
5959+set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
6060+set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
6161+set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
6262+set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
6363+6464+# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
6565+# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
6666+# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
6767+# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
6868+if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
6969+ find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
7070+endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
7171+7272+# Setup iOS platform
7373+if (NOT DEFINED IOS_PLATFORM)
7474+ set (IOS_PLATFORM "OS")
7575+endif (NOT DEFINED IOS_PLATFORM)
7676+set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
7777+7878+# Check the platform selection and setup for developer root
7979+if (${IOS_PLATFORM} STREQUAL "OS")
8080+ set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
8181+elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
8282+ set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
8383+else (${IOS_PLATFORM} STREQUAL "OS")
8484+ message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
8585+endif (${IOS_PLATFORM} STREQUAL "OS")
8686+8787+# Setup iOS developer location
8888+if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
8989+ set (CMAKE_IOS_DEVELOPER_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
9090+endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
9191+set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
9292+9393+# Find and use the most recent iOS sdk
9494+if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
9595+ file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
9696+ if (_CMAKE_IOS_SDKS)
9797+ list (SORT _CMAKE_IOS_SDKS)
9898+ list (REVERSE _CMAKE_IOS_SDKS)
9999+ list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
100100+ else (_CMAKE_IOS_SDKS)
101101+ message (FATAL_ERROR "No iOS SDK's found in default seach path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.")
102102+ endif (_CMAKE_IOS_SDKS)
103103+ message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
104104+endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
105105+set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
106106+107107+# Set the sysroot default to the most recent SDK
108108+set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
109109+110110+# set the architecture for iOS - using ARCHS_STANDARD_32_BIT sets armv6,armv7 and appears to be XCode's standard.
111111+# The other value that works is ARCHS_UNIVERSAL_IPHONE_OS but that sets armv7 only
112112+set (CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_BIT)" CACHE string "Build architecture for iOS")
113113+114114+# Set the find root to the iOS developer roots and to user defined paths
115115+set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root")
116116+117117+# default to searching for frameworks first
118118+set (CMAKE_FIND_FRAMEWORK FIRST)
119119+120120+# set up the default search directories for frameworks
121121+set (CMAKE_SYSTEM_FRAMEWORK_PATH
122122+ ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
123123+ ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
124124+ ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
125125+)
126126+127127+# only search the iOS sdks, not the remainder of the host filesystem
128128+set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
129129+set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
130130+set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
131131+
+3-1
src/renderer_GLES_1.c
···12121313// Most of the code pulled in from here...
1414#define SDL_GPU_USE_GLES
1515-#define SDL_GPU_USE_ARRAY_PIPELINE
1615#define SDL_GPU_GL_TIER 2
1716#define SDL_GPU_GLES_MAJOR_VERSION 1
1717+1818+#define SDL_GPU_USE_ARRAY_PIPELINE
1919+#define SDL_GPU_DISABLE_TEXTURE_GETS
1820#define SDL_GPU_DISABLE_SHADERS
1921#define SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK
2022#define SDL_GPU_NO_VAO
+5-3
src/renderer_GLES_2.c
···13131414// Most of the code pulled in from here...
1515#define SDL_GPU_USE_GLES
1616+#define SDL_GPU_GL_TIER 3
1717+#define SDL_GPU_GLES_MAJOR_VERSION 2
1818+#define SDL_GPU_GLSL_VERSION 100
1919+1620#define SDL_GPU_USE_BUFFER_PIPELINE
1721#ifdef __IPHONEOS__
1822 #define SDL_GPU_USE_BUFFER_RESET
1923#endif
2024#define SDL_GPU_SKIP_ENABLE_TEXTURE_2D
2125#define SDL_GPU_ASSUME_SHADERS
2222-#define SDL_GPU_GL_TIER 3
2323-#define SDL_GPU_GLSL_VERSION 100
2424-#define SDL_GPU_GLES_MAJOR_VERSION 2
2626+#define SDL_GPU_DISABLE_TEXTURE_GETS
2527#define SDL_GPU_NO_VAO
26282729#include "renderer_GL_common.inl"