blob: 39b77cd0a684738268b04208ab1d64d376b66879 (
plain)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
cmake_minimum_required(VERSION 3.6)
include(RunCMake)
foreach(v TEST_ANDROID_NDK TEST_ANDROID_STANDALONE_TOOLCHAIN)
string(REPLACE "|" ";" ${v} "${${v}}")
endforeach()
function(run_Android case)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
${RunCMake_TEST_OPTIONS}
${ARGN}
)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-build)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake(${case})
run_cmake_command(${case}-build ${CMAKE_COMMAND} --build .)
endfunction()
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_SYSROOT=${CMAKE_CURRENT_SOURCE_DIR}
)
run_cmake(BadSYSROOT)
unset(RunCMake_TEST_OPTIONS)
foreach(ndk IN LISTS TEST_ANDROID_NDK)
# Load available toolchain versions and abis.
file(GLOB _config_mks
"${ndk}/build/core/toolchains/*/config.mk"
"${ndk}/toolchains/*/config.mk"
)
set(_versions "")
set(_latest_gcc 0)
set(_latest_clang "")
set(_latest_clang_vers 0)
foreach(config_mk IN LISTS _config_mks)
file(STRINGS "${config_mk}" _abis REGEX "^TOOLCHAIN_ABIS +:= +[^ ].*( |$)")
if(_abis AND "${config_mk}" MATCHES [[-((clang)?([0-9]\.[0-9]|))/config\.mk$]])
set(_version "${CMAKE_MATCH_1}")
set(_is_clang "${CMAKE_MATCH_2}")
set(_cur_vers "${CMAKE_MATCH_3}")
if(_is_clang)
if(_latest_clang_vers STREQUAL "")
# already the latest possible
elseif(_cur_vers STREQUAL "" OR _cur_vers VERSION_GREATER _latest_clang_vers)
set(_latest_clang_vers "${_cur_vers}")
set(_latest_clang "${_version}")
endif()
else()
if(_version VERSION_GREATER _latest_gcc)
set(_latest_gcc ${_version})
endif()
endif()
list(APPEND _versions "${_version}")
string(REGEX MATCHALL "[a-z][a-z0-9_-]+" _abis "${_abis}")
list(APPEND _abis_${_version} ${_abis})
endif()
endforeach()
set(_abis_ ${_abis_${_latest_gcc}})
set(_abis_clang ${_abis_${_latest_clang}})
if(_versions MATCHES "clang")
set(_versions "clang" ${_versions})
endif()
list(REMOVE_DUPLICATES _versions)
list(SORT _versions)
set(_versions ";${_versions}")
foreach(vers IN LISTS _versions)
list(REMOVE_DUPLICATES _abis_${vers})
endforeach()
# Test failure cases.
message(STATUS "ndk='${ndk}'")
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_ARCH_ABI=badabi
)
run_cmake(ndk-badabi)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_ARCH_ABI=x86
-DCMAKE_ANDROID_ARM_MODE=0
)
run_cmake(ndk-badarm)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_ARM_NEON=0
)
run_cmake(ndk-badneon)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=badver
)
run_cmake(ndk-badver)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=1.0
)
run_cmake(ndk-badvernum)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_STL_TYPE=badstl
)
run_cmake(ndk-badstl)
unset(RunCMake_TEST_OPTIONS)
# Find a sysroot to test.
file(GLOB _sysroots "${ndk}/platforms/android-[0-9][0-9]/arch-arm")
if(_sysroots)
list(GET _sysroots 0 _sysroot)
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_SYSROOT=${_sysroot}
)
run_cmake(ndk-sysroot-armeabi)
unset(RunCMake_TEST_OPTIONS)
endif()
# Find available STLs.
set(stl_types
none
system
gnustl_static
gnustl_shared
)
if(IS_DIRECTORY "${ndk}/sources/cxx-stl/gabi++/libs")
list(APPEND stl_types gabi++_static gabi++_shared)
endif()
if(IS_DIRECTORY "${ndk}/sources/cxx-stl/stlport/libs")
list(APPEND stl_types stlport_static stlport_shared)
endif()
if(IS_DIRECTORY "${ndk}/sources/cxx-stl/llvm-libc++/libs")
list(APPEND stl_types c++_static c++_shared)
endif()
# List possible ABIs.
set(abi_names
armeabi
armeabi-v6
armeabi-v7a
arm64-v8a
mips
mips64
x86
x86_64
)
# Test all combinations.
foreach(vers IN LISTS _versions)
foreach(stl IN LISTS stl_types)
foreach(config Release Debug)
# Test this combination for all available abis.
message(STATUS "ndk='${ndk}' vers='${vers}' stl='${stl}' config='${config}'")
set(RunCMake_TEST_OPTIONS
-DCMAKE_ANDROID_NDK=${ndk}
-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=${vers}
-DCMAKE_ANDROID_STL_TYPE=${stl}
-DCMAKE_BUILD_TYPE=${config}
)
foreach(abi IN LISTS abi_names)
# Skip ABIs not supported by this compiler.
if(NOT ";${_abis_${vers}};" MATCHES ";${abi};")
continue()
endif()
# Skip combinations that seem to be broken.
if("${stl};${abi}" MATCHES [[^c\+\+_static;armeabi]])
continue()
endif()
# Run the tests for this combination.
if("${abi}" STREQUAL "armeabi")
run_Android(ndk-armeabi-thumb) # default: -DCMAKE_ANDROID_ARCH_ABI=armeabi -DCMAKE_ANDROID_ARM_MODE=0
run_Android(ndk-armeabi-arm -DCMAKE_ANDROID_ARM_MODE=1) # default: -DCMAKE_ANDROID_ARCH_ABI=armeabi
else()
run_Android(ndk-${abi} -DCMAKE_ANDROID_ARCH_ABI=${abi})
if("${abi}" STREQUAL "armeabi-v7a")
run_Android(ndk-${abi}-neon -DCMAKE_ANDROID_ARCH_ABI=${abi} -DCMAKE_ANDROID_ARM_NEON=1)
endif()
endif()
endforeach()
unset(RunCMake_TEST_OPTIONS)
endforeach()
endforeach()
endforeach()
endforeach()
foreach(toolchain IN LISTS TEST_ANDROID_STANDALONE_TOOLCHAIN)
message(STATUS "toolchain='${toolchain}'")
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_SYSROOT=${toolchain}/sysroot
)
run_cmake(standalone-sysroot)
unset(RunCMake_TEST_OPTIONS)
foreach(config Release Debug)
message(STATUS "toolchain='${toolchain}' config='${config}'")
set(RunCMake_TEST_OPTIONS
-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=${toolchain}
-DCMAKE_BUILD_TYPE=${config}
)
run_Android(standalone)
unset(RunCMake_TEST_OPTIONS)
endforeach()
endforeach()
|