forked from ruslo/polly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiphone.cmake
165 lines (142 loc) · 4.36 KB
/
iphone.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Copyright (c) 2014, Ruslan Baratov
# All rights reserved.
if(DEFINED POLLY_OS_IPHONE_CMAKE)
return()
else()
set(POLLY_OS_IPHONE_CMAKE 1)
endif()
set(CMAKE_OSX_SYSROOT "iphoneos" CACHE STRING "System root for iOS" FORCE)
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
# find 'iphoneos' and 'iphonesimulator' roots and version
find_program(XCODE_SELECT_EXECUTABLE xcode-select)
if(NOT XCODE_SELECT_EXECUTABLE)
polly_fatal_error("xcode-select not found")
endif()
if(XCODE_VERSION VERSION_LESS "5.0.0")
polly_fatal_error("Works since Xcode 5.0.0 (current ver: ${XCODE_VERSION})")
endif()
if(CMAKE_VERSION VERSION_LESS "3.5")
polly_fatal_error(
"CMake minimum required version for iOS is 3.5 (current ver: ${CMAKE_VERSION})"
)
endif()
string(COMPARE EQUAL "$ENV{DEVELOPER_DIR}" "" _is_empty)
if(NOT _is_empty)
polly_status_debug("Developer root (env): $ENV{DEVELOPER_DIR}")
endif()
execute_process(
COMMAND
${XCODE_SELECT_EXECUTABLE}
"-print-path"
OUTPUT_VARIABLE
XCODE_DEVELOPER_ROOT # /.../Xcode.app/Contents/Developer
OUTPUT_STRIP_TRAILING_WHITESPACE
)
polly_status_debug("Developer root: ${XCODE_DEVELOPER_ROOT}")
find_program(XCODEBUILD_EXECUTABLE xcodebuild)
if(NOT XCODEBUILD_EXECUTABLE)
polly_fatal_error("xcodebuild not found")
endif()
# Check version exists
execute_process(
COMMAND
"${XCODEBUILD_EXECUTABLE}"
-showsdks
-sdk
"iphoneos${IOS_SDK_VERSION}"
RESULT_VARIABLE
IOS_SDK_VERSION_RESULT
OUTPUT_QUIET
ERROR_QUIET
)
if(NOT "${IOS_SDK_VERSION_RESULT}" EQUAL 0)
polly_fatal_error("iOS version `${IOS_SDK_VERSION}` not found (${IOS_SDK_VERSION_RESULT})")
endif()
# iPhone simulator root
set(
IPHONESIMULATOR_ROOT
"${XCODE_DEVELOPER_ROOT}/Platforms/iPhoneSimulator.platform/Developer"
)
if(NOT EXISTS "${IPHONESIMULATOR_ROOT}")
polly_fatal_error(
"IPHONESIMULATOR_ROOT not found (${IPHONESIMULATOR_ROOT})\n"
"XCODE_DEVELOPER_ROOT: ${XCODE_DEVELOPER_ROOT}\n"
)
endif()
# iPhone simulator SDK root
set(
IPHONESIMULATOR_SDK_ROOT
"${IPHONESIMULATOR_ROOT}/SDKs/iPhoneSimulator${IOS_SDK_VERSION}.sdk"
)
if(NOT EXISTS ${IPHONESIMULATOR_SDK_ROOT})
polly_fatal_error(
"IPHONESIMULATOR_SDK_ROOT not found (${IPHONESIMULATOR_SDK_ROOT})\n"
"IPHONESIMULATOR_ROOT: ${IPHONESIMULATOR_ROOT}\n"
"IOS_SDK_VERSION: ${IOS_SDK_VERSION}\n"
)
endif()
# iPhone root
set(
IPHONEOS_ROOT
"${XCODE_DEVELOPER_ROOT}/Platforms/iPhoneOS.platform/Developer"
)
if(NOT EXISTS "${IPHONEOS_ROOT}")
polly_fatal_error(
"IPHONEOS_ROOT not found (${IPHONEOS_ROOT})\n"
"XCODE_DEVELOPER_ROOT: ${XCODE_DEVELOPER_ROOT}\n"
)
endif()
# iPhone SDK root
set(IPHONEOS_SDK_ROOT "${IPHONEOS_ROOT}/SDKs/iPhoneOS${IOS_SDK_VERSION}.sdk")
if(NOT EXISTS ${IPHONEOS_SDK_ROOT})
hunter_fatal_error(
"IPHONEOS_SDK_ROOT not found (${IPHONEOS_SDK_ROOT})\n"
"IPHONEOS_ROOT: ${IPHONEOS_ROOT}\n"
"IOS_SDK_VERSION: ${IOS_SDK_VERSION}\n"
)
endif()
string(COMPARE EQUAL "${IOS_DEPLOYMENT_SDK_VERSION}" "" _is_empty)
if(_is_empty)
set(
CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET
"${IOS_SDK_VERSION}"
)
else()
set(
CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET
"${IOS_DEPLOYMENT_SDK_VERSION}"
)
endif()
# Emulate OpenCV toolchain --
set(IOS YES)
# -- end
# Set iPhoneOS architectures
set(archs "")
foreach(arch ${IPHONEOS_ARCHS})
set(archs "${archs} ${arch}")
endforeach()
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphoneos*] "${archs}")
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphoneos*] "${archs}")
# Set iPhoneSimulator architectures
set(archs "")
foreach(arch ${IPHONESIMULATOR_ARCHS})
set(archs "${archs} ${arch}")
endforeach()
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] "${archs}")
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] "${archs}")
# Introduced in iOS 9.0
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE NO)
# This will set CMAKE_CROSSCOMPILING to TRUE.
# CMAKE_CROSSCOMPILING needed for try_run:
# * https://cmake.org/cmake/help/latest/command/try_run.html#behavior-when-cross-compiling
# (used in CURL)
set(CMAKE_SYSTEM_NAME "Darwin")
# Set CMAKE_SYSTEM_PROCESSOR for one-arch toolchain
# (needed for OpenCV 3.3)
set(_all_archs ${IPHONESIMULATOR_ARCHS} ${IPHONEOS_ARCHS})
list(LENGTH _all_archs _all_archs_len)
if(_all_archs_len EQUAL 1)
set(CMAKE_SYSTEM_PROCESSOR ${_all_archs})
else()
set(CMAKE_SYSTEM_PROCESSOR "")
endif()