1# iOS.cmake 2# 3# Copyright (C) 2014-2020 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 68set(CMAKE_SYSTEM_NAME Darwin) 69set(CMAKE_SYSTEM_VERSION 1) 70set(UNIX True) 71set(APPLE True) 72set(IOS True) 73 74# required as of cmake 2.8.10 75set(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 81find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin) 82if (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}") 86endif (CMAKE_UNAME) 87 88# skip the platform compiler checks for cross compiling 89set(CMAKE_CXX_COMPILER_WORKS TRUE) 90set(CMAKE_C_COMPILER_WORKS TRUE) 91 92# all iOS/Darwin specific settings - some may be redundant 93set(CMAKE_SHARED_LIBRARY_PREFIX "lib") 94set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib") 95set(CMAKE_SHARED_MODULE_PREFIX "lib") 96set(CMAKE_SHARED_MODULE_SUFFIX ".so") 97set(CMAKE_MODULE_EXISTS 1) 98set(CMAKE_DL_LIBS "") 99 100set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG 101 "-compatibility_version ") 102set(CMAKE_C_OSX_CURRENT_VERSION_FLAG 103 "-current_version ") 104set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG 105 "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") 106set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG 107 "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") 108 109# hidden visibility is required for cxx on iOS 110set(CMAKE_C_FLAGS_INIT "") 111set(CMAKE_CXX_FLAGS_INIT 112 "-headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden") 113 114set(CMAKE_C_LINK_FLAGS 115 "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") 116set(CMAKE_CXX_LINK_FLAGS 117 "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") 118 119set(CMAKE_PLATFORM_HAS_INSTALLNAME 1) 120set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS 121 "-dynamiclib -headerpad_max_install_names") 122set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS 123 "-bundle -headerpad_max_install_names") 124set(CMAKE_SHARED_MODULE_LOADER_C_FLAG 125 "-Wl,-bundle_loader,") 126set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG 127 "-Wl,-bundle_loader,") 128set(CMAKE_FIND_LIBRARY_SUFFIXES 129 ".dylib" ".so" ".a") 130 131# hack: If a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old 132# build tree (where `install_name_tool' was hardcoded), and where 133# CMAKE_INSTALL_NAME_TOOL isn't in the cache and still cmake didn't 134# fail in `CMakeFindBinUtils.cmake' (because it isn't rerun), hardcode 135# CMAKE_INSTALL_NAME_TOOL here to `install_name_tool' so it behaves as 136# it did before. 137if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) 138 find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool) 139endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) 140 141# set up iOS platform unless specified manually with IOS_PLATFORM 142if (NOT DEFINED IOS_PLATFORM) 143 set(IOS_PLATFORM "OS") 144endif (NOT DEFINED IOS_PLATFORM) 145 146set(IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform") 147 148# check the platform selection and setup for developer root 149if (${IOS_PLATFORM} STREQUAL "OS") 150 set(IOS_PLATFORM_LOCATION "iPhoneOS.platform") 151 152 # this causes the installers to properly locate the output libraries 153 set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos") 154 155elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") 156 set(IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") 157 158 # this causes the installers to properly locate the output libraries 159 set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") 160 161else (${IOS_PLATFORM} STREQUAL "OS") 162 message(FATAL_ERROR 163 "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR.") 164 165endif (${IOS_PLATFORM} STREQUAL "OS") 166 167# set up iOS developer location unless specified manually with 168# CMAKE_IOS_DEVELOPER_ROOT -- 169# note that Xcode 4.3 changed the installation location; choose the most 170# recent one available 171set(XCODE_POST_43_ROOT 172 "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") 173set(XCODE_PRE_43_ROOT 174 "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") 175 176if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) 177 if (EXISTS ${XCODE_POST_43_ROOT}) 178 set(CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT}) 179 elseif (EXISTS ${XCODE_PRE_43_ROOT}) 180 set(CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT}) 181 endif (EXISTS ${XCODE_POST_43_ROOT}) 182endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) 183 184set(CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} 185 CACHE PATH "Location of iOS Platform" 186) 187 188# find and use the most recent iOS SDK unless specified manually with 189# CMAKE_IOS_SDK_ROOT 190if (NOT DEFINED CMAKE_IOS_SDK_ROOT) 191 file(GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*") 192 if (_CMAKE_IOS_SDKS) 193 list(SORT _CMAKE_IOS_SDKS) 194 list(REVERSE _CMAKE_IOS_SDKS) 195 list(GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT) 196 else (_CMAKE_IOS_SDKS) 197 message(FATAL_ERROR 198 "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.") 199 endif (_CMAKE_IOS_SDKS) 200 201 message(STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}") 202endif (NOT DEFINED CMAKE_IOS_SDK_ROOT) 203 204set(CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} 205 CACHE PATH "Location of the selected iOS SDK" 206) 207 208# set the sysroot default to the most recent SDK 209set(CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} 210 CACHE PATH "Sysroot used for iOS support" 211) 212 213# set the architecture for iOS -- 214# note that currently both ARCHS_STANDARD_32_BIT and 215# ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually 216if (${IOS_PLATFORM} STREQUAL "OS") 217 set(IOS_ARCH $(ARCHS_STANDARD_32_64_BIT)) 218else (${IOS_PLATFORM} STREQUAL "OS") 219 set(IOS_ARCH i386) 220endif (${IOS_PLATFORM} STREQUAL "OS") 221 222set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} 223 CACHE string "Build architecture for iOS" 224) 225 226# set the find root to the iOS developer roots and to user defined paths 227set(CMAKE_FIND_ROOT_PATH 228 ${CMAKE_IOS_DEVELOPER_ROOT} 229 ${CMAKE_IOS_SDK_ROOT} 230 ${CMAKE_PREFIX_PATH} 231 CACHE string "iOS find search path root" 232) 233 234# default to searching for frameworks first 235set(CMAKE_FIND_FRAMEWORK FIRST) 236 237# set up the default search directories for frameworks 238set(CMAKE_SYSTEM_FRAMEWORK_PATH 239 ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks 240 ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks 241 ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks 242) 243 244# only search the iOS SDKs, not the remainder of the host filesystem 245set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) 246set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 247set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 248 249# this little macro lets you set any Xcode specific property 250macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE) 251 set_property(TARGET ${TARGET} 252 PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE}) 253endmacro(set_xcode_property) 254 255# this macro lets you find executable programs on the host system 256macro(find_host_package) 257 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 258 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) 259 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) 260 set(IOS FALSE) 261 262 find_package(${ARGN}) 263 264 set(IOS TRUE) 265 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) 266 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 267 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 268endmacro(find_host_package) 269 270# eof 271