4 # David Turner, Robert Wilhelm, and Werner Lemberg.
6 # Written by David Wimsey <david@wimsey.us>
8 # This file is part of the FreeType project, and may only be used, modified,
9 # and distributed under the terms of the FreeType project license,
10 # LICENSE.TXT. By continuing to use, modify, or distribute this file you
11 # indicate that you have read the license and understand and accept it
15 # This file is derived from the files `Platform/Darwin.cmake' and
16 # `Platform/UnixPaths.cmake', which are part of CMake 2.8.4. It has been
17 # altered for iOS development.
23 # IOS_PLATFORM = OS | SIMULATOR
25 # This decides whether SDKS are selected from the `iPhoneOS.platform' or
26 # `iPhoneSimulator.platform' folders.
28 # OS - the default, used to build for iPhone and iPad physical devices,
29 # which have an ARM architecture.
30 # SIMULATOR - used to build for the Simulator platforms, which have an
33 # CMAKE_IOS_DEVELOPER_ROOT = /path/to/platform/Developer folder
35 # By default, this location is automatically chosen based on the
36 # IOS_PLATFORM value above. If you manually set this variable, it
37 # overrides the default location and forces the use of a particular
40 # CMAKE_IOS_SDK_ROOT = /path/to/platform/Developer/SDKs/SDK folder
42 # By default, this location is automatically chosen based on the
43 # CMAKE_IOS_DEVELOPER_ROOT value. In this case it is always the most
44 # up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path. If you
45 # manually set this variable, it forces the use of a specific SDK
52 # set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE)
54 # A convenience macro for setting Xcode specific properties on targets.
58 # set_xcode_property(myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1")
60 # find_host_package (PROGRAM ARGS)
62 # A macro to find executable programs on the host system, not within the
63 # iOS environment. Thanks to the `android-cmake' project for providing
68 set(CMAKE_SYSTEM_NAME Darwin)
69 set(CMAKE_SYSTEM_VERSION 1)
74 # required as of cmake 2.8.10
75 set(CMAKE_OSX_DEPLOYMENT_TARGET ""
76 CACHE STRING "Force unset of the deployment target for iOS" FORCE
79 # determine the cmake host system version so we know where to find the iOS
81 find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
83 exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
84 string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1"
85 DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
88 # force the compilers to gcc for iOS
89 include(CMakeForceCompiler)
90 CMAKE_FORCE_C_COMPILER(gcc gcc)
91 CMAKE_FORCE_CXX_COMPILER(g++ g++)
93 # skip the platform compiler checks for cross compiling
94 set(CMAKE_CXX_COMPILER_WORKS TRUE)
95 set(CMAKE_C_COMPILER_WORKS TRUE)
97 # all iOS/Darwin specific settings - some may be redundant
98 set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
99 set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
100 set(CMAKE_SHARED_MODULE_PREFIX "lib")
101 set(CMAKE_SHARED_MODULE_SUFFIX ".so")
102 set(CMAKE_MODULE_EXISTS 1)
103 set(CMAKE_DL_LIBS "")
105 set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG
106 "-compatibility_version ")
107 set(CMAKE_C_OSX_CURRENT_VERSION_FLAG
109 set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG
110 "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
111 set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG
112 "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
114 # hidden visibility is required for cxx on iOS
115 set(CMAKE_C_FLAGS_INIT "")
116 set(CMAKE_CXX_FLAGS_INIT
117 "-headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden")
119 set(CMAKE_C_LINK_FLAGS
120 "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
121 set(CMAKE_CXX_LINK_FLAGS
122 "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
124 set(CMAKE_PLATFORM_HAS_INSTALLNAME 1)
125 set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS
126 "-dynamiclib -headerpad_max_install_names")
127 set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
128 "-bundle -headerpad_max_install_names")
129 set(CMAKE_SHARED_MODULE_LOADER_C_FLAG
130 "-Wl,-bundle_loader,")
131 set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG
132 "-Wl,-bundle_loader,")
133 set(CMAKE_FIND_LIBRARY_SUFFIXES
136 # hack: If a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old
137 # build tree (where `install_name_tool' was hardcoded), and where
138 # CMAKE_INSTALL_NAME_TOOL isn't in the cache and still cmake didn't
139 # fail in `CMakeFindBinUtils.cmake' (because it isn't rerun), hardcode
140 # CMAKE_INSTALL_NAME_TOOL here to `install_name_tool' so it behaves as
142 if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
143 find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
144 endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
146 # set up iOS platform unless specified manually with IOS_PLATFORM
147 if (NOT DEFINED IOS_PLATFORM)
148 set(IOS_PLATFORM "OS")
149 endif (NOT DEFINED IOS_PLATFORM)
151 set(IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
153 # check the platform selection and setup for developer root
154 if (${IOS_PLATFORM} STREQUAL "OS")
155 set(IOS_PLATFORM_LOCATION "iPhoneOS.platform")
157 # this causes the installers to properly locate the output libraries
158 set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
160 elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
161 set(IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
163 # this causes the installers to properly locate the output libraries
164 set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
166 else (${IOS_PLATFORM} STREQUAL "OS")
168 "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR.")
170 endif (${IOS_PLATFORM} STREQUAL "OS")
172 # set up iOS developer location unless specified manually with
173 # CMAKE_IOS_DEVELOPER_ROOT --
174 # note that Xcode 4.3 changed the installation location; choose the most
175 # recent one available
176 set(XCODE_POST_43_ROOT
177 "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
178 set(XCODE_PRE_43_ROOT
179 "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
181 if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
182 if (EXISTS ${XCODE_POST_43_ROOT})
183 set(CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
184 elseif (EXISTS ${XCODE_PRE_43_ROOT})
185 set(CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
186 endif (EXISTS ${XCODE_POST_43_ROOT})
187 endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
189 set(CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT}
190 CACHE PATH "Location of iOS Platform"
193 # find and use the most recent iOS SDK unless specified manually with
195 if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
196 file(GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
198 list(SORT _CMAKE_IOS_SDKS)
199 list(REVERSE _CMAKE_IOS_SDKS)
200 list(GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
201 else (_CMAKE_IOS_SDKS)
203 "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.")
204 endif (_CMAKE_IOS_SDKS)
206 message(STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
207 endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
209 set(CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT}
210 CACHE PATH "Location of the selected iOS SDK"
213 # set the sysroot default to the most recent SDK
214 set(CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT}
215 CACHE PATH "Sysroot used for iOS support"
218 # set the architecture for iOS --
219 # note that currently both ARCHS_STANDARD_32_BIT and
220 # ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually
221 if (${IOS_PLATFORM} STREQUAL "OS")
222 set(IOS_ARCH $(ARCHS_STANDARD_32_64_BIT))
223 else (${IOS_PLATFORM} STREQUAL "OS")
225 endif (${IOS_PLATFORM} STREQUAL "OS")
227 set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH}
228 CACHE string "Build architecture for iOS"
231 # set the find root to the iOS developer roots and to user defined paths
232 set(CMAKE_FIND_ROOT_PATH
233 ${CMAKE_IOS_DEVELOPER_ROOT}
234 ${CMAKE_IOS_SDK_ROOT}
236 CACHE string "iOS find search path root"
239 # default to searching for frameworks first
240 set(CMAKE_FIND_FRAMEWORK FIRST)
242 # set up the default search directories for frameworks
243 set(CMAKE_SYSTEM_FRAMEWORK_PATH
244 ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
245 ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
246 ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
249 # only search the iOS SDKs, not the remainder of the host filesystem
250 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
251 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
252 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
254 # this little macro lets you set any Xcode specific property
255 macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
256 set_property(TARGET ${TARGET}
257 PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
258 endmacro(set_xcode_property)
260 # this macro lets you find executable programs on the host system
261 macro(find_host_package)
262 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
263 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
264 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
267 find_package(${ARGN})
270 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
271 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
272 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
273 endmacro(find_host_package)