tizen 2.3.1 release
[framework/graphics/freetype.git] / builds / cmake / iOS.cmake
1 # iOS.cmake
2 #
3 # Copyright 2014 by
4 # David Turner, Robert Wilhelm, and Werner Lemberg.
5 #
6 # Written by David Wimsey <david@wimsey.us>
7 #
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
12 # fully.
13 #
14 #
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.
18
19
20 # Options
21 # -------
22 #
23 #   IOS_PLATFORM = OS | SIMULATOR
24 #
25 #     This decides whether SDKS are selected from the `iPhoneOS.platform' or
26 #     `iPhoneSimulator.platform' folders.
27 #
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
31 #       x86 architecture.
32 #
33 #   CMAKE_IOS_DEVELOPER_ROOT = /path/to/platform/Developer folder
34 #
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
38 #     Developer Platform.
39 #
40 #   CMAKE_IOS_SDK_ROOT = /path/to/platform/Developer/SDKs/SDK folder
41 #
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
46 #     version.
47 #
48 #
49 # Macros
50 # ------
51 #
52 #   set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE)
53 #
54 #     A convenience macro for setting Xcode specific properties on targets.
55 #
56 #     Example:
57 #
58 #       set_xcode_property(myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1")
59 #
60 #   find_host_package (PROGRAM ARGS)
61 #
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
64 #     the command.
65
66
67 # standard settings
68 set(CMAKE_SYSTEM_NAME Darwin)
69 set(CMAKE_SYSTEM_VERSION 1)
70 set(UNIX True)
71 set(APPLE True)
72 set(IOS True)
73
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
77 )
78
79 # determine the cmake host system version so we know where to find the iOS
80 # SDKs
81 find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
82 if (CMAKE_UNAME)
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}")
86 endif (CMAKE_UNAME)
87
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++)
92
93 # skip the platform compiler checks for cross compiling
94 set(CMAKE_CXX_COMPILER_WORKS TRUE)
95 set(CMAKE_C_COMPILER_WORKS TRUE)
96
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 "")
104
105 set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG
106   "-compatibility_version ")
107 set(CMAKE_C_OSX_CURRENT_VERSION_FLAG
108   "-current_version ")
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}")
113
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")
118
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}")
123
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
134   ".dylib" ".so" ".a")
135
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
141 #       it did before.
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)
145
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)
150
151 set(IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
152
153 # check the platform selection and setup for developer root
154 if (${IOS_PLATFORM} STREQUAL "OS")
155   set(IOS_PLATFORM_LOCATION "iPhoneOS.platform")
156
157   # this causes the installers to properly locate the output libraries
158   set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
159
160 elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
161   set(IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
162
163   # this causes the installers to properly locate the output libraries
164   set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
165
166 else (${IOS_PLATFORM} STREQUAL "OS")
167   message(FATAL_ERROR
168     "Unsupported IOS_PLATFORM value selected.  Please choose OS or SIMULATOR.")
169
170 endif (${IOS_PLATFORM} STREQUAL "OS")
171
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")
180
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)
188
189 set(CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT}
190   CACHE PATH "Location of iOS Platform"
191 )
192
193 # find and use the most recent iOS SDK unless specified manually with
194 # CMAKE_IOS_SDK_ROOT
195 if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
196   file(GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
197   if (_CMAKE_IOS_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)
202     message(FATAL_ERROR
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)
205
206   message(STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
207 endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
208
209 set(CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT}
210   CACHE PATH "Location of the selected iOS SDK"
211 )
212
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"
216 )
217
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")
224   set(IOS_ARCH i386)
225 endif (${IOS_PLATFORM} STREQUAL "OS")
226
227 set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH}
228   CACHE string "Build architecture for iOS"
229 )
230
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}
235   ${CMAKE_PREFIX_PATH}
236   CACHE string  "iOS find search path root"
237 )
238
239 # default to searching for frameworks first
240 set(CMAKE_FIND_FRAMEWORK FIRST)
241
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
247 )
248
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)
253
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)
259
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)
265   set(IOS FALSE)
266
267   find_package(${ARGN})
268
269   set(IOS TRUE)
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)
274
275 # eof