Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

675 řádky
29KB

  1. # This file is part of the ios-cmake project. It was retrieved from
  2. # https://github.com/cristeab/ios-cmake.git, which is a fork of
  3. # https://code.google.com/p/ios-cmake/. Which in turn is based off of
  4. # the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which
  5. # are included with CMake 2.8.4
  6. #
  7. # The ios-cmake project is licensed under the new BSD license.
  8. #
  9. # Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software,
  10. # Kitware, Inc., Insight Software Consortium. All rights reserved.
  11. # Redistribution and use in source and binary forms, with or without
  12. # modification, are permitted provided that the following conditions
  13. # are met:
  14. # 1. Redistributions of source code must retain the above copyright
  15. # notice, this list of conditions and the following disclaimer.
  16. #
  17. # 2. Redistributions in binary form must reproduce the above copyright
  18. # notice, this list of conditions and the following disclaimer in the
  19. # documentation and/or other materials provided with the distribution.
  20. #
  21. # 3. Neither the name of the copyright holder nor the names of its
  22. # contributors may be used to endorse or promote products derived from
  23. # this software without specific prior written permission.
  24. #
  25. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  28. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  29. # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  30. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  31. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  32. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  35. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. # POSSIBILITY OF SUCH DAMAGE.
  37. #
  38. # This file is based off of the Platform/Darwin.cmake and
  39. # Platform/UnixPaths.cmake files which are included with CMake 2.8.4
  40. # It has been altered for iOS development.
  41. #
  42. # Updated by Alex Stewart (alexs.mac@gmail.com)
  43. #
  44. # *****************************************************************************
  45. # Now maintained by Alexander Widerberg (widerbergaren [at] gmail.com)
  46. # under the BSD-3-Clause license
  47. # https://github.com/leetal/ios-cmake
  48. # *****************************************************************************
  49. #
  50. # INFORMATION / HELP
  51. #
  52. # The following arguments control the behaviour of this toolchain:
  53. #
  54. # PLATFORM: (default "OS")
  55. # OS = Build for iPhoneOS.
  56. # OS64 = Build for arm64 iphoneOS.
  57. # OS64COMBINED = Build for arm64 x86_64 iphoneOS. Combined into FAT STATIC lib (supported on 3.14+ of CMakewith "-G Xcode" argument ONLY)
  58. # SIMULATOR = Build for x86 i386 iphoneOS Simulator.
  59. # SIMULATOR64 = Build for x86_64 iphoneOS Simulator.
  60. # TVOS = Build for arm64 tvOS.
  61. # TVOSCOMBINED = Build for arm64 x86_64 tvOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY)
  62. # SIMULATOR_TVOS = Build for x86_64 tvOS Simulator.
  63. # WATCHOS = Build for armv7k arm64_32 for watchOS.
  64. # WATCHOSCOMBINED = Build for armv7k arm64_32 x86_64 watchOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY)
  65. # SIMULATOR_WATCHOS = Build for x86_64 for watchOS Simulator.
  66. #
  67. # CMAKE_OSX_SYSROOT: Path to the SDK to use. By default this is
  68. # automatically determined from PLATFORM and xcodebuild, but
  69. # can also be manually specified (although this should not be required).
  70. #
  71. # CMAKE_DEVELOPER_ROOT: Path to the Developer directory for the platform
  72. # being compiled for. By default this is automatically determined from
  73. # CMAKE_OSX_SYSROOT, but can also be manually specified (although this should
  74. # not be required).
  75. #
  76. # DEPLOYMENT_TARGET: Minimum SDK version to target. Default 2.0 on watchOS and 9.0 on tvOS+iOS
  77. #
  78. # ENABLE_BITCODE: (1|0) Enables or disables bitcode support. Default 1 (true)
  79. #
  80. # ENABLE_ARC: (1|0) Enables or disables ARC support. Default 1 (true, ARC enabled by default)
  81. #
  82. # ENABLE_VISIBILITY: (1|0) Enables or disables symbol visibility support. Default 0 (false, visibility hidden by default)
  83. #
  84. # ENABLE_STRICT_TRY_COMPILE: (1|0) Enables or disables strict try_compile() on all Check* directives (will run linker
  85. # to actually check if linking is possible). Default 0 (false, will set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY)
  86. #
  87. # ARCHS: (armv7 armv7s armv7k arm64 arm64_32 i386 x86_64) If specified, will override the default architectures for the given PLATFORM
  88. # OS = armv7 armv7s arm64 (if applicable)
  89. # OS64 = arm64 (if applicable)
  90. # SIMULATOR = i386
  91. # SIMULATOR64 = x86_64
  92. # TVOS = arm64
  93. # SIMULATOR_TVOS = x86_64 (i386 has since long been deprecated)
  94. # WATCHOS = armv7k arm64_32 (if applicable)
  95. # SIMULATOR_WATCHOS = x86_64 (i386 has since long been deprecated)
  96. #
  97. # This toolchain defines the following variables for use externally:
  98. #
  99. # XCODE_VERSION: Version number (not including Build version) of Xcode detected.
  100. # SDK_VERSION: Version of SDK being used.
  101. # CMAKE_OSX_ARCHITECTURES: Architectures being compiled for (generated from PLATFORM).
  102. #
  103. # This toolchain defines the following macros for use externally:
  104. #
  105. # set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE XCODE_VARIANT)
  106. # A convenience macro for setting xcode specific properties on targets.
  107. # Available variants are: All, Release, RelWithDebInfo, Debug, MinSizeRel
  108. # example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1" "all").
  109. #
  110. # find_host_package (PROGRAM ARGS)
  111. # A macro used to find executable programs on the host system, not within the
  112. # environment. Thanks to the android-cmake project for providing the
  113. # command.
  114. #
  115. # ******************************** DEPRECATIONS *******************************
  116. #
  117. # IOS_DEPLOYMENT_TARGET: (Deprecated) Alias to DEPLOYMENT_TARGET
  118. # CMAKE_IOS_DEVELOPER_ROOT: (Deprecated) Alias to CMAKE_DEVELOPER_ROOT
  119. # IOS_PLATFORM: (Deprecated) Alias to PLATFORM
  120. # IOS_ARCH: (Deprecated) Alias to ARCHS
  121. #
  122. # *****************************************************************************
  123. #
  124. # Fix for PThread library not in path
  125. set(CMAKE_THREAD_LIBS_INIT "-lpthread")
  126. set(CMAKE_HAVE_THREADS_LIBRARY 1)
  127. set(CMAKE_USE_WIN32_THREADS_INIT 0)
  128. set(CMAKE_USE_PTHREADS_INIT 1)
  129. # Cache what generator is used
  130. set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE)
  131. if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14")
  132. set(MODERN_CMAKE YES)
  133. message(STATUS "Merging integrated CMake 3.14+ iOS,tvOS,watchOS,macOS toolchain(s) with this toolchain!")
  134. endif()
  135. # Get the Xcode version being used.
  136. execute_process(COMMAND xcodebuild -version
  137. OUTPUT_VARIABLE XCODE_VERSION
  138. ERROR_QUIET
  139. OUTPUT_STRIP_TRAILING_WHITESPACE)
  140. string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}")
  141. string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}")
  142. message(STATUS "Building with Xcode version: ${XCODE_VERSION}")
  143. ######## ALIASES (DEPRECATION WARNINGS)
  144. if(DEFINED IOS_PLATFORM)
  145. set(PLATFORM ${IOS_PLATFORM})
  146. message(DEPRECATION "IOS_PLATFORM argument is DEPRECATED. Consider using the new PLATFORM argument instead.")
  147. endif()
  148. if(DEFINED IOS_DEPLOYMENT_TARGET)
  149. set(DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET})
  150. message(DEPRECATION "IOS_DEPLOYMENT_TARGET argument is DEPRECATED. Consider using the new DEPLOYMENT_TARGET argument instead.")
  151. endif()
  152. if(DEFINED CMAKE_IOS_DEVELOPER_ROOT)
  153. set(CMAKE_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT})
  154. message(DEPRECATION "CMAKE_IOS_DEVELOPER_ROOT argument is DEPRECATED. Consider using the new CMAKE_DEVELOPER_ROOT argument instead.")
  155. endif()
  156. if(DEFINED IOS_ARCH)
  157. set(ARCHS ${IOS_ARCH})
  158. message(DEPRECATION "IOS_ARCH argument is DEPRECATED. Consider using the new ARCHS argument instead.")
  159. endif()
  160. ######## END ALIASES
  161. # Unset the FORCE on cache variables if in try_compile()
  162. set(FORCE_CACHE FORCE)
  163. get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
  164. if(_CMAKE_IN_TRY_COMPILE)
  165. unset(FORCE_CACHE)
  166. endif()
  167. # Default to building for iPhoneOS if not specified otherwise, and we cannot
  168. # determine the platform from the CMAKE_OSX_ARCHITECTURES variable. The use
  169. # of CMAKE_OSX_ARCHITECTURES is such that try_compile() projects can correctly
  170. # determine the value of PLATFORM from the root project, as
  171. # CMAKE_OSX_ARCHITECTURES is propagated to them by CMake.
  172. if(NOT DEFINED PLATFORM)
  173. if (CMAKE_OSX_ARCHITECTURES)
  174. if(CMAKE_OSX_ARCHITECTURES MATCHES ".*arm.*" AND CMAKE_OSX_SYSROOT MATCHES ".*iphoneos.*")
  175. set(PLATFORM "OS")
  176. elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*")
  177. set(PLATFORM "SIMULATOR")
  178. elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*")
  179. set(PLATFORM "SIMULATOR64")
  180. elseif(CMAKE_OSX_ARCHITECTURES MATCHES "arm64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvos.*")
  181. set(PLATFORM "TVOS")
  182. elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvsimulator.*")
  183. set(PLATFORM "SIMULATOR_TVOS")
  184. elseif(CMAKE_OSX_ARCHITECTURES MATCHES ".*armv7k.*" AND CMAKE_OSX_SYSROOT MATCHES ".*watchos.*")
  185. set(PLATFORM "WATCHOS")
  186. elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*watchsimulator.*")
  187. set(PLATFORM "SIMULATOR_WATCHOS")
  188. endif()
  189. endif()
  190. if (NOT PLATFORM)
  191. set(PLATFORM "OS")
  192. endif()
  193. endif()
  194. set(PLATFORM_INT "${PLATFORM}" CACHE STRING "Type of platform for which the build targets.")
  195. # Handle the case where we are targeting iOS and a version above 10.3.4 (32-bit support dropped officially)
  196. if(PLATFORM_INT STREQUAL "OS" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4)
  197. set(PLATFORM_INT "OS64")
  198. message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.")
  199. elseif(PLATFORM_INT STREQUAL "SIMULATOR" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4)
  200. set(PLATFORM_INT "SIMULATOR64")
  201. message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.")
  202. endif()
  203. # Determine the platform name and architectures for use in xcodebuild commands
  204. # from the specified PLATFORM name.
  205. if(PLATFORM_INT STREQUAL "OS")
  206. set(SDK_NAME iphoneos)
  207. if(NOT ARCHS)
  208. set(ARCHS armv7 armv7s arm64)
  209. endif()
  210. elseif(PLATFORM_INT STREQUAL "OS64")
  211. set(SDK_NAME iphoneos)
  212. if(NOT ARCHS)
  213. if (XCODE_VERSION VERSION_GREATER 10.0)
  214. set(ARCHS arm64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example
  215. else()
  216. set(ARCHS arm64)
  217. endif()
  218. endif()
  219. elseif(PLATFORM_INT STREQUAL "OS64COMBINED")
  220. set(SDK_NAME iphoneos)
  221. if(MODERN_CMAKE)
  222. if(NOT ARCHS)
  223. if (XCODE_VERSION VERSION_GREATER 10.0)
  224. set(ARCHS arm64 x86_64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example
  225. else()
  226. set(ARCHS arm64 x86_64)
  227. endif()
  228. endif()
  229. else()
  230. message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the OS64COMBINED setting work")
  231. endif()
  232. elseif(PLATFORM_INT STREQUAL "SIMULATOR")
  233. set(SDK_NAME iphonesimulator)
  234. if(NOT ARCHS)
  235. set(ARCHS i386)
  236. endif()
  237. message(DEPRECATION "SIMULATOR IS DEPRECATED. Consider using SIMULATOR64 instead.")
  238. elseif(PLATFORM_INT STREQUAL "SIMULATOR64")
  239. set(SDK_NAME iphonesimulator)
  240. if(NOT ARCHS)
  241. set(ARCHS x86_64)
  242. endif()
  243. elseif(PLATFORM_INT STREQUAL "TVOS")
  244. set(SDK_NAME appletvos)
  245. if(NOT ARCHS)
  246. set(ARCHS arm64)
  247. endif()
  248. elseif (PLATFORM_INT STREQUAL "TVOSCOMBINED")
  249. set(SDK_NAME appletvos)
  250. if(MODERN_CMAKE)
  251. if(NOT ARCHS)
  252. set(ARCHS arm64 x86_64)
  253. endif()
  254. else()
  255. message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the TVOSCOMBINED setting work")
  256. endif()
  257. elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS")
  258. set(SDK_NAME appletvsimulator)
  259. if(NOT ARCHS)
  260. set(ARCHS x86_64)
  261. endif()
  262. elseif(PLATFORM_INT STREQUAL "WATCHOS")
  263. set(SDK_NAME watchos)
  264. if(NOT ARCHS)
  265. if (XCODE_VERSION VERSION_GREATER 10.0)
  266. set(ARCHS armv7k arm64_32)
  267. else()
  268. set(ARCHS armv7k)
  269. endif()
  270. endif()
  271. elseif(PLATFORM_INT STREQUAL "WATCHOSCOMBINED")
  272. set(SDK_NAME watchos)
  273. if(MODERN_CMAKE)
  274. if(NOT ARCHS)
  275. if (XCODE_VERSION VERSION_GREATER 10.0)
  276. set(ARCHS armv7k arm64_32 i386)
  277. else()
  278. set(ARCHS armv7k i386)
  279. endif()
  280. endif()
  281. else()
  282. message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the WATCHOSCOMBINED setting work")
  283. endif()
  284. elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS")
  285. set(SDK_NAME watchsimulator)
  286. if(NOT ARCHS)
  287. set(ARCHS i386)
  288. endif()
  289. else()
  290. message(FATAL_ERROR "Invalid PLATFORM: ${PLATFORM_INT}")
  291. endif()
  292. message(STATUS "Configuring ${SDK_NAME} build for platform: ${PLATFORM_INT}, architecture(s): ${ARCHS}")
  293. if(MODERN_CMAKE AND PLATFORM_INT MATCHES ".*COMBINED" AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode")
  294. message(FATAL_ERROR "The COMBINED options only work with Xcode generator, -G Xcode")
  295. endif()
  296. # If user did not specify the SDK root to use, then query xcodebuild for it.
  297. execute_process(COMMAND xcodebuild -version -sdk ${SDK_NAME} Path
  298. OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_INT
  299. ERROR_QUIET
  300. OUTPUT_STRIP_TRAILING_WHITESPACE)
  301. if (NOT DEFINED CMAKE_OSX_SYSROOT_INT AND NOT DEFINED CMAKE_OSX_SYSROOT)
  302. message(SEND_ERROR "Please make sure that Xcode is installed and that the toolchain"
  303. "is pointing to the correct path. Please run:"
  304. "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer"
  305. "and see if that fixes the problem for you.")
  306. message(FATAL_ERROR "Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} "
  307. "does not exist.")
  308. elseif(DEFINED CMAKE_OSX_SYSROOT)
  309. message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT} for platform: ${PLATFORM_INT} when checking compatibility")
  310. elseif(DEFINED CMAKE_OSX_SYSROOT_INT)
  311. message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT_INT} for platform: ${PLATFORM_INT}")
  312. set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "")
  313. endif()
  314. # Set Xcode property for SDKROOT as well if Xcode generator is used
  315. if(USED_CMAKE_GENERATOR MATCHES "Xcode")
  316. set(CMAKE_OSX_SYSROOT "${SDK_NAME}" CACHE INTERNAL "")
  317. if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM)
  318. set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM 123456789A CACHE INTERNAL "")
  319. endif()
  320. endif()
  321. # Specify minimum version of deployment target.
  322. if(NOT DEFINED DEPLOYMENT_TARGET)
  323. if (PLATFORM_INT STREQUAL "WATCHOS" OR PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS")
  324. # Unless specified, SDK version 2.0 is used by default as minimum target version (watchOS).
  325. set(DEPLOYMENT_TARGET "2.0"
  326. CACHE STRING "Minimum SDK version to build for." )
  327. else()
  328. # Unless specified, SDK version 9.0 is used by default as minimum target version (iOS, tvOS).
  329. set(DEPLOYMENT_TARGET "9.0"
  330. CACHE STRING "Minimum SDK version to build for." )
  331. endif()
  332. message(STATUS "Using the default min-version since DEPLOYMENT_TARGET not provided!")
  333. endif()
  334. # Use bitcode or not
  335. if(NOT DEFINED ENABLE_BITCODE AND NOT ARCHS MATCHES "((^|;|, )(i386|x86_64))+")
  336. # Unless specified, enable bitcode support by default
  337. message(STATUS "Enabling bitcode support by default. ENABLE_BITCODE not provided!")
  338. set(ENABLE_BITCODE TRUE)
  339. elseif(NOT DEFINED ENABLE_BITCODE)
  340. message(STATUS "Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!")
  341. set(ENABLE_BITCODE FALSE)
  342. endif()
  343. set(ENABLE_BITCODE_INT ${ENABLE_BITCODE} CACHE BOOL "Whether or not to enable bitcode" ${FORCE_CACHE})
  344. # Use ARC or not
  345. if(NOT DEFINED ENABLE_ARC)
  346. # Unless specified, enable ARC support by default
  347. set(ENABLE_ARC TRUE)
  348. message(STATUS "Enabling ARC support by default. ENABLE_ARC not provided!")
  349. endif()
  350. set(ENABLE_ARC_INT ${ENABLE_ARC} CACHE BOOL "Whether or not to enable ARC" ${FORCE_CACHE})
  351. # Use hidden visibility or not
  352. if(NOT DEFINED ENABLE_VISIBILITY)
  353. # Unless specified, disable symbols visibility by default
  354. set(ENABLE_VISIBILITY FALSE)
  355. message(STATUS "Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!")
  356. endif()
  357. set(ENABLE_VISIBILITY_INT ${ENABLE_VISIBILITY} CACHE BOOL "Whether or not to hide symbols (-fvisibility=hidden)" ${FORCE_CACHE})
  358. # Set strict compiler checks or not
  359. if(NOT DEFINED ENABLE_STRICT_TRY_COMPILE)
  360. # Unless specified, disable strict try_compile()
  361. set(ENABLE_STRICT_TRY_COMPILE FALSE)
  362. message(STATUS "Using NON-strict compiler checks by default. ENABLE_STRICT_TRY_COMPILE not provided!")
  363. endif()
  364. set(ENABLE_STRICT_TRY_COMPILE_INT ${ENABLE_STRICT_TRY_COMPILE} CACHE BOOL "Whether or not to use strict compiler checks" ${FORCE_CACHE})
  365. # Get the SDK version information.
  366. execute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion
  367. OUTPUT_VARIABLE SDK_VERSION
  368. ERROR_QUIET
  369. OUTPUT_STRIP_TRAILING_WHITESPACE)
  370. # Find the Developer root for the specific iOS platform being compiled for
  371. # from CMAKE_OSX_SYSROOT. Should be ../../ from SDK specified in
  372. # CMAKE_OSX_SYSROOT. There does not appear to be a direct way to obtain
  373. # this information from xcrun or xcodebuild.
  374. if (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode")
  375. get_filename_component(PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH)
  376. get_filename_component(CMAKE_DEVELOPER_ROOT ${PLATFORM_SDK_DIR} PATH)
  377. if (NOT DEFINED CMAKE_DEVELOPER_ROOT)
  378. message(FATAL_ERROR "Invalid CMAKE_DEVELOPER_ROOT: "
  379. "${CMAKE_DEVELOPER_ROOT} does not exist.")
  380. endif()
  381. endif()
  382. # Find the C & C++ compilers for the specified SDK.
  383. if(NOT CMAKE_C_COMPILER)
  384. execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang
  385. OUTPUT_VARIABLE CMAKE_C_COMPILER
  386. ERROR_QUIET
  387. OUTPUT_STRIP_TRAILING_WHITESPACE)
  388. message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}")
  389. endif()
  390. if(NOT CMAKE_CXX_COMPILER)
  391. execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang++
  392. OUTPUT_VARIABLE CMAKE_CXX_COMPILER
  393. ERROR_QUIET
  394. OUTPUT_STRIP_TRAILING_WHITESPACE)
  395. message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}")
  396. endif()
  397. # Find (Apple's) libtool.
  398. execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find libtool
  399. OUTPUT_VARIABLE BUILD_LIBTOOL
  400. ERROR_QUIET
  401. OUTPUT_STRIP_TRAILING_WHITESPACE)
  402. message(STATUS "Using libtool: ${BUILD_LIBTOOL}")
  403. # Configure libtool to be used instead of ar + ranlib to build static libraries.
  404. # This is required on Xcode 7+, but should also work on previous versions of
  405. # Xcode.
  406. set(CMAKE_C_CREATE_STATIC_LIBRARY
  407. "${BUILD_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
  408. set(CMAKE_CXX_CREATE_STATIC_LIBRARY
  409. "${BUILD_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
  410. # Find the toolchain's provided install_name_tool if none is found on the host
  411. if(NOT CMAKE_INSTALL_NAME_TOOL)
  412. execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find install_name_tool
  413. OUTPUT_VARIABLE CMAKE_INSTALL_NAME_TOOL_INT
  414. ERROR_QUIET
  415. OUTPUT_STRIP_TRAILING_WHITESPACE)
  416. set(CMAKE_INSTALL_NAME_TOOL ${CMAKE_INSTALL_NAME_TOOL_INT} CACHE STRING "" ${FORCE_CACHE})
  417. message(STATUS "Using install_name_tool: ${CMAKE_INSTALL_NAME_TOOL}")
  418. endif()
  419. # Get the version of Darwin (OS X) of the host.
  420. execute_process(COMMAND uname -r
  421. OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION
  422. ERROR_QUIET
  423. OUTPUT_STRIP_TRAILING_WHITESPACE)
  424. # CMake 3.14+ support building for iOS, watchOS and tvOS out of the box.
  425. if(MODERN_CMAKE)
  426. if(SDK_NAME MATCHES "iphone")
  427. set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE})
  428. elseif(SDK_NAME MATCHES "appletv")
  429. set(CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL "" ${FORCE_CACHE})
  430. elseif(SDK_NAME MATCHES "watch")
  431. set(CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL "" ${FORCE_CACHE})
  432. endif()
  433. # Provide flags for a combined FAT library build on newer CMake versions
  434. if(PLATFORM_INT MATCHES ".*COMBINED")
  435. set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO CACHE INTERNAL "" ${FORCE_CACHE})
  436. set(CMAKE_IOS_INSTALL_COMBINED YES CACHE INTERNAL "" ${FORCE_CACHE})
  437. message(STATUS "Will combine built (static) artifacts into FAT lib...")
  438. endif()
  439. else()
  440. # Legacy code path prior to CMake 3.14
  441. set(CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "" ${FORCE_CACHE})
  442. endif()
  443. # Standard settings.
  444. set(CMAKE_SYSTEM_VERSION ${SDK_VERSION} CACHE INTERNAL "")
  445. set(UNIX TRUE CACHE BOOL "")
  446. set(APPLE TRUE CACHE BOOL "")
  447. set(IOS TRUE CACHE BOOL "")
  448. set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
  449. set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE)
  450. set(CMAKE_STRIP strip CACHE FILEPATH "" FORCE)
  451. # Set the architectures for which to build.
  452. set(CMAKE_OSX_ARCHITECTURES ${ARCHS} CACHE STRING "Build architecture for iOS")
  453. # Change the type of target generated for try_compile() so it'll work when cross-compiling, weak compiler checks
  454. if(ENABLE_STRICT_TRY_COMPILE_INT)
  455. message(STATUS "Using strict compiler checks (default in CMake).")
  456. else()
  457. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  458. endif()
  459. # All iOS/Darwin specific settings - some may be redundant.
  460. set(CMAKE_MACOSX_BUNDLE YES)
  461. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
  462. set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
  463. set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
  464. set(CMAKE_SHARED_MODULE_PREFIX "lib")
  465. set(CMAKE_SHARED_MODULE_SUFFIX ".so")
  466. set(CMAKE_C_COMPILER_ABI ELF)
  467. set(CMAKE_CXX_COMPILER_ABI ELF)
  468. set(CMAKE_C_HAS_ISYSROOT 1)
  469. set(CMAKE_CXX_HAS_ISYSROOT 1)
  470. set(CMAKE_MODULE_EXISTS 1)
  471. set(CMAKE_DL_LIBS "")
  472. set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
  473. set(CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
  474. set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
  475. set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
  476. if(ARCHS MATCHES "((^|;|, )(arm64|arm64e|x86_64))+")
  477. set(CMAKE_C_SIZEOF_DATA_PTR 8)
  478. set(CMAKE_CXX_SIZEOF_DATA_PTR 8)
  479. if(ARCHS MATCHES "((^|;|, )(arm64|arm64e))+")
  480. set(CMAKE_SYSTEM_PROCESSOR "aarch64")
  481. else()
  482. set(CMAKE_SYSTEM_PROCESSOR "x86_64")
  483. endif()
  484. message(STATUS "Using a data_ptr size of 8")
  485. else()
  486. set(CMAKE_C_SIZEOF_DATA_PTR 4)
  487. set(CMAKE_CXX_SIZEOF_DATA_PTR 4)
  488. set(CMAKE_SYSTEM_PROCESSOR "arm")
  489. message(STATUS "Using a data_ptr size of 4")
  490. endif()
  491. message(STATUS "Building for minimum ${SDK_NAME} version: ${DEPLOYMENT_TARGET}"
  492. " (SDK version: ${SDK_VERSION})")
  493. # Note that only Xcode 7+ supports the newer more specific:
  494. # -m${SDK_NAME}-version-min flags, older versions of Xcode use:
  495. # -m(ios/ios-simulator)-version-min instead.
  496. if(PLATFORM_INT STREQUAL "OS" OR PLATFORM_INT STREQUAL "OS64")
  497. if(XCODE_VERSION VERSION_LESS 7.0)
  498. set(SDK_NAME_VERSION_FLAGS
  499. "-mios-version-min=${DEPLOYMENT_TARGET}")
  500. else()
  501. # Xcode 7.0+ uses flags we can build directly from SDK_NAME.
  502. set(SDK_NAME_VERSION_FLAGS
  503. "-m${SDK_NAME}-version-min=${DEPLOYMENT_TARGET}")
  504. endif()
  505. elseif(PLATFORM_INT STREQUAL "TVOS")
  506. set(SDK_NAME_VERSION_FLAGS
  507. "-mtvos-version-min=${DEPLOYMENT_TARGET}")
  508. elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS")
  509. set(SDK_NAME_VERSION_FLAGS
  510. "-mtvos-simulator-version-min=${DEPLOYMENT_TARGET}")
  511. elseif(PLATFORM_INT STREQUAL "WATCHOS")
  512. set(SDK_NAME_VERSION_FLAGS
  513. "-mwatchos-version-min=${DEPLOYMENT_TARGET}")
  514. elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS")
  515. set(SDK_NAME_VERSION_FLAGS
  516. "-mwatchos-simulator-version-min=${DEPLOYMENT_TARGET}")
  517. else()
  518. # SIMULATOR or SIMULATOR64 both use -mios-simulator-version-min.
  519. set(SDK_NAME_VERSION_FLAGS
  520. "-mios-simulator-version-min=${DEPLOYMENT_TARGET}")
  521. endif()
  522. message(STATUS "Version flags set to: ${SDK_NAME_VERSION_FLAGS}")
  523. set(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} CACHE STRING
  524. "Set CMake deployment target" ${FORCE_CACHE})
  525. if(ENABLE_BITCODE_INT)
  526. set(BITCODE "-fembed-bitcode")
  527. set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode CACHE INTERNAL "")
  528. message(STATUS "Enabling bitcode support.")
  529. else()
  530. set(BITCODE "")
  531. set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE NO CACHE INTERNAL "")
  532. message(STATUS "Disabling bitcode support.")
  533. endif()
  534. if(ENABLE_ARC_INT)
  535. set(FOBJC_ARC "-fobjc-arc")
  536. set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES CACHE INTERNAL "")
  537. message(STATUS "Enabling ARC support.")
  538. else()
  539. set(FOBJC_ARC "-fno-objc-arc")
  540. set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC NO CACHE INTERNAL "")
  541. message(STATUS "Disabling ARC support.")
  542. endif()
  543. if(NOT ENABLE_VISIBILITY_INT)
  544. set(VISIBILITY "-fvisibility=hidden")
  545. set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES CACHE INTERNAL "")
  546. message(STATUS "Hiding symbols (-fvisibility=hidden).")
  547. else()
  548. set(VISIBILITY "")
  549. set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN NO CACHE INTERNAL "")
  550. endif()
  551. #Check if Xcode generator is used, since that will handle these flags automagically
  552. if(USED_CMAKE_GENERATOR MATCHES "Xcode")
  553. message(STATUS "Not setting any manual command-line buildflags, since Xcode is selected as generator.")
  554. else()
  555. set(CMAKE_C_FLAGS
  556. "${SDK_NAME_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}")
  557. # Hidden visibilty is required for C++ on iOS.
  558. set(CMAKE_CXX_FLAGS
  559. "${SDK_NAME_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} -fvisibility-inlines-hidden -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_CXX_FLAGS}")
  560. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g ${CMAKE_CXX_FLAGS_DEBUG}")
  561. set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG -Os -ffast-math ${CMAKE_CXX_FLAGS_MINSIZEREL}")
  562. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -g -ffast-math ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
  563. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -ffast-math ${CMAKE_CXX_FLAGS_RELEASE}")
  564. set(CMAKE_C_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
  565. set(CMAKE_CXX_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
  566. # In order to ensure that the updated compiler flags are used in try_compile()
  567. # tests, we have to forcibly set them in the CMake cache, not merely set them
  568. # in the local scope.
  569. list(APPEND VARS_TO_FORCE_IN_CACHE
  570. CMAKE_C_FLAGS
  571. CMAKE_CXX_FLAGS
  572. CMAKE_CXX_FLAGS_DEBUG
  573. CMAKE_CXX_FLAGS_RELWITHDEBINFO
  574. CMAKE_CXX_FLAGS_MINSIZEREL
  575. CMAKE_CXX_FLAGS_RELEASE
  576. CMAKE_C_LINK_FLAGS
  577. CMAKE_CXX_LINK_FLAGS)
  578. foreach(VAR_TO_FORCE ${VARS_TO_FORCE_IN_CACHE})
  579. set(${VAR_TO_FORCE} "${${VAR_TO_FORCE}}" CACHE STRING "")
  580. endforeach()
  581. endif()
  582. set(CMAKE_PLATFORM_HAS_INSTALLNAME 1)
  583. set(CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks")
  584. set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names")
  585. set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -Wl,-headerpad_max_install_names")
  586. set(CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
  587. set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
  588. set(CMAKE_FIND_LIBRARY_SUFFIXES ".tbd" ".dylib" ".so" ".a")
  589. set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name")
  590. # Set the find root to the iOS developer roots and to user defined paths.
  591. set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT_INT} ${CMAKE_PREFIX_PATH} CACHE STRING "Root path that will be prepended
  592. to all search paths")
  593. # Default to searching for frameworks first.
  594. set(CMAKE_FIND_FRAMEWORK FIRST)
  595. # Set up the default search directories for frameworks.
  596. set(CMAKE_FRAMEWORK_PATH
  597. ${CMAKE_DEVELOPER_ROOT}/Library/PrivateFrameworks
  598. ${CMAKE_OSX_SYSROOT_INT}/System/Library/Frameworks
  599. ${CMAKE_FRAMEWORK_PATH} CACHE STRING "Frameworks search paths" ${FORCE_CACHE})
  600. # By default, search both the specified iOS SDK and the remainder of the host filesystem.
  601. if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM)
  602. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE STRING "" ${FORCE_CACHE})
  603. endif()
  604. if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
  605. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE STRING "" ${FORCE_CACHE})
  606. endif()
  607. if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)
  608. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE STRING "" ${FORCE_CACHE})
  609. endif()
  610. if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE)
  611. set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY CACHE STRING "" ${FORCE_CACHE})
  612. endif()
  613. #
  614. # Some helper-macros below to simplify and beautify the CMakeFile
  615. #
  616. # This little macro lets you set any Xcode specific property.
  617. macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE XCODE_RELVERSION)
  618. set(XCODE_RELVERSION_I "${XCODE_RELVERSION}")
  619. if(XCODE_RELVERSION_I STREQUAL "All")
  620. set_property(TARGET ${TARGET} PROPERTY
  621. XCODE_ATTRIBUTE_${XCODE_PROPERTY} "${XCODE_VALUE}")
  622. else()
  623. set_property(TARGET ${TARGET} PROPERTY
  624. XCODE_ATTRIBUTE_${XCODE_PROPERTY}[variant=${XCODE_RELVERSION_I}] "${XCODE_VALUE}")
  625. endif()
  626. endmacro(set_xcode_property)
  627. # This macro lets you find executable programs on the host system.
  628. macro(find_host_package)
  629. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  630. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
  631. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
  632. set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)
  633. set(IOS FALSE)
  634. find_package(${ARGN})
  635. set(IOS TRUE)
  636. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
  637. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
  638. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
  639. set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
  640. endmacro(find_host_package)