You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
9.0KB

  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 or SIMULATOR64
  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 gcc for iOS
  43. include (CMakeForceCompiler)
  44. #CMAKE_FORCE_C_COMPILER (/usr/bin/gcc Apple)
  45. set(CMAKE_C_COMPILER /usr/bin/clang)
  46. #CMAKE_FORCE_CXX_COMPILER (/usr/bin/g++ Apple)
  47. set(CMAKE_CXX_COMPILER /usr/bin/clang++)
  48. set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
  49. # Skip the platform compiler checks for cross compiling
  50. set (CMAKE_CXX_COMPILER_WORKS TRUE)
  51. set (CMAKE_C_COMPILER_WORKS TRUE)
  52. # All iOS/Darwin specific settings - some may be redundant
  53. set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
  54. set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
  55. set (CMAKE_SHARED_MODULE_PREFIX "lib")
  56. set (CMAKE_SHARED_MODULE_SUFFIX ".so")
  57. set (CMAKE_MODULE_EXISTS 1)
  58. set (CMAKE_DL_LIBS "")
  59. set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
  60. set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
  61. set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
  62. set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
  63. # Hidden visibilty is required for cxx on iOS
  64. set (CMAKE_C_FLAGS_INIT "")
  65. set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden")
  66. set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
  67. set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
  68. set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
  69. set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
  70. set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
  71. set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
  72. set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
  73. set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
  74. # hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
  75. # (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
  76. # and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
  77. # hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
  78. if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
  79. find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
  80. endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
  81. # Setup iOS platform unless specified manually with IOS_PLATFORM
  82. if (NOT DEFINED IOS_PLATFORM)
  83. set (IOS_PLATFORM "OS")
  84. endif (NOT DEFINED IOS_PLATFORM)
  85. set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
  86. # Setup building for arm64 or not
  87. if (NOT DEFINED BUILD_ARM64)
  88. set (BUILD_ARM64 true)
  89. endif (NOT DEFINED BUILD_ARM64)
  90. set (BUILD_ARM64 ${BUILD_ARM64} CACHE STRING "Build arm64 arch or not")
  91. # Check the platform selection and setup for developer root
  92. if (${IOS_PLATFORM} STREQUAL "OS")
  93. set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
  94. # This causes the installers to properly locate the output libraries
  95. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
  96. elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
  97. set (SIMULATOR true)
  98. set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
  99. # This causes the installers to properly locate the output libraries
  100. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
  101. elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64")
  102. set (SIMULATOR true)
  103. set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
  104. # This causes the installers to properly locate the output libraries
  105. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
  106. else (${IOS_PLATFORM} STREQUAL "OS")
  107. message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
  108. endif (${IOS_PLATFORM} STREQUAL "OS")
  109. # Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
  110. # Note Xcode 4.3 changed the installation location, choose the most recent one available
  111. exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR)
  112. set (XCODE_POST_43_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
  113. set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
  114. if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
  115. if (EXISTS ${XCODE_POST_43_ROOT})
  116. set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
  117. elseif(EXISTS ${XCODE_PRE_43_ROOT})
  118. set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
  119. endif (EXISTS ${XCODE_POST_43_ROOT})
  120. endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
  121. set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
  122. # Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
  123. if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
  124. file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
  125. if (_CMAKE_IOS_SDKS)
  126. list (SORT _CMAKE_IOS_SDKS)
  127. list (REVERSE _CMAKE_IOS_SDKS)
  128. list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
  129. else (_CMAKE_IOS_SDKS)
  130. 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.")
  131. endif (_CMAKE_IOS_SDKS)
  132. message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
  133. endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
  134. set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
  135. # Set the sysroot default to the most recent SDK
  136. set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
  137. # set the architecture for iOS
  138. if (${IOS_PLATFORM} STREQUAL "OS")
  139. set (IOS_ARCH armv7 armv7s arm64)
  140. elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
  141. set (IOS_ARCH i386)
  142. elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64")
  143. set (IOS_ARCH x86_64)
  144. endif (${IOS_PLATFORM} STREQUAL "OS")
  145. set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
  146. # Set the find root to the iOS developer roots and to user defined paths
  147. set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root")
  148. # default to searching for frameworks first
  149. set (CMAKE_FIND_FRAMEWORK FIRST)
  150. # set up the default search directories for frameworks
  151. set (CMAKE_SYSTEM_FRAMEWORK_PATH
  152. ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
  153. ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
  154. ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
  155. )
  156. # only search the iOS sdks, not the remainder of the host filesystem
  157. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
  158. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  159. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  160. # This little macro lets you set any XCode specific property
  161. macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
  162. set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
  163. endmacro (set_xcode_property)
  164. # This macro lets you find executable programs on the host system
  165. macro (find_host_package)
  166. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  167. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
  168. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
  169. set (IOS FALSE)
  170. find_package(${ARGN})
  171. set (IOS TRUE)
  172. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
  173. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  174. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  175. endmacro (find_host_package)