toolchain-ios.cmake revision 3fdee359c9eee4d6c1d823b23f7f64631b5945f8
1# This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake
2# files which are included with CMake 2.8.4
3# It has been altered for iOS development
4
5# Options:
6#
7# IOS_PLATFORM = OS (default) or SIMULATOR
8#   This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders
9#   OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.
10#   SIMULATOR - used to build for the Simulator platforms, which have an x86 arch.
11#
12# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder
13#   By default this location is automatcially chosen based on the IOS_PLATFORM value above.
14#   If set manually, it will override the default location and force the user of a particular Developer Platform
15#
16# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
17#   By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
18#   In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path.
19#   If set manually, this will force the use of a specific SDK version
20
21# Standard settings
22set (CMAKE_SYSTEM_NAME Darwin)
23set (CMAKE_SYSTEM_VERSION 1)
24set (UNIX True)
25set (APPLE True)
26set (IOS True)
27
28# Required as of cmake 2.8.10
29set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
30
31# Determine the cmake host system version so we know where to find the iOS SDKs
32find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
33if (CMAKE_UNAME)
34	exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
35	string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
36endif ()
37
38# Force the compilers to gcc for iOS
39include (CMakeForceCompiler)
40CMAKE_FORCE_C_COMPILER ("clang" Clang)
41CMAKE_FORCE_CXX_COMPILER ("clang++" Clang++)
42
43# Skip the platform compiler checks for cross compiling
44set (CMAKE_CXX_COMPILER_WORKS TRUE)
45set (CMAKE_C_COMPILER_WORKS TRUE)
46
47# All iOS/Darwin specific settings - some may be redundant
48set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
49set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
50set (CMAKE_SHARED_MODULE_PREFIX "lib")
51set (CMAKE_SHARED_MODULE_SUFFIX ".so")
52set (CMAKE_MODULE_EXISTS 1)
53set (CMAKE_DL_LIBS "")
54
55set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
56set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
57set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
58set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
59
60# Hidden visibilty is required for cxx on iOS
61set (CMAKE_C_FLAGS_INIT "")
62set (CMAKE_CXX_FLAGS_INIT "-headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden")
63
64set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
65set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
66
67set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
68set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
69set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
70set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
71set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
72set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
73
74# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
75# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
76# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
77# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
78if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
79	find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
80endif ()
81
82# Setup iOS platform unless specified manually with IOS_PLATFORM
83if (NOT DEFINED IOS_PLATFORM)
84	set (IOS_PLATFORM "OS")
85endif ()
86set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
87
88# Check the platform selection and setup for developer root
89if (${IOS_PLATFORM} STREQUAL "OS")
90	set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
91
92	# This causes the installers to properly locate the output libraries
93	set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
94elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
95	set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
96
97	# This causes the installers to properly locate the output libraries
98	set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
99else ()
100	message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
101endif ()
102
103# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
104# Note Xcode 4.3 changed the installation location, choose the most recent one available
105set (XCODE_POST_43_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
106set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
107if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
108	if (EXISTS ${XCODE_POST_43_ROOT})
109		set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
110	elseif ()
111		set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
112	endif ()
113endif ()
114set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
115
116# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
117if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
118	file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
119	if (_CMAKE_IOS_SDKS)
120		list (SORT _CMAKE_IOS_SDKS)
121		list (REVERSE _CMAKE_IOS_SDKS)
122		list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
123	else ()
124		message (FATAL_ERROR "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.")
125	endif ()
126	message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
127endif ()
128set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
129
130# Set the sysroot default to the most recent SDK
131set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
132
133# set the architecture for iOS
134# NOTE: Currently both ARCHS_STANDARD_32_BIT and ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually
135if (${IOS_PLATFORM} STREQUAL "OS")
136	set (IOS_ARCH	armv7)
137#	set (IOS_ARCH	armv6 armv7 armv7s)
138	set (DE_CPU		"DE_CPU_ARM")
139else (${IOS_PLATFORM} STREQUAL "SIMULATOR")
140	set (IOS_ARCH	i386)
141	set (DE_CPU		"DE_CPU_X86")
142endif ()
143
144set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string  "Build architecture for iOS")
145
146# Set the find root to the iOS developer roots and to user defined paths
147set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string  "iOS find search path root")
148
149# default to searching for frameworks first
150set (CMAKE_FIND_FRAMEWORK FIRST)
151
152# set up the default search directories for frameworks
153set (CMAKE_SYSTEM_FRAMEWORK_PATH
154	${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
155	${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
156	${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
157)
158
159# only search the iOS sdks, not the remainder of the host filesystem
160set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
161set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
162set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
163
164# dE Defines - DE_CPU is set earlier
165set(DE_PTR_SIZE	4)
166set(DE_OS		"DE_OS_IOS")
167set(DE_COMPILER	"DE_COMPILER_CLANG")
168