1 # This file is part of the ios-cmake project. It was retrieved from 2 # https://github.com/cristeab/ios-cmake.git, which is a fork of 3 # https://code.google.com/p/ios-cmake/. Which in turn is based off of 4 # the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which 5 # are included with CMake 2.8.4 6 # 7 # The ios-cmake project is licensed under the new BSD license. 8 # 9 # Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software, 10 # Kitware, Inc., Insight Software Consortium. All rights reserved. 11 12 # Redistribution and use in source and binary forms, with or without 13 # modification, are permitted provided that the following conditions 14 # are met: 15 16 # 1. Redistributions of source code must retain the above copyright 17 # notice, this list of conditions and the following disclaimer. 18 # 19 # 2. Redistributions in binary form must reproduce the above copyright 20 # notice, this list of conditions and the following disclaimer in the 21 # documentation and/or other materials provided with the distribution. 22 # 23 # 3. Neither the name of the copyright holder nor the names of its 24 # contributors may be used to endorse or promote products derived from 25 # this software without specific prior written permission. 26 # 27 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 # POSSIBILITY OF SUCH DAMAGE. 39 # 40 # This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake 41 # files which are included with CMake 2.8.4 42 # It has been altered for iOS development 43 44 # Options: 45 # 46 # IOS_PLATFORM = OS (default) or SIMULATOR or SIMULATOR64 47 # This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders 48 # OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch. 49 # SIMULATOR - used to build for the Simulator platforms, which have an x86 arch. 50 # 51 # CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder 52 # By default this location is automatcially chosen based on the IOS_PLATFORM value above. 53 # If set manually, it will override the default location and force the user of a particular Developer Platform 54 # 55 # CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder 56 # By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value. 57 # In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path. 58 # If set manually, this will force the use of a specific SDK version 59 60 # Macros: 61 # 62 # set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE) 63 # A convenience macro for setting xcode specific properties on targets 64 # example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1") 65 # 66 # find_host_package (PROGRAM ARGS) 67 # A macro used to find executable programs on the host system, not within the iOS environment. 68 # Thanks to the android-cmake project for providing the command 69 70 # Standard settings 71 set (CMAKE_SYSTEM_NAME Darwin) 72 set (CMAKE_SYSTEM_VERSION 1) 73 set (UNIX True) 74 set (APPLE True) 75 set (IOS True) 76 77 # Required as of cmake 2.8.10 78 set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE) 79 80 # Determine the cmake host system version so we know where to find the iOS 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" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}") 85 endif (CMAKE_UNAME) 86 87 # Force the compilers to gcc for iOS 88 include (CMakeForceCompiler) 89 CMAKE_FORCE_C_COMPILER (clang Apple) 90 CMAKE_FORCE_CXX_COMPILER (clang++ Apple) 91 set(CMAKE_AR ar CACHE FILEPATH "" FORCE) 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 "-compatibility_version ") 106 set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ") 107 set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") 108 set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") 109 110 # Hidden visibilty is required for cxx on iOS 111 set (CMAKE_C_FLAGS_INIT "") 112 set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden") 113 set (CMAKE_CXX_FLAGS_RELEASE_INIT "-DNDEBUG -O3 -fomit-frame-pointer -ffast-math") 114 115 set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") 116 set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") 117 118 set (CMAKE_PLATFORM_HAS_INSTALLNAME 1) 119 set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names") 120 set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names") 121 set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,") 122 set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,") 123 set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a") 124 125 # hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree 126 # (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache 127 # and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun) 128 # hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex 129 if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) 130 find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool) 131 endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) 132 133 # Setup iOS platform unless specified manually with IOS_PLATFORM 134 if (NOT DEFINED IOS_PLATFORM) 135 set (IOS_PLATFORM "OS") 136 endif (NOT DEFINED IOS_PLATFORM) 137 set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform") 138 139 # Setup building for arm64 or not 140 if (NOT DEFINED BUILD_ARM64) 141 set (BUILD_ARM64 true) 142 endif (NOT DEFINED BUILD_ARM64) 143 set (BUILD_ARM64 ${BUILD_ARM64} CACHE STRING "Build arm64 arch or not") 144 145 # Check the platform selection and setup for developer root 146 if (${IOS_PLATFORM} STREQUAL "OS") 147 set (IOS_PLATFORM_LOCATION "iPhoneOS.platform") 148 149 # This causes the installers to properly locate the output libraries 150 set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos") 151 elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") 152 set (SIMULATOR true) 153 set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") 154 155 # This causes the installers to properly locate the output libraries 156 set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") 157 elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64") 158 set (SIMULATOR true) 159 set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") 160 161 # This causes the installers to properly locate the output libraries 162 set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") 163 else (${IOS_PLATFORM} STREQUAL "OS") 164 message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR") 165 endif (${IOS_PLATFORM} STREQUAL "OS") 166 167 # Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT 168 # Note Xcode 4.3 changed the installation location, choose the most recent one available 169 set (XCODE_POST_43_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") 170 set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") 171 if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) 172 if (EXISTS ${XCODE_POST_43_ROOT}) 173 set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT}) 174 elseif(EXISTS ${XCODE_PRE_43_ROOT}) 175 set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT}) 176 endif (EXISTS ${XCODE_POST_43_ROOT}) 177 endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) 178 set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform") 179 180 # Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT 181 if (NOT DEFINED CMAKE_IOS_SDK_ROOT) 182 file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*") 183 if (_CMAKE_IOS_SDKS) 184 list (SORT _CMAKE_IOS_SDKS) 185 list (REVERSE _CMAKE_IOS_SDKS) 186 list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT) 187 else (_CMAKE_IOS_SDKS) 188 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.") 189 endif (_CMAKE_IOS_SDKS) 190 message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}") 191 endif (NOT DEFINED CMAKE_IOS_SDK_ROOT) 192 set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK") 193 194 # Set the sysroot default to the most recent SDK 195 set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support") 196 197 # set the architecture for iOS 198 if (${IOS_PLATFORM} STREQUAL "OS") 199 set (IOS_ARCH armv7 armv7s arm64) 200 elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") 201 set (IOS_ARCH i386) 202 elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64") 203 set (IOS_ARCH x86_64) 204 endif (${IOS_PLATFORM} STREQUAL "OS") 205 206 set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS") 207 208 # Set the find root to the iOS developer roots and to user defined paths 209 set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root") 210 211 # default to searching for frameworks first 212 set (CMAKE_FIND_FRAMEWORK FIRST) 213 214 # set up the default search directories for frameworks 215 set (CMAKE_SYSTEM_FRAMEWORK_PATH 216 ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks 217 ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks 218 ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks 219 ) 220 221 # only search the iOS sdks, not the remainder of the host filesystem 222 set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) 223 set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 224 set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 225 226 227 # This little macro lets you set any XCode specific property 228 macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE) 229 set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE}) 230 endmacro (set_xcode_property) 231 232 233 # This macro lets you find executable programs on the host system 234 macro (find_host_package) 235 set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 236 set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) 237 set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) 238 set (IOS FALSE) 239 240 find_package(${ARGN}) 241 242 set (IOS TRUE) 243 set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) 244 set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 245 set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 246 endmacro (find_host_package) 247