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.

193 lines
8.4 KiB

  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 (gcc gcc)
  45. CMAKE_FORCE_CXX_COMPILER (g++ g++)
  46. # Skip the platform compiler checks for cross compiling
  47. set (CMAKE_CXX_COMPILER_WORKS TRUE)
  48. set (CMAKE_C_COMPILER_WORKS TRUE)
  49. # All iOS/Darwin specific settings - some may be redundant
  50. set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
  51. set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
  52. set (CMAKE_SHARED_MODULE_PREFIX "lib")
  53. set (CMAKE_SHARED_MODULE_SUFFIX ".so")
  54. set (CMAKE_MODULE_EXISTS 1)
  55. set (CMAKE_DL_LIBS "")
  56. set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
  57. set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
  58. set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
  59. set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
  60. # Hidden visibilty is required for cxx on iOS
  61. set (CMAKE_C_FLAGS_INIT "")
  62. set (CMAKE_CXX_FLAGS_INIT "-headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden")
  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. # Check the platform selection and setup for developer root
  84. if (${IOS_PLATFORM} STREQUAL "OS")
  85. set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
  86. # This causes the installers to properly locate the output libraries
  87. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
  88. elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
  89. set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
  90. # This causes the installers to properly locate the output libraries
  91. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
  92. else (${IOS_PLATFORM} STREQUAL "OS")
  93. message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
  94. endif (${IOS_PLATFORM} STREQUAL "OS")
  95. # Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
  96. # Note Xcode 4.3 changed the installation location, choose the most recent one available
  97. set (XCODE_POST_43_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
  98. set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
  99. if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
  100. if (EXISTS ${XCODE_POST_43_ROOT})
  101. set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
  102. elseif(EXISTS ${XCODE_PRE_43_ROOT})
  103. set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
  104. endif (EXISTS ${XCODE_POST_43_ROOT})
  105. endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
  106. set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
  107. # Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
  108. if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
  109. file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
  110. if (_CMAKE_IOS_SDKS)
  111. list (SORT _CMAKE_IOS_SDKS)
  112. list (REVERSE _CMAKE_IOS_SDKS)
  113. list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
  114. else (_CMAKE_IOS_SDKS)
  115. 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.")
  116. endif (_CMAKE_IOS_SDKS)
  117. message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
  118. endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
  119. set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
  120. # Set the sysroot default to the most recent SDK
  121. set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
  122. # set the architecture for iOS
  123. # NOTE: Currently both ARCHS_STANDARD_32_BIT and ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually
  124. if (${IOS_PLATFORM} STREQUAL "OS")
  125. set (IOS_ARCH armv6 armv7)
  126. else (${IOS_PLATFORM} STREQUAL "OS")
  127. set (IOS_ARCH i386)
  128. endif (${IOS_PLATFORM} STREQUAL "OS")
  129. set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
  130. # Set the find root to the iOS developer roots and to user defined paths
  131. set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root")
  132. # default to searching for frameworks first
  133. set (CMAKE_FIND_FRAMEWORK FIRST)
  134. # set up the default search directories for frameworks
  135. set (CMAKE_SYSTEM_FRAMEWORK_PATH
  136. ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
  137. ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
  138. ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
  139. )
  140. # only search the iOS sdks, not the remainder of the host filesystem
  141. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
  142. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  143. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  144. # This little macro lets you set any XCode specific property
  145. macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
  146. set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
  147. endmacro (set_xcode_property)
  148. # This macro lets you find executable programs on the host system
  149. macro (find_host_package)
  150. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  151. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
  152. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
  153. set (IOS FALSE)
  154. find_package(${ARGN})
  155. set (IOS TRUE)
  156. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
  157. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  158. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  159. endmacro (find_host_package)