iOS.cmake 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. # IOS_ARCH = arm64 (default for OS), armv7, armv7s, i386 (default for SIMULATOR), x86_64 (default for SIMULATOR64)
  12. #
  13. # CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder
  14. # By default this location is automatcially chosen based on the IOS_PLATFORM value above.
  15. # If set manually, it will override the default location and force the user of a particular Developer Platform
  16. #
  17. # CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
  18. # By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
  19. # In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path.
  20. # If set manually, this will force the use of a specific SDK version
  21. #
  22. # IOS_DISABLE_BITCODE - set to 1 if you want to disable bitcode generation
  23. # Standard settings
  24. set (CMAKE_SYSTEM_NAME Darwin)
  25. set (CMAKE_SYSTEM_VERSION 1)
  26. set (UNIX True)
  27. set (APPLE True)
  28. set (IOS True)
  29. # Required as of cmake 2.8.10
  30. set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
  31. # Determine the cmake host system version so we know where to find the iOS SDKs
  32. find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
  33. if (CMAKE_UNAME)
  34. exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
  35. string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
  36. endif (CMAKE_UNAME)
  37. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  38. set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
  39. set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
  40. set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
  41. set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
  42. set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
  43. if (NOT DEFINED IOS_DISABLE_BITCODE)
  44. set (EMBED_OPTIONS "-fembed-bitcode")
  45. endif(NOT DEFINED IOS_DISABLE_BITCODE)
  46. if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR ENABLE_DEBUG)
  47. set(IOS_DEBUG_OPTIONS "-glldb -gmodules")
  48. else()
  49. set(IOS_DEBUG_OPTIONS "-fvisibility=hidden -fvisibility-inlines-hidden")
  50. endif()
  51. set (CMAKE_C_FLAGS_INIT "${IOS_DEBUG_OPTIONS} ${EMBED_OPTIONS}")
  52. set (CMAKE_CXX_FLAGS_INIT "${IOS_DEBUG_OPTIONS} ${EMBED_OPTIONS}")
  53. set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${EMBED_OPTIONS} ${CMAKE_C_LINK_FLAGS}")
  54. set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${EMBED_OPTIONS} ${CMAKE_CXX_LINK_FLAGS}")
  55. set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
  56. set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib")
  57. set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle")
  58. set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
  59. set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
  60. set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
  61. # Specify install_name_tool and pkg-config since it outside of SDK path and therefore can't be found by CMake
  62. if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
  63. find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
  64. endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
  65. if (NOT DEFINED PKG_CONFIG_EXECUTABLE)
  66. find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config)
  67. if (DEFINED PKG_CONFIG_EXECUTABLE)
  68. execute_process(COMMAND pkg-config --version OUTPUT_VARIABLE PKG_CONFIG_VERSION_STRING)
  69. endif(DEFINED PKG_CONFIG_EXECUTABLE)
  70. endif(NOT DEFINED PKG_CONFIG_EXECUTABLE)
  71. # fffio Specify path to install shared library on device
  72. set (CMAKE_INSTALL_NAME_DIR "@executable_path/Frameworks")
  73. set (CMAKE_BUILD_WITH_INSTALL_NAME_DIR TRUE)
  74. # Setup iOS platform unless specified manually with IOS_PLATFORM
  75. if (NOT DEFINED IOS_PLATFORM)
  76. set (IOS_PLATFORM "OS")
  77. endif (NOT DEFINED IOS_PLATFORM)
  78. set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
  79. # Check the platform selection and setup for developer root
  80. if (${IOS_PLATFORM} STREQUAL OS)
  81. set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
  82. # This causes the installers to properly locate the output libraries
  83. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
  84. elseif (${IOS_PLATFORM} STREQUAL SIMULATOR)
  85. set (SIMULATOR true)
  86. set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
  87. # This causes the installers to properly locate the output libraries
  88. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
  89. elseif (${IOS_PLATFORM} STREQUAL SIMULATOR64)
  90. set (SIMULATOR true)
  91. set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
  92. # This causes the installers to properly locate the output libraries
  93. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
  94. else (${IOS_PLATFORM} STREQUAL OS)
  95. message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
  96. endif (${IOS_PLATFORM} STREQUAL OS)
  97. # Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
  98. if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
  99. exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR)
  100. set (CMAKE_IOS_DEVELOPER_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
  101. endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
  102. set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
  103. # Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
  104. if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
  105. file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
  106. if (_CMAKE_IOS_SDKS)
  107. list (SORT _CMAKE_IOS_SDKS)
  108. list (REVERSE _CMAKE_IOS_SDKS)
  109. list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
  110. else (_CMAKE_IOS_SDKS)
  111. 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.")
  112. endif (_CMAKE_IOS_SDKS)
  113. message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
  114. endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
  115. set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
  116. # Set the sysroot default to the most recent SDK
  117. set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
  118. # set the architecture for iOS
  119. if (NOT DEFINED IOS_ARCH)
  120. if (${IOS_PLATFORM} STREQUAL OS)
  121. set (IOS_ARCH arm64)
  122. elseif (${IOS_PLATFORM} STREQUAL SIMULATOR)
  123. set (IOS_ARCH i386)
  124. elseif (${IOS_PLATFORM} STREQUAL SIMULATOR64)
  125. set (IOS_ARCH x86_64)
  126. endif (${IOS_PLATFORM} STREQUAL OS)
  127. endif(NOT DEFINED IOS_ARCH)
  128. set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE STRING "Build architecture for iOS")
  129. # Set the find root to the iOS developer roots and to user defined paths
  130. set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE STRING "iOS find search path root")
  131. # default to searching for frameworks first
  132. set (CMAKE_FIND_FRAMEWORK FIRST)
  133. # set up the default search directories for frameworks
  134. set (CMAKE_SYSTEM_FRAMEWORK_PATH
  135. ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
  136. ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
  137. ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
  138. )
  139. # only search the iOS sdks, not the remainder of the host filesystem
  140. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
  141. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  142. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)