• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Toolchain config for iOS.
2#
3# Usage:
4# mkdir build; cd build
5# cmake ..; make
6# mkdir ios; cd ios
7# cmake -DLLVM_IOS_TOOLCHAIN_DIR=/path/to/ios/ndk \
8#   -DCMAKE_TOOLCHAIN_FILE=../../cmake/platforms/iOS.cmake ../..
9# make <target>
10
11SET(CMAKE_SYSTEM_NAME Darwin)
12SET(CMAKE_SYSTEM_VERSION 13)
13SET(CMAKE_CXX_COMPILER_WORKS True)
14SET(CMAKE_C_COMPILER_WORKS True)
15SET(DARWIN_TARGET_OS_NAME ios)
16
17IF(NOT DEFINED ENV{SDKROOT})
18 execute_process(COMMAND xcodebuild -version -sdk iphoneos Path
19   OUTPUT_VARIABLE SDKROOT
20   ERROR_QUIET
21   OUTPUT_STRIP_TRAILING_WHITESPACE)
22ELSE()
23  execute_process(COMMAND xcodebuild -version -sdk $ENV{SDKROOT} Path
24   OUTPUT_VARIABLE SDKROOT
25   ERROR_QUIET
26   OUTPUT_STRIP_TRAILING_WHITESPACE)
27ENDIF()
28
29IF(NOT EXISTS ${SDKROOT})
30  MESSAGE(FATAL_ERROR "SDKROOT could not be detected!")
31ENDIF()
32
33set(CMAKE_OSX_SYSROOT ${SDKROOT})
34
35IF(NOT CMAKE_C_COMPILER)
36  execute_process(COMMAND xcrun -sdk ${SDKROOT} -find clang
37   OUTPUT_VARIABLE CMAKE_C_COMPILER
38   ERROR_QUIET
39   OUTPUT_STRIP_TRAILING_WHITESPACE)
40  message(STATUS "Using c compiler ${CMAKE_C_COMPILER}")
41ENDIF()
42
43IF(NOT CMAKE_CXX_COMPILER)
44  execute_process(COMMAND xcrun -sdk ${SDKROOT} -find clang++
45   OUTPUT_VARIABLE CMAKE_CXX_COMPILER
46   ERROR_QUIET
47   OUTPUT_STRIP_TRAILING_WHITESPACE)
48  message(STATUS "Using c compiler ${CMAKE_CXX_COMPILER}")
49ENDIF()
50
51IF(NOT CMAKE_AR)
52  execute_process(COMMAND xcrun -sdk ${SDKROOT} -find ar
53   OUTPUT_VARIABLE CMAKE_AR_val
54   ERROR_QUIET
55   OUTPUT_STRIP_TRAILING_WHITESPACE)
56  SET(CMAKE_AR ${CMAKE_AR_val} CACHE FILEPATH "Archiver")
57  message(STATUS "Using ar ${CMAKE_AR}")
58ENDIF()
59
60IF(NOT CMAKE_RANLIB)
61  execute_process(COMMAND xcrun -sdk ${SDKROOT} -find ranlib
62   OUTPUT_VARIABLE CMAKE_RANLIB_val
63   ERROR_QUIET
64   OUTPUT_STRIP_TRAILING_WHITESPACE)
65  SET(CMAKE_RANLIB ${CMAKE_RANLIB_val} CACHE FILEPATH "Ranlib")
66  message(STATUS "Using ranlib ${CMAKE_RANLIB}")
67ENDIF()
68
69IF (NOT DEFINED IOS_MIN_TARGET)
70execute_process(COMMAND xcodebuild -sdk ${SDKROOT} -version SDKVersion
71   OUTPUT_VARIABLE IOS_MIN_TARGET
72   ERROR_QUIET
73   OUTPUT_STRIP_TRAILING_WHITESPACE)
74ENDIF()
75
76SET(IOS_COMMON_FLAGS "-mios-version-min=${IOS_MIN_TARGET}")
77SET(CMAKE_C_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_cflags" FORCE)
78SET(CMAKE_CXX_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_cxxflags" FORCE)
79SET(CMAKE_LINK_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_linkflags" FORCE)
80