ios.toolchain.cmake 8.8 KB

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