ios.toolchain.cmake 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 gcc for iOS
  43. include (CMakeForceCompiler)
  44. CMAKE_FORCE_C_COMPILER (/usr/bin/clang Apple)
  45. CMAKE_FORCE_CXX_COMPILER (/usr/bin/clang++ Apple)
  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. # Hidden visibilty is required for cxx on iOS
  62. set (CMAKE_C_FLAGS_INIT "")
  63. set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden -isysroot ${CMAKE_OSX_SYSROOT}")
  64. set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
  65. set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
  66. set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
  67. set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
  68. set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
  69. set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
  70. set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
  71. set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
  72. # hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
  73. # (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
  74. # and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
  75. # hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
  76. if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
  77. find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
  78. endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
  79. # Setup iOS platform unless specified manually with IOS_PLATFORM
  80. if (NOT DEFINED IOS_PLATFORM)
  81. set (IOS_PLATFORM "OS")
  82. endif (NOT DEFINED IOS_PLATFORM)
  83. set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
  84. # Check the platform selection and setup for developer root
  85. if (${IOS_PLATFORM} STREQUAL "OS")
  86. set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
  87. # This causes the installers to properly locate the output libraries
  88. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
  89. elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
  90. set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
  91. # This causes the installers to properly locate the output libraries
  92. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
  93. else (${IOS_PLATFORM} STREQUAL "OS")
  94. message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
  95. endif (${IOS_PLATFORM} STREQUAL "OS")
  96. # Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
  97. # Note Xcode 4.3 changed the installation location, choose the most recent one available
  98. set (XCODE_POST_43_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
  99. set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
  100. if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
  101. if (EXISTS ${XCODE_POST_43_ROOT})
  102. set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
  103. elseif(EXISTS ${XCODE_PRE_43_ROOT})
  104. set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
  105. endif (EXISTS ${XCODE_POST_43_ROOT})
  106. endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
  107. set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
  108. # Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
  109. if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
  110. file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
  111. if (_CMAKE_IOS_SDKS)
  112. list (SORT _CMAKE_IOS_SDKS)
  113. list (REVERSE _CMAKE_IOS_SDKS)
  114. list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
  115. else (_CMAKE_IOS_SDKS)
  116. 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.")
  117. endif (_CMAKE_IOS_SDKS)
  118. message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
  119. endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
  120. set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
  121. # Set the sysroot default to the most recent SDK
  122. set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
  123. # set the architecture for iOS
  124. # NOTE: Currently both ARCHS_STANDARD_32_BIT and ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually
  125. if (${IOS_PLATFORM} STREQUAL "OS")
  126. set (IOS_ARCH armv6 armv7)
  127. else (${IOS_PLATFORM} STREQUAL "OS")
  128. set (IOS_ARCH i386)
  129. endif (${IOS_PLATFORM} STREQUAL "OS")
  130. set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
  131. # Set the find root to the iOS developer roots and to user defined paths
  132. set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root")
  133. # default to searching for frameworks first
  134. set (CMAKE_FIND_FRAMEWORK FIRST)
  135. # set up the default search directories for frameworks
  136. set (CMAKE_SYSTEM_FRAMEWORK_PATH
  137. ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
  138. ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
  139. ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
  140. )
  141. # only search the iOS sdks, not the remainder of the host filesystem
  142. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
  143. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  144. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  145. # This little macro lets you set any XCode specific property
  146. macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
  147. set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
  148. endmacro (set_xcode_property)
  149. # This macro lets you find executable programs on the host system
  150. macro (find_host_package)
  151. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  152. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
  153. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
  154. set (IOS FALSE)
  155. find_package(${ARGN})
  156. set (IOS TRUE)
  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. endmacro (find_host_package)