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
7 # IOS_VERSION = last(default) or specific one (4.3, 5.0, 4.1)
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.
12 # IOS_PLATFORM = OS (default) or SIMULATOR or ALL
13 # This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders
14 # OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.
15 # SIMULATOR - used to build for the Simulator platforms, which have an x86 arch.
17 # CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder
18 # By default this location is automatcially chosen based on the IOS_PLATFORM value above.
19 # If set manually, it will override the default location and force the user of a particular Developer Platform
21 # CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
22 # By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
23 # In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path.
24 # If set manually, this will force the use of a specific SDK version
26 IF(DEFINED CMAKE_CROSSCOMPILING)
27 # subsequent toolchain loading is not really needed
32 SET(CMAKE_SYSTEM_NAME Darwin)
33 SET(CMAKE_SYSTEM_VERSION 1) # TODO: determine target Darwin version
39 IF(NOT DEFINED IOS_PLATFORM)
40 SET(IOS_PLATFORM "OS")
43 SET(IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
45 SET(IOS_PLATFORM_LOCATION "iPhoneOS.platform")
46 SET(IOS_SIMULATOR_PLATFORM_LOCATION "iPhoneSimulator.platform")
48 # Check the platform selection and setup for developer root
49 if(${IOS_PLATFORM} STREQUAL "OS")
50 # This causes the installers to properly locate the output libraries
51 set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
52 elseif(${IOS_PLATFORM} STREQUAL "SIMULATOR")
53 # This causes the installers to properly locate the output libraries
54 set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
55 elseif(${IOS_PLATFORM} STREQUAL "ALL")
56 # This causes the installers to properly locate the output libraries
57 set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator;-iphoneos")
59 message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
61 set (CMAKE_XCODE_EFFECTIVE_PLATFORMS ${CMAKE_XCODE_EFFECTIVE_PLATFORMS} CACHE PATH "iOS Platform")
63 # Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
64 # Note Xcode 4.3 changed the installation location, choose the most recent one available
65 SET(XCODE_DEFAULT_ROOT "/Applications/Xcode.app/Contents")
67 IF(NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
68 IF(NOT DEFINED CMAKE_XCODE_ROOT)
69 IF(EXISTS ${XCODE_DEFAULT_ROOT})
70 SET(CMAKE_XCODE_ROOT ${XCODE_DEFAULT_ROOT} CACHE STRING "Xcode root")
72 MESSAGE(FATAL_ERROR "Xcode directory ${XCODE_DEFAULT_ROOT} doesn't exist")
75 SET(TMP ${CMAKE_XCODE_ROOT}/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer)
77 SET(CMAKE_IOS_DEVELOPER_ROOT ${TMP})
78 MESSAGE(STATUS "Use iOS developer root: ${CMAKE_IOS_DEVELOPER_ROOT}")
80 SET(TMP ${CMAKE_XCODE_ROOT}/Developer/Platforms/${IOS_SIMULATOR_PLATFORM_LOCATION}/Developer)
82 SET(CMAKE_IOS_SIMULATOR_DEVELOPER_ROOT ${TMP})
83 MESSAGE(STATUS "Use iOS simulator developer root: ${CMAKE_IOS_SIMULATOR_DEVELOPER_ROOT}")
87 SET(CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
88 SET(CMAKE_IOS_SIMULATOR_DEVELOPER_ROOT ${CMAKE_IOS_SIMULATOR_DEVELOPER_ROOT} CACHE PATH "Location of iOS Simulator Platform")
90 MACRO(GET_AVAILABLE_SDK_VERSIONS ROOT VERSIONS)
91 FILE(GLOB _CMAKE_IOS_SDKS "${ROOT}/SDKs/iPhoneOS*")
93 LIST(SORT _CMAKE_IOS_SDKS)
94 LIST(REVERSE _CMAKE_IOS_SDKS)
95 FOREACH(_CMAKE_IOS_SDK ${_CMAKE_IOS_SDKS})
96 STRING(REGEX REPLACE ".+iPhoneOS([0-9.]+)\\.sdk" "\\1" _IOS_SDK "${_CMAKE_IOS_SDK}")
97 LIST(APPEND ${VERSIONS} ${_IOS_SDK})
102 # Find and use the most recent iOS sdk
103 IF(NOT DEFINED CMAKE_IOS_SDK_ROOT)
104 # Search for a specific version of a SDK
105 GET_AVAILABLE_SDK_VERSIONS(${CMAKE_IOS_DEVELOPER_ROOT} IOS_VERSIONS)
108 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.")
112 LIST(FIND IOS_VERSIONS "${IOS_VERSION}" _INDEX)
114 LIST(GET IOS_VERSIONS 0 IOS_SDK_VERSION)
116 SET(IOS_SDK_VERSION ${IOS_VERSION})
119 LIST(GET IOS_VERSIONS 0 IOS_VERSION)
120 SET(IOS_SDK_VERSION ${IOS_VERSION})
123 MESSAGE(STATUS "Target iOS ${IOS_VERSION} and use SDK ${IOS_SDK_VERSION}")
125 SET(CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/iPhoneOS${IOS_SDK_VERSION}.sdk)
126 SET(CMAKE_IOS_SIMULATOR_SDK_ROOT ${CMAKE_IOS_SIMULATOR_DEVELOPER_ROOT}/SDKs/iPhoneSimulator${IOS_SDK_VERSION}.sdk)
129 SET(CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
130 SET(CMAKE_IOS_SIMULATOR_SDK_ROOT ${CMAKE_IOS_SIMULATOR_SDK_ROOT} CACHE PATH "Location of the selected iOS Simulator SDK")
132 SET(IOS_VERSION ${IOS_VERSION} CACHE STRING "iOS target version")
134 # Set the sysroot default to the most recent SDK
135 SET(CMAKE_IOS_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
136 SET(CMAKE_IOS_SIMULATOR_SYSROOT ${CMAKE_IOS_SIMULATOR_SDK_ROOT} CACHE PATH "Sysroot used for iOS Simulator support")
138 IF(CMAKE_GENERATOR MATCHES Xcode)
139 IF(${IOS_PLATFORM} STREQUAL "OS")
140 SET(CMAKE_SYSTEM_PROCESSOR "arm64")
141 ELSEIF(${IOS_PLATFORM} STREQUAL "SIMULATOR")
142 SET(CMAKE_SYSTEM_PROCESSOR "x86_64")
143 ELSEIF(${IOS_PLATFORM} STREQUAL "ALL")
144 SET(CMAKE_SYSTEM_PROCESSOR "arm64")
147 IF(${IOS_PLATFORM} STREQUAL "OS")
148 SET(ARCHS armv7 arm64)
149 SET(CMAKE_SYSTEM_PROCESSOR "arm64")
150 ELSEIF(${IOS_PLATFORM} STREQUAL "SIMULATOR")
151 # iPhone simulator targets x86_64
153 SET(CMAKE_SYSTEM_PROCESSOR "x86")
154 ELSEIF(${IOS_PLATFORM} STREQUAL "ALL")
155 SET(ARCHS armv7 arm64 x86_64)
156 SET(CMAKE_SYSTEM_PROCESSOR "arm64")
160 # set the architecture for iOS - using ARCHS_STANDARD_32_BIT sets armv7,armv7s and appears to be XCode's standard.
161 # The other value that works is ARCHS_UNIVERSAL_IPHONE_OS but that sets armv7 only
163 SET(CMAKE_OSX_ARCHITECTURES ${ARCHS} CACHE STRING "Build architecture for iOS")
166 # Set the find root to the iOS developer roots and to user defined paths
167 SET(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} ${CMAKE_INSTALL_PREFIX} ${CMAKE_SOURCE_DIR}/external $ENV{EXTERNAL_IOS_PATH} CACHE STRING "iOS find search path root")
169 # default to searching for frameworks first
170 SET(CMAKE_FIND_FRAMEWORK FIRST)
172 # set up the default search directories for frameworks
173 SET(CMAKE_SYSTEM_FRAMEWORK_PATH
174 ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
175 ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
176 ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
179 # only search the iOS sdks, not the remainder of the host filesystem
180 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
181 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
182 SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
184 # Force the compilers to Clang for iOS
185 SET(CMAKE_C_COMPILER clang)
186 SET(CMAKE_CXX_COMPILER clang++)
188 # Skip the platform compiler checks for cross compiling.
189 SET(CMAKE_CXX_COMPILER_FORCED TRUE)
190 SET(CMAKE_C_COMPILER_FORCED TRUE)
192 # determinate location for bin utils based on CMAKE_FIND_ROOT_PATH
193 INCLUDE(CMakeFindBinUtils)