@@ -97,6 +97,10 @@ package("opencv")
97
97
local arch = (package :is_arch (" x86_64" ) and " x64" or " x86" )
98
98
local linkdir = (package :config (" shared" ) and " lib" or " staticlib" )
99
99
package :add (" linkdirs" , path.join (arch , " mingw" , linkdir ))
100
+ elseif package :is_plat (" android" ) then
101
+ local arch = package :targetarch ()
102
+ local linkdir = (package :config (" shared" ) and " lib" or " staticlibs" )
103
+ package :add (" linkdirs" , path.join (" sdk/native" , linkdir , package :targetarch ()))
100
104
elseif package :version ():ge (" 4.0" ) then
101
105
package :add (" includedirs" , " include/opencv4" )
102
106
package :add (" linkdirs" , " lib" , " lib/opencv4/3rdparty" )
@@ -136,7 +140,7 @@ package("opencv")
136
140
end )
137
141
end
138
142
139
- on_install (" linux" , " macosx" , " windows" , " mingw@windows,msys" , function (package )
143
+ on_install (" android " , " linux" , " macosx" , " windows" , " mingw@windows,msys" , function (package )
140
144
io .replace (" cmake/OpenCVUtils.cmake" , " if(PKG_CONFIG_FOUND OR PkgConfig_FOUND)" , " if(NOT WIN32 AND (PKG_CONFIG_FOUND OR PkgConfig_FOUND))" , {plain = true })
141
145
local configs = {" -DCMAKE_OSX_DEPLOYMENT_TARGET=" ,
142
146
" -DBUILD_PERF_TESTS=OFF" ,
@@ -179,8 +183,18 @@ package("opencv")
179
183
table.insert (configs , " -DCMAKE_SYSTEM_NAME=Darwin" )
180
184
elseif package :is_plat (" linux" ) then
181
185
table.insert (configs , " -DCMAKE_SYSTEM_NAME=Linux" )
186
+ elseif package :is_plat (" android" ) then
187
+ table.insert (configs , " -DCMAKE_SYSTEM_NAME=Android" )
188
+ -- from https://github.com/opencv/opencv/issues/15769#issuecomment-549570072
189
+ table.insert (configs , " -DBUILD_ANDROID_EXAMPLES=OFF" )
190
+ end
191
+
192
+ -- In case of android we prefer to set CMAKE_ANDROID_ARCH_ABI rather than CMAKE_SYSTEM_PROCESSOR
193
+ if package :is_plat (" android" ) then
194
+ table.insert (configs , " -DCMAKE_ANDROID_ARCH_ABI=" .. package :targetarch ())
195
+ else
196
+ table.insert (configs , " -DCMAKE_SYSTEM_PROCESSOR=" .. package :targetarch ())
182
197
end
183
- table.insert (configs , " -DCMAKE_SYSTEM_PROCESSOR=" .. package :targetarch ())
184
198
end
185
199
local resourcedir = package :resourcedir (" opencv_contrib" )
186
200
if resourcedir then
@@ -223,7 +237,23 @@ package("opencv")
223
237
end
224
238
package :add (" links" , reallink )
225
239
end
226
- if package :is_plat (" windows" ) then
240
+ print (" package install dir: " , package :installdir ())
241
+ if package :is_plat (" android" ) then
242
+ local linkdir = (package :config (" shared" ) and " lib" or " staticlibs" )
243
+
244
+ print (" searching libs in: " , path.join (package :installdir (), " sdk/native" , linkdir , package :targetarch ()))
245
+ local libfiles = {}
246
+ table .join2 (libfiles , os.files (path.join (package :installdir (), " sdk/native" , linkdir , package :targetarch (), " lib*.a" )))
247
+ for _ , f in ipairs (libfiles ) do
248
+ print (" found: " , f )
249
+ if f :match (" libopencv_.+" ) then
250
+ print (" adding:" , path.basename (f ))
251
+ package :add (" links" , path.basename (f ))
252
+ end
253
+ end
254
+ package :addenv (" PATH" , " bin" )
255
+
256
+ elseif package :is_plat (" windows" ) then
227
257
local arch = " x64"
228
258
if package :is_arch (" x86" ) then arch = " x86"
229
259
elseif package :is_arch (" arm64" ) then arch = " ARM64"
0 commit comments