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# Macros:
22#
23# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE)
24#  A convenience macro for setting xcode specific properties on targets
25#  example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1")
26#
27# find_host_package (PROGRAM ARGS)
28#  A macro used to find executable programs on the host system, not within the iOS environment.
29#  Thanks to the android-cmake project for providing the command
30
31# Standard settings
32set (CMAKE_SYSTEM_NAME Darwin)
33set (CMAKE_SYSTEM_VERSION 1)
34set (UNIX True)
35set (APPLE True)
36set (IOS True)
37
38# Required as of cmake 2.8.10
39set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
40
41# Determine the cmake host system version so we know where to find the iOS SDKs
42find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
43if (CMAKE_UNAME)
44	exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
45	string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
46endif (CMAKE_UNAME)
47
48# Force the compilers to clang for iOS
49include (CMakeForceCompiler)
50CMAKE_FORCE_C_COMPILER (/usr/bin/clang Apple)
51CMAKE_FORCE_CXX_COMPILER (/usr/bin/clang++ Apple)
52set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
53
54# Skip the platform compiler checks for cross compiling
55set (CMAKE_CXX_COMPILER_WORKS TRUE)
56set (CMAKE_C_COMPILER_WORKS TRUE)
57
58# All iOS/Darwin specific settings - some may be redundant
59set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
60set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
61set (CMAKE_SHARED_MODULE_PREFIX "lib")
62set (CMAKE_SHARED_MODULE_SUFFIX ".so")
63set (CMAKE_MODULE_EXISTS 1)
64set (CMAKE_DL_LIBS "")
65
66set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
67set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
68set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
69set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
70
71# Hidden visibilty is required for cxx on iOS
72set (CMAKE_C_FLAGS_INIT "")
73set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden -isysroot ${CMAKE_OSX_SYSROOT}")
74
75set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
76set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
77
78set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
79set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
80set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
81set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
82set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
83set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
84
85# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
86# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
87# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
88# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
89if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
90	find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
91endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
92
93# Setup iOS platform unless specified manually with IOS_PLATFORM
94if (NOT DEFINED IOS_PLATFORM)
95	set (IOS_PLATFORM "OS")
96endif (NOT DEFINED IOS_PLATFORM)
97set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
98
99# Check the platform selection and setup for developer root
100if (${IOS_PLATFORM} STREQUAL "OS")
101	set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
102
103	# This causes the installers to properly locate the output libraries
104	set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
105elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
106	set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
107
108	# This causes the installers to properly locate the output libraries
109	set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
110else (${IOS_PLATFORM} STREQUAL "OS")
111	message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
112endif (${IOS_PLATFORM} STREQUAL "OS")
113
114# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
115# Note Xcode 4.3 changed the installation location, choose the most recent one available
116set (XCODE_POST_43_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
117set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
118if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
119	if (EXISTS ${XCODE_POST_43_ROOT})
120		set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
121	elseif(EXISTS ${XCODE_PRE_43_ROOT})
122		set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
123	endif (EXISTS ${XCODE_POST_43_ROOT})
124endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
125set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
126
127# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
128if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
129	file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
130	if (_CMAKE_IOS_SDKS)
131		list (SORT _CMAKE_IOS_SDKS)
132		list (REVERSE _CMAKE_IOS_SDKS)
133		list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
134	else (_CMAKE_IOS_SDKS)
135		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.")
136	endif (_CMAKE_IOS_SDKS)
137	message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
138endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
139set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
140
141# Set the sysroot default to the most recent SDK
142set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
143
144# set the architecture for iOS
145# NOTE: Currently both ARCHS_STANDARD_32_BIT and ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually
146if (${IOS_PLATFORM} STREQUAL "OS")
147	set (IOS_ARCH armv6 armv7)
148else (${IOS_PLATFORM} STREQUAL "OS")
149	set (IOS_ARCH i386)
150endif (${IOS_PLATFORM} STREQUAL "OS")
151
152set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string  "Build architecture for iOS")
153
154# Set the find root to the iOS developer roots and to user defined paths
155set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string  "iOS find search path root")
156
157# default to searching for frameworks first
158set (CMAKE_FIND_FRAMEWORK FIRST)
159
160# set up the default search directories for frameworks
161set (CMAKE_SYSTEM_FRAMEWORK_PATH
162	${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
163	${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
164	${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
165)
166
167# only search the iOS sdks, not the remainder of the host filesystem
168set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
169set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
170set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
171
172
173# This little macro lets you set any XCode specific property
174macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
175	set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
176endmacro (set_xcode_property)
177
178
179# This macro lets you find executable programs on the host system
180macro (find_host_package)
181	set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
182	set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
183	set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
184	set (IOS FALSE)
185
186	find_package(${ARGN})
187
188	set (IOS TRUE)
189	set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
190	set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
191	set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
192endmacro (find_host_package)
193
194