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 or SIMULATOR64
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# IOS_ARCH = arm64 (default for OS), armv7, armv7s, i386 (default for SIMULATOR), x86_64 (default for SIMULATOR64)
13#
14# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder
15#   By default this location is automatcially chosen based on the IOS_PLATFORM value above.
16#   If set manually, it will override the default location and force the user of a particular Developer Platform
17#
18# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
19#   By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
20#   In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path.
21#   If set manually, this will force the use of a specific SDK version
22#
23# IOS_DISABLE_BITCODE - set to 1 if you want to disable bitcode generation
24
25# Standard settings
26set (CMAKE_SYSTEM_NAME Darwin)
27set (CMAKE_SYSTEM_VERSION 1)
28set (UNIX True)
29set (APPLE True)
30set (IOS True)
31
32# Required as of cmake 2.8.10
33set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
34
35# Determine the cmake host system version so we know where to find the iOS SDKs
36find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
37if (CMAKE_UNAME)
38	exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
39	string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
40endif (CMAKE_UNAME)
41
42
43set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
44set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
45
46set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
47set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
48set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
49set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
50
51if (NOT DEFINED IOS_DISABLE_BITCODE)
52	set (EMBED_OPTIONS "-fembed-bitcode")
53endif(NOT DEFINED IOS_DISABLE_BITCODE)
54
55if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR ENABLE_DEBUG)
56	set(IOS_DEBUG_OPTIONS "-glldb -gmodules")
57else()
58	set(IOS_DEBUG_OPTIONS "-fvisibility=hidden -fvisibility-inlines-hidden")
59endif()
60
61set (CMAKE_C_FLAGS_INIT "${IOS_DEBUG_OPTIONS} ${EMBED_OPTIONS}")
62set (CMAKE_CXX_FLAGS_INIT "${IOS_DEBUG_OPTIONS} ${EMBED_OPTIONS}")
63
64set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${EMBED_OPTIONS} ${CMAKE_C_LINK_FLAGS}")
65set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${EMBED_OPTIONS} ${CMAKE_CXX_LINK_FLAGS}")
66
67
68set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
69set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib")
70set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle")
71set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
72set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
73set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
74
75# Specify install_name_tool and pkg-config since it outside of SDK path and therefore can't be found by CMake
76if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
77	find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
78endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
79
80if (NOT DEFINED PKG_CONFIG_EXECUTABLE)
81	find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config)
82	if (DEFINED PKG_CONFIG_EXECUTABLE)
83		execute_process(COMMAND pkg-config --version OUTPUT_VARIABLE PKG_CONFIG_VERSION_STRING)
84	endif(DEFINED PKG_CONFIG_EXECUTABLE)
85endif(NOT DEFINED PKG_CONFIG_EXECUTABLE)
86
87
88# fffio Specify path to install shared library on device
89set (CMAKE_INSTALL_NAME_DIR  "@executable_path/Frameworks")
90set (CMAKE_BUILD_WITH_INSTALL_NAME_DIR TRUE)
91
92# Setup iOS platform unless specified manually with IOS_PLATFORM
93if (NOT DEFINED IOS_PLATFORM)
94	set (IOS_PLATFORM "OS")
95endif (NOT DEFINED IOS_PLATFORM)
96set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
97
98# Check the platform selection and setup for developer root
99if (${IOS_PLATFORM} STREQUAL OS)
100	set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
101
102	# This causes the installers to properly locate the output libraries
103	set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
104elseif (${IOS_PLATFORM} STREQUAL SIMULATOR)
105    set (SIMULATOR true)
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")
110elseif (${IOS_PLATFORM} STREQUAL SIMULATOR64)
111    set (SIMULATOR true)
112	set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
113
114	# This causes the installers to properly locate the output libraries
115	set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
116else (${IOS_PLATFORM} STREQUAL OS)
117	message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
118endif (${IOS_PLATFORM} STREQUAL OS)
119
120# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
121if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
122	exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR)
123	set (CMAKE_IOS_DEVELOPER_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
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
145if (NOT DEFINED IOS_ARCH)
146	if (${IOS_PLATFORM} STREQUAL OS)
147		set (IOS_ARCH arm64)
148	elseif (${IOS_PLATFORM} STREQUAL SIMULATOR)
149		set (IOS_ARCH i386)
150	elseif (${IOS_PLATFORM} STREQUAL SIMULATOR64)
151		set (IOS_ARCH x86_64)
152	endif (${IOS_PLATFORM} STREQUAL OS)
153endif(NOT DEFINED IOS_ARCH)
154set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE STRING "Build architecture for iOS")
155
156# Set the find root to the iOS developer roots and to user defined paths
157set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE STRING "iOS find search path root")
158
159# default to searching for frameworks first
160set (CMAKE_FIND_FRAMEWORK FIRST)
161
162# set up the default search directories for frameworks
163set (CMAKE_SYSTEM_FRAMEWORK_PATH
164	${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
165	${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
166	${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
167)
168
169# only search the iOS sdks, not the remainder of the host filesystem
170set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
171set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
172set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
173
174