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 11 SET(CMAKE_SYSTEM_NAME Darwin) 12 SET(CMAKE_SYSTEM_VERSION 13) 13 SET(CMAKE_CXX_COMPILER_WORKS True) 14 SET(CMAKE_C_COMPILER_WORKS True) 15 SET(DARWIN_TARGET_OS_NAME ios) 16 17 IF(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) 22 ELSE() 23 execute_process(COMMAND xcodebuild -version -sdk $ENV{SDKROOT} Path 24 OUTPUT_VARIABLE SDKROOT 25 ERROR_QUIET 26 OUTPUT_STRIP_TRAILING_WHITESPACE) 27 ENDIF() 28 29 IF(NOT EXISTS ${SDKROOT}) 30 MESSAGE(FATAL_ERROR "SDKROOT could not be detected!") 31 ENDIF() 32 33 set(CMAKE_OSX_SYSROOT ${SDKROOT}) 34 35 IF(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}") 41 ENDIF() 42 43 IF(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}") 49 ENDIF() 50 51 IF(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}") 58 ENDIF() 59 60 IF(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}") 67 ENDIF() 68 69 IF (NOT DEFINED IOS_MIN_TARGET) 70 execute_process(COMMAND xcodebuild -sdk ${SDKROOT} -version SDKVersion 71 OUTPUT_VARIABLE IOS_MIN_TARGET 72 ERROR_QUIET 73 OUTPUT_STRIP_TRAILING_WHITESPACE) 74 ENDIF() 75 76 SET(IOS_COMMON_FLAGS "-mios-version-min=${IOS_MIN_TARGET}") 77 SET(CMAKE_C_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_cflags" FORCE) 78 SET(CMAKE_CXX_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_cxxflags" FORCE) 79 SET(CMAKE_LINK_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_linkflags" FORCE) 80