Sameer Agarwal | 082d9e2 | 2014-05-12 20:41:27 -0700 | [diff] [blame] | 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 | |
| 114 | set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") |
| 115 | set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") |
| 116 | |
| 117 | set (CMAKE_PLATFORM_HAS_INSTALLNAME 1) |
| 118 | set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names") |
| 119 | set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names") |
| 120 | set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,") |
| 121 | set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,") |
| 122 | set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a") |
| 123 | |
| 124 | # hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree |
| 125 | # (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache |
| 126 | # and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun) |
| 127 | # hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex |
| 128 | if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) |
| 129 | find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool) |
| 130 | endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) |
| 131 | |
| 132 | # Setup iOS platform unless specified manually with IOS_PLATFORM |
| 133 | if (NOT DEFINED IOS_PLATFORM) |
| 134 | set (IOS_PLATFORM "OS") |
| 135 | endif (NOT DEFINED IOS_PLATFORM) |
| 136 | set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform") |
| 137 | |
| 138 | # Setup building for arm64 or not |
| 139 | if (NOT DEFINED BUILD_ARM64) |
| 140 | set (BUILD_ARM64 true) |
| 141 | endif (NOT DEFINED BUILD_ARM64) |
| 142 | set (BUILD_ARM64 ${BUILD_ARM64} CACHE STRING "Build arm64 arch or not") |
| 143 | |
| 144 | # Check the platform selection and setup for developer root |
| 145 | if (${IOS_PLATFORM} STREQUAL "OS") |
| 146 | set (IOS_PLATFORM_LOCATION "iPhoneOS.platform") |
| 147 | |
| 148 | # This causes the installers to properly locate the output libraries |
| 149 | set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos") |
| 150 | elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") |
| 151 | set (SIMULATOR true) |
| 152 | set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") |
| 153 | |
| 154 | # This causes the installers to properly locate the output libraries |
| 155 | set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") |
| 156 | elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64") |
| 157 | set (SIMULATOR true) |
| 158 | set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") |
| 159 | |
| 160 | # This causes the installers to properly locate the output libraries |
| 161 | set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") |
| 162 | else (${IOS_PLATFORM} STREQUAL "OS") |
| 163 | message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR") |
| 164 | endif (${IOS_PLATFORM} STREQUAL "OS") |
| 165 | |
| 166 | # Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT |
| 167 | # Note Xcode 4.3 changed the installation location, choose the most recent one available |
| 168 | set (XCODE_POST_43_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") |
| 169 | set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") |
| 170 | if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) |
| 171 | if (EXISTS ${XCODE_POST_43_ROOT}) |
| 172 | set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT}) |
| 173 | elseif(EXISTS ${XCODE_PRE_43_ROOT}) |
| 174 | set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT}) |
| 175 | endif (EXISTS ${XCODE_POST_43_ROOT}) |
| 176 | endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) |
| 177 | set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform") |
| 178 | |
| 179 | # Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT |
| 180 | if (NOT DEFINED CMAKE_IOS_SDK_ROOT) |
| 181 | file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*") |
| 182 | if (_CMAKE_IOS_SDKS) |
| 183 | list (SORT _CMAKE_IOS_SDKS) |
| 184 | list (REVERSE _CMAKE_IOS_SDKS) |
| 185 | list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT) |
| 186 | else (_CMAKE_IOS_SDKS) |
| 187 | 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.") |
| 188 | endif (_CMAKE_IOS_SDKS) |
| 189 | message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}") |
| 190 | endif (NOT DEFINED CMAKE_IOS_SDK_ROOT) |
| 191 | set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK") |
| 192 | |
| 193 | # Set the sysroot default to the most recent SDK |
| 194 | set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support") |
| 195 | |
| 196 | # set the architecture for iOS |
| 197 | if (${IOS_PLATFORM} STREQUAL "OS") |
| 198 | set (IOS_ARCH armv7 armv7s arm64) |
| 199 | elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") |
| 200 | set (IOS_ARCH i386) |
| 201 | elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64") |
| 202 | set (IOS_ARCH x86_64) |
| 203 | endif (${IOS_PLATFORM} STREQUAL "OS") |
| 204 | |
| 205 | set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS") |
| 206 | |
| 207 | # Set the find root to the iOS developer roots and to user defined paths |
| 208 | set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root") |
| 209 | |
| 210 | # default to searching for frameworks first |
| 211 | set (CMAKE_FIND_FRAMEWORK FIRST) |
| 212 | |
| 213 | # set up the default search directories for frameworks |
| 214 | set (CMAKE_SYSTEM_FRAMEWORK_PATH |
| 215 | ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks |
| 216 | ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks |
| 217 | ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks |
| 218 | ) |
| 219 | |
| 220 | # only search the iOS sdks, not the remainder of the host filesystem |
| 221 | set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) |
| 222 | set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| 223 | set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
| 224 | |
| 225 | |
| 226 | # This little macro lets you set any XCode specific property |
| 227 | macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE) |
| 228 | set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE}) |
| 229 | endmacro (set_xcode_property) |
| 230 | |
| 231 | |
| 232 | # This macro lets you find executable programs on the host system |
| 233 | macro (find_host_package) |
| 234 | set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
| 235 | set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) |
| 236 | set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) |
| 237 | set (IOS FALSE) |
| 238 | |
| 239 | find_package(${ARGN}) |
| 240 | |
| 241 | set (IOS TRUE) |
| 242 | set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) |
| 243 | set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| 244 | set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
| 245 | endmacro (find_host_package) |