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