1d4afb5ceSopenharmony_ci# This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake
2d4afb5ceSopenharmony_ci# files which are included with CMake 2.8.4
3d4afb5ceSopenharmony_ci# It has been altered for iOS development
4d4afb5ceSopenharmony_ci
5d4afb5ceSopenharmony_ci# Options:
6d4afb5ceSopenharmony_ci#
7d4afb5ceSopenharmony_ci# IOS_PLATFORM = OS (default) or OS32 or SIMULATOR or SIMULATOR64
8d4afb5ceSopenharmony_ci#   This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders
9d4afb5ceSopenharmony_ci#   OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.
10d4afb5ceSopenharmony_ci#   SIMULATOR - used to build for the Simulator platforms, which have an x86 arch.
11d4afb5ceSopenharmony_ci#
12d4afb5ceSopenharmony_ci# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder
13d4afb5ceSopenharmony_ci#   By default this location is automatcially chosen based on the IOS_PLATFORM value above.
14d4afb5ceSopenharmony_ci#   If set manually, it will override the default location and force the user of a particular Developer Platform
15d4afb5ceSopenharmony_ci#
16d4afb5ceSopenharmony_ci# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
17d4afb5ceSopenharmony_ci#   By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
18d4afb5ceSopenharmony_ci#   In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path.
19d4afb5ceSopenharmony_ci#   If set manually, this will force the use of a specific SDK version
20d4afb5ceSopenharmony_ci#
21d4afb5ceSopenharmony_ci# IOS_BITCODE = 1/0: Enable bitcode or not. Only iOS >= 6.0 device build can enable bitcode. Default is enabled.
22d4afb5ceSopenharmony_ci
23d4afb5ceSopenharmony_ci# Macros:
24d4afb5ceSopenharmony_ci#
25d4afb5ceSopenharmony_ci# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE)
26d4afb5ceSopenharmony_ci#  A convenience macro for setting xcode specific properties on targets
27d4afb5ceSopenharmony_ci#  example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1")
28d4afb5ceSopenharmony_ci#
29d4afb5ceSopenharmony_ci# find_host_package (PROGRAM ARGS)
30d4afb5ceSopenharmony_ci#  A macro used to find executable programs on the host system, not within the iOS environment.
31d4afb5ceSopenharmony_ci#  Thanks to the android-cmake project for providing the command
32d4afb5ceSopenharmony_ci
33d4afb5ceSopenharmony_ci# Standard settings
34d4afb5ceSopenharmony_ciset (CMAKE_SYSTEM_NAME Darwin)
35d4afb5ceSopenharmony_ciset (CMAKE_SYSTEM_VERSION 1)
36d4afb5ceSopenharmony_ciset(CMAKE_CROSSCOMPILING TRUE)
37d4afb5ceSopenharmony_ciset (UNIX TRUE)
38d4afb5ceSopenharmony_ciset (APPLE TRUE)
39d4afb5ceSopenharmony_ciset (IOS TRUE)
40d4afb5ceSopenharmony_ci
41d4afb5ceSopenharmony_ciif(NOT DEFINED IOS_BITCODE) # check xcode/clang version? since xcode 7
42d4afb5ceSopenharmony_ci  set(IOS_BITCODE 1)
43d4afb5ceSopenharmony_ciendif()
44d4afb5ceSopenharmony_ciset(IOS_BITCODE_MARKER 0)
45d4afb5ceSopenharmony_ci
46d4afb5ceSopenharmony_ci# Required as of cmake 2.8.10
47d4afb5ceSopenharmony_ciset (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
48d4afb5ceSopenharmony_ci
49d4afb5ceSopenharmony_ci# Determine the cmake host system version so we know where to find the iOS SDKs
50d4afb5ceSopenharmony_cifind_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
51d4afb5ceSopenharmony_ciif (CMAKE_UNAME)
52d4afb5ceSopenharmony_ci	exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
53d4afb5ceSopenharmony_ci	string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
54d4afb5ceSopenharmony_ciendif (CMAKE_UNAME)
55d4afb5ceSopenharmony_ci
56d4afb5ceSopenharmony_ci# Force the compilers to gcc for iOS
57d4afb5ceSopenharmony_ciinclude (CMakeForceCompiler)
58d4afb5ceSopenharmony_ciset (CMAKE_C_COMPILER /usr/bin/clang)
59d4afb5ceSopenharmony_ciset (CMAKE_CXX_COMPILER /usr/bin/clang++)
60d4afb5ceSopenharmony_ciset(CMAKE_AR ar CACHE FILEPATH "" FORCE)
61d4afb5ceSopenharmony_ci
62d4afb5ceSopenharmony_ci# Skip the platform compiler checks for cross compiling
63d4afb5ceSopenharmony_ciset (CMAKE_CXX_COMPILER_WORKS TRUE)
64d4afb5ceSopenharmony_ciset (CMAKE_C_COMPILER_WORKS TRUE)
65d4afb5ceSopenharmony_ci
66d4afb5ceSopenharmony_ci# All iOS/Darwin specific settings - some may be redundant
67d4afb5ceSopenharmony_ciset (CMAKE_SHARED_LIBRARY_PREFIX "lib")
68d4afb5ceSopenharmony_ciset (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
69d4afb5ceSopenharmony_ciset (CMAKE_SHARED_MODULE_PREFIX "lib")
70d4afb5ceSopenharmony_ciset (CMAKE_SHARED_MODULE_SUFFIX ".so")
71d4afb5ceSopenharmony_ciset (CMAKE_MODULE_EXISTS 1)
72d4afb5ceSopenharmony_ciset (CMAKE_DL_LIBS "")
73d4afb5ceSopenharmony_ci
74d4afb5ceSopenharmony_ciif(IOS_BITCODE)
75d4afb5ceSopenharmony_ci    set(BITCODE_FLAGS "-fembed-bitcode")
76d4afb5ceSopenharmony_ci  elseif(IOS_BITCODE_MARKER)
77d4afb5ceSopenharmony_ci    set(BITCODE_FLAGS "-fembed-bitcode-marker")
78d4afb5ceSopenharmony_ci  endif()
79d4afb5ceSopenharmony_ci
80d4afb5ceSopenharmony_ciset (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
81d4afb5ceSopenharmony_ciset (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
82d4afb5ceSopenharmony_ciset (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
83d4afb5ceSopenharmony_ciset (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
84d4afb5ceSopenharmony_ci
85d4afb5ceSopenharmony_ci# Hidden visibilty is required for cxx on iOS 
86d4afb5ceSopenharmony_ciset (CMAKE_C_FLAGS_INIT "${BITCODE_FLAGS}")
87d4afb5ceSopenharmony_ciset (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden ${BITCODE_FLAGS}")
88d4afb5ceSopenharmony_ci
89d4afb5ceSopenharmony_ciset (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
90d4afb5ceSopenharmony_ciset (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
91d4afb5ceSopenharmony_ci
92d4afb5ceSopenharmony_ciset (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
93d4afb5ceSopenharmony_ciset (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
94d4afb5ceSopenharmony_ciset (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
95d4afb5ceSopenharmony_ciset (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
96d4afb5ceSopenharmony_ciset (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
97d4afb5ceSopenharmony_ciset (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
98d4afb5ceSopenharmony_ci
99d4afb5ceSopenharmony_ci# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
100d4afb5ceSopenharmony_ci# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
101d4afb5ceSopenharmony_ci# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
102d4afb5ceSopenharmony_ci# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
103d4afb5ceSopenharmony_ciif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
104d4afb5ceSopenharmony_ci	find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
105d4afb5ceSopenharmony_ciendif ()
106d4afb5ceSopenharmony_ci
107d4afb5ceSopenharmony_ci# Setup iOS platform unless specified manually with IOS_PLATFORM
108d4afb5ceSopenharmony_ciif (NOT DEFINED IOS_PLATFORM)
109d4afb5ceSopenharmony_ci	set (IOS_PLATFORM "OS")
110d4afb5ceSopenharmony_ciendif ()
111d4afb5ceSopenharmony_ciset (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
112d4afb5ceSopenharmony_ci
113d4afb5ceSopenharmony_ci# Setup building for arm64 or not
114d4afb5ceSopenharmony_ciif (NOT DEFINED BUILD_ARM64)
115d4afb5ceSopenharmony_ci    set (BUILD_ARM64 true)
116d4afb5ceSopenharmony_ciendif ()
117d4afb5ceSopenharmony_ciset (BUILD_ARM64 ${BUILD_ARM64} CACHE STRING "Build arm64 arch or not")
118d4afb5ceSopenharmony_ci
119d4afb5ceSopenharmony_ci# Check the platform selection and setup for developer root
120d4afb5ceSopenharmony_ciif (${IOS_PLATFORM} STREQUAL "OS")
121d4afb5ceSopenharmony_ci	set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
122d4afb5ceSopenharmony_ci
123d4afb5ceSopenharmony_ci	# This causes the installers to properly locate the output libraries
124d4afb5ceSopenharmony_ci	set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
125d4afb5ceSopenharmony_cielseif (${IOS_PLATFORM} STREQUAL "OS32")
126d4afb5ceSopenharmony_ci	set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
127d4afb5ceSopenharmony_ci
128d4afb5ceSopenharmony_ci	# This causes the installers to properly locate the output libraries
129d4afb5ceSopenharmony_ci	set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
130d4afb5ceSopenharmony_cielseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
131d4afb5ceSopenharmony_ci    set (IS_SIMULATOR true)
132d4afb5ceSopenharmony_ci	set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
133d4afb5ceSopenharmony_ci
134d4afb5ceSopenharmony_ci	# This causes the installers to properly locate the output libraries
135d4afb5ceSopenharmony_ci	set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
136d4afb5ceSopenharmony_cielseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64")
137d4afb5ceSopenharmony_ci    set (IS_SIMULATOR true)
138d4afb5ceSopenharmony_ci	set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
139d4afb5ceSopenharmony_ci
140d4afb5ceSopenharmony_ci	# This causes the installers to properly locate the output libraries
141d4afb5ceSopenharmony_ci	set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
142d4afb5ceSopenharmony_cielse ()
143d4afb5ceSopenharmony_ci	message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
144d4afb5ceSopenharmony_ciendif ()
145d4afb5ceSopenharmony_ci
146d4afb5ceSopenharmony_ci# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
147d4afb5ceSopenharmony_ci# Note Xcode 4.3 changed the installation location, choose the most recent one available
148d4afb5ceSopenharmony_ciexec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR)
149d4afb5ceSopenharmony_ciset (XCODE_POST_43_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
150d4afb5ceSopenharmony_ciset (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
151d4afb5ceSopenharmony_ciif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
152d4afb5ceSopenharmony_ci	if (EXISTS ${XCODE_POST_43_ROOT})
153d4afb5ceSopenharmony_ci		set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
154d4afb5ceSopenharmony_ci	elseif(EXISTS ${XCODE_PRE_43_ROOT})
155d4afb5ceSopenharmony_ci		set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
156d4afb5ceSopenharmony_ci	endif (EXISTS ${XCODE_POST_43_ROOT})
157d4afb5ceSopenharmony_ciendif ()
158d4afb5ceSopenharmony_ciset (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
159d4afb5ceSopenharmony_ci
160d4afb5ceSopenharmony_ci# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
161d4afb5ceSopenharmony_ciif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
162d4afb5ceSopenharmony_ci	file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
163d4afb5ceSopenharmony_ci	if (_CMAKE_IOS_SDKS) 
164d4afb5ceSopenharmony_ci		list (SORT _CMAKE_IOS_SDKS)
165d4afb5ceSopenharmony_ci		list (REVERSE _CMAKE_IOS_SDKS)
166d4afb5ceSopenharmony_ci		list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
167d4afb5ceSopenharmony_ci	else (_CMAKE_IOS_SDKS)
168d4afb5ceSopenharmony_ci		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.")
169d4afb5ceSopenharmony_ci	endif (_CMAKE_IOS_SDKS)
170d4afb5ceSopenharmony_ci	message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
171d4afb5ceSopenharmony_ciendif ()
172d4afb5ceSopenharmony_ciset (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
173d4afb5ceSopenharmony_ci
174d4afb5ceSopenharmony_ci# Set the sysroot default to the most recent SDK
175d4afb5ceSopenharmony_ciset (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
176d4afb5ceSopenharmony_ci
177d4afb5ceSopenharmony_ci# set the architecture for iOS 
178d4afb5ceSopenharmony_ciif (${IOS_PLATFORM} STREQUAL "OS")
179d4afb5ceSopenharmony_ci    set (IOS_ARCH arm64)
180d4afb5ceSopenharmony_cielseif (${IOS_PLATFORM} STREQUAL "OS32")
181d4afb5ceSopenharmony_ci	set (IOS_ARCH armv7)
182d4afb5ceSopenharmony_cielseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
183d4afb5ceSopenharmony_ci    set (IOS_ARCH i386)
184d4afb5ceSopenharmony_cielseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64")
185d4afb5ceSopenharmony_ci    set (IOS_ARCH x86_64)
186d4afb5ceSopenharmony_ciendif ()
187d4afb5ceSopenharmony_ci
188d4afb5ceSopenharmony_ciset (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE STRING  "Build architecture for iOS")
189d4afb5ceSopenharmony_ci
190d4afb5ceSopenharmony_ci# Set the find root to the iOS developer roots and to user defined paths
191d4afb5ceSopenharmony_ciset (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE STRING  "iOS find search path root")
192d4afb5ceSopenharmony_ci
193d4afb5ceSopenharmony_ci# default to searching for frameworks first
194d4afb5ceSopenharmony_ciset (CMAKE_FIND_FRAMEWORK FIRST)
195d4afb5ceSopenharmony_ci
196d4afb5ceSopenharmony_ci# set up the default search directories for frameworks
197d4afb5ceSopenharmony_ciset (CMAKE_SYSTEM_FRAMEWORK_PATH
198d4afb5ceSopenharmony_ci	${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
199d4afb5ceSopenharmony_ci	${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
200d4afb5ceSopenharmony_ci	${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
201d4afb5ceSopenharmony_ci)
202d4afb5ceSopenharmony_ci
203d4afb5ceSopenharmony_ci# only search the iOS sdks, not the remainder of the host filesystem
204d4afb5ceSopenharmony_ciset (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
205d4afb5ceSopenharmony_ciset (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
206d4afb5ceSopenharmony_ciset (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
207d4afb5ceSopenharmony_ci
208d4afb5ceSopenharmony_ci
209d4afb5ceSopenharmony_ci# This little macro lets you set any XCode specific property
210d4afb5ceSopenharmony_cimacro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
211d4afb5ceSopenharmony_ci	set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
212d4afb5ceSopenharmony_ciendmacro (set_xcode_property)
213d4afb5ceSopenharmony_ci
214d4afb5ceSopenharmony_ci
215d4afb5ceSopenharmony_ci# This macro lets you find executable programs on the host system
216d4afb5ceSopenharmony_cimacro (find_host_package)
217d4afb5ceSopenharmony_ci	set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
218d4afb5ceSopenharmony_ci	set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
219d4afb5ceSopenharmony_ci	set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
220d4afb5ceSopenharmony_ci	set (IOS FALSE)
221d4afb5ceSopenharmony_ci
222d4afb5ceSopenharmony_ci	find_package(${ARGN})
223d4afb5ceSopenharmony_ci
224d4afb5ceSopenharmony_ci	set (IOS TRUE)
225d4afb5ceSopenharmony_ci	set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
226d4afb5ceSopenharmony_ci	set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
227d4afb5ceSopenharmony_ci	set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
228d4afb5ceSopenharmony_ciendmacro (find_host_package)
229d4afb5ceSopenharmony_ci
230