xmake-repo
xmake-repo copied to clipboard
add opencv android
- Add support of Android opencv in xrepo
- Disabling Android tests
-DBUILD_ANDROID_EXAMPLES=OFFas it causes issues. see https://github.com/opencv/opencv/issues/15769#issuecomment-549570072 - Got issues from Android-Determine.cmake (cmake 3.28) : Android: Unknown processor CMAKE_SYSTEM_PROCESSOR=arm64-v8a, looking into the file it appears that we should map arm64-v8a to aarch64 by passing it to -DCMAKE_SYSTEM_PROCESSOR=aarch64
[Need to way a clean way to handle it] ==> done: setting the
DCMAKE_ANDROID_ARCH_ABIinstead ofDCMAKE_SYSTEM_PROCESSORfor Android seems the right way to do it.
Testing locally by running xmake l scripts/test.lua -v -D --shallow -p android --ndk=~/android-ndk-r28b --ndk_sdkver=32 -a arm64-v8a opencv
and for shared:
xmake l scripts/test.lua -v -D --shallow -p android --ndk=~/android-ndk-r27c --ndk_sdkver=32 -a arm64-v8a -k shared opencv
current state:
CMake Error at /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/cmake/OpenCVGenPkgconfig.cmake:113 (cmake_minimum_required): Compatibility with CMake < 3.5 has been removed from CMake.
Update the VERSION argument
Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
==> Looks like adding table.insert(configs, "-DCMAKE_POLICY_VERSION_MINIMUM=3.5") fixed the issue
current state:
CMake Error at /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/cmake/OpenCVGenPkgconfig.cmake:113 (cmake_minimum_required): Compatibility with CMake < 3.5 has been removed from CMake.
Update the VERSION argument value. Or, use the ... syntax to tell CMake that the project requires at least but has been updated to work with policies introduced by or earlier.
Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
==> Looks like adding table.insert(configs, "-DCMAKE_POLICY_VERSION_MINIMUM=3.5") fixed the issue
If you update xmake by xmake update dev, would it resolve this issue, so there would not need to add "-DCMAKE_POLICY_VERSION_MINIMUM=3.5"?
current state: CMake Error at /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/cmake/OpenCVGenPkgconfig.cmake:113 (cmake_minimum_required): Compatibility with CMake < 3.5 has been removed from CMake. Update the VERSION argument value. Or, use the ... syntax to tell CMake that the project requires at least but has been updated to work with policies introduced by or earlier. Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway. ==> Looks like adding table.insert(configs, "-DCMAKE_POLICY_VERSION_MINIMUM=3.5") fixed the issue
If you update xmake by
xmake update dev, would it resolve this issue, so there would not need to add"-DCMAKE_POLICY_VERSION_MINIMUM=3.5"?
Looks like it didn't work :( using xmake --version xmake v3.0.0+dev.3d3f6c3
FAILED: unix-install/opencv4.pc /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/bd/unix-install/opencv4.pc cd /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/bd && /home/kekopom/.xmake/packages/c/cmake/4.0.1/ee0342c3438b4e54a11f5d4d26f5299a/bin/cmake -DCMAKE_HELPER_SCRIPT=/home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/bd/OpenCVGenPkgConfig.info.cmake -P /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/cmake/OpenCVGenPkgconfig.cmake CMake Error at /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/cmake/OpenCVGenPkgconfig.cmake:113 (cmake_minimum_required): Compatibility with CMake < 3.5 has been removed from CMake.
Update the VERSION argument
Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
==> Looks like the warning has became an error since CMake 4.0.0 which is pulled by XMake if I am not misleading
current state: CMake Error at /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/cmake/OpenCVGenPkgconfig.cmake:113 (cmake_minimum_required): Compatibility with CMake < 3.5 has been removed from CMake. Update the VERSION argument value. Or, use the ... syntax to tell CMake that the project requires at least but has been updated to work with policies introduced by or earlier. Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway. ==> Looks like adding table.insert(configs, "-DCMAKE_POLICY_VERSION_MINIMUM=3.5") fixed the issue
If you update xmake by
xmake update dev, would it resolve this issue, so there would not need to add"-DCMAKE_POLICY_VERSION_MINIMUM=3.5"?Looks like it didn't work :( using xmake --version xmake v3.0.0+dev.3d3f6c3
FAILED: unix-install/opencv4.pc /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/bd/unix-install/opencv4.pc cd /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/bd && /home/kekopom/.xmake/packages/c/cmake/4.0.1/ee0342c3438b4e54a11f5d4d26f5299a/bin/cmake -DCMAKE_HELPER_SCRIPT=/home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/bd/OpenCVGenPkgConfig.info.cmake -P /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/cmake/OpenCVGenPkgconfig.cmake CMake Error at /home/kekopom/.xmake/cache/packages/2505/o/opencv/4.11.0/source/cmake/OpenCVGenPkgconfig.cmake:113 (cmake_minimum_required): Compatibility with CMake < 3.5 has been removed from CMake.
Update the VERSION argument value. Or, use the ... syntax to tell CMake that the project requires at least but has been updated to work with policies introduced by or earlier.
Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
==> Looks like the warning has became an error since CMake 4.0.0 which is pulled by XMake if I am not misleading
https://github.com/xmake-io/xmake/blob/ea13d87b271fbfe6ec96b90cb6b315220f4c53e9/xmake/modules/package/tools/cmake.lua#L951-L953 This supposed to pass -DCMAKE_POLICY_VERSION_MINIMUM=3.5 during build with CMake 4.0 & newer though automatically appended into configs...
@luadebug indeed I can see that the flag is well propagated to cmake
You will find below the full outputs of the command xmake l scripts/test.lua -v -D --shallow -p android --ndk=~/android-ndk-r27c --ndk_sdkver=32 -a arm64-v8a opencv
On my side I cannot understand what's wrong 😞
edit: I might have found an interesting link: https://github.com/opencv/opencv/issues/27122
adding add_patches("4.11.0", "https://raw.githubusercontent.com/eweOS/packages/refs/heads/opencv/0001-Fix-configuring-with-CMake-4.patch", "c9ac48cbcde10146af6fd9ca22d05091d5a3a35943a723bdcf4d30d51bfbf4a4") leads to a different error, I assume that it fixed the error for now
I would like also to avoid to pull a .patch from a non-opencv repo, if someone knows a better way to use a commit id maybe
leads to a different error, I assume that it fixed the error for now
I suppose it leads to
error: D:\xm\xmake-repo\packages\o\opencv\xmake.lua:311: ...amdir\core\sandbox\modules\import\core\tool\compiler.lua:84: @programdir\modules\core\tools\gcc.lua:1020: C:\Users\Admin\AppData\Local\Temp\.xmake\250507\_C595EFB0B9474EA38934169C8482FD35.cpp:2:10: fatal error: 'opencv2/opencv.hpp' file not found
2 | #include <opencv2/opencv.hpp>
| ^~~~~~~~~~~~~~~~~~~~
1 error generated.
Since package:installdir("include") folder is empty, you might need os.cp headers into this folder.
Yep I fixed it by adding package:add("includedirs", "sdk/native/jni/include")
I think it does the same as your suggestion? :)
I think I've been able to finally build it [0m[38;2;255;255;0m => [0minstall opencv 4.11.0 .. [38;2;0;255;0;1mok[0m
Both (shared / static) builds are OK
seems related to #1228
I've been able to build and run this exemple https://docs.opencv.org/4.x/d9/d15/samples_2cpp_2cout_mat_8cpp-example.html
On my Android phone!
@luadebug thanks for helping fixing windows build :D with your patch, it complains to not find links
Could it be linked with elseif package:is_arch("arm64") then arch = "ARM64" line 255?
Since you added -DAARCH64=ON should it be now aarch64 instead of "ARM64"? (in case of arm only)
It looks like linkdir for windows arm64 is x64 for local arch. Need some workaround like new implementation would support old implementation as well..
C:/Users/runneradmin/AppData/Local/.xmake/packages/o/opencv/4.11.0/954bb460d4834f52b7ff0e8b3ff4d938/x64/vc17/staticlib/opencv_dpm4110.lib
@luadebug do you know what's happening?
C:\Program Files (x86)\Windows Kits\10\include\10.0.26100.0\ucrt\wchar.h(254): error C2664: '__n64 __uint64x1_t_to_n64(uint64x1_t)': cannot convert argument 1 from 'uint16x4_t' to 'uint64x1_t'
Only related topic I could find is https://developercommunity.visualstudio.com/t/wcharh-header-fails-compilation-on-ARM6/10868106?sort=newest with no solution in it ..
Btw since we haven't changed anything for Windows ARM I would have expected it to work, I am a bit surprised
@luadebug do you know what's happening?
C:\Program Files (x86)\Windows Kits\10\include\10.0.26100.0\ucrt\wchar.h(254): error C2664: '__n64 __uint64x1_t_to_n64(uint64x1_t)': cannot convert argument 1 from 'uint16x4_t' to 'uint64x1_t'Only related topic I could find is https://developercommunity.visualstudio.com/t/wcharh-header-fails-compilation-on-ARM6/10868106?sort=newest with no solution in it ..
Why is this being mentioned, is it some current Github CI failure? Looks like issue present for 2022 worker. The only mention is https://github.com/microsoft/vcpkg/issues/44310 as it is Windows SDK version breaking changes.
Btw since we haven't changed anything for Windows ARM I would have expected it to work, I am a bit surprised
Maybe new version update broke something.
So what do we do? can we disable windows arm support for now?
So what do we do? can we disable windows arm support for now?
It looks like this package has windows@arm64 introduced exactly for 4.10.0->4.11.0... exactly for 2022 worker... about 3 months ago 4.11.0 was pushed.
if on_check then
on_check("windows|arm64", function (package)
if package:version() and package:version():lt("4.10.0") then
raise("current opencv version does not support windows/arm64!")
end
local vs = package:toolchain("msvc"):config("vs")
assert(tonumber(vs) >= 2022, "opencv requires Visual Studio 2022 and later for arm targets")
end)
end
I wish we could limit Windows SDK that being used by 2022 worker to be newer version (on_check should assert newer Windows SDK version) and at same time keep mine workaround (resolve https://github.com/xmake-io/xmake-repo/actions/runs/14924396539/job/41926501716#step:5:1292), and find fix links (add_links, linkdirs) for Windows-11 arm worker at same time. This looks tough to limit arm64 ones. Though I'm open to suggestions. I tried to filter out Windows-11 arm and 2022 workers by vs sdkver, but it seems it stopped Windows-11 arm worker as well (Im 100% sure they use same SDK version 10.0.26100.0, the only difference is bin\Host), I suppose there is some way to differ them, so vs sdkver is only what comes up, need to skip 2022 worker, but Windows-11 arm worker should build & work. Yet, need to fix links so Windows-11 arm worker would succeed.
Since you added
-DAARCH64=ONshould it be now aarch64 instead of "ARM64"? (in case of arm only)
Afaik -DARM in case of arm but not arm64 for arm64 it is -DAARCH64
Could it be linked with
elseif package:is_arch("arm64") then arch = "ARM64"line 255?
I resolved this by os.trymv but now executable opencv version issues for /MT vs runtime... This one is Im unsure what to do next. (https://github.com/opencv/opencv/blob/eae77dae865a6204fa3ef9e39803e7fb2e855b5c/cmake/OpenCVCRTLinkage.cmake#L40-L56 https://github.com/opencv/opencv/blob/eae77dae865a6204fa3ef9e39803e7fb2e855b5c/CMakeLists.txt#L497 This one looks very strange)
previous change is because if you actually follow the link that is commented line 181, (= https://github.com/opencv/opencv/issues/25052)
They said to add "-DCPU_BASELINE=NEON", I have no clue where the previous instruction (-DCPU_NEON_FP16_SUPPORTED=OFF) was from ..
reverting as it is worst xd
hey @luadebug since the scope of this MR is to add opencv for android, can we disable support of Windows-11 arm MT so that we can merge what we have now? we can open an issue for anyone that needs opencv on Windows-11 arm MT to fix it by themself instead?
On my side I've never developped under windows and got no idea how to test/fix it .. just wanted to add opencv on android at first :(
Well now need to check if MSVC Windows-2025 worker is being skipped as well as MSVC Windows-2022 worker, since they have same issue... https://github.com/opencv/opencv/issues/27401 Expected windows-11-arm worker succeed.
Is it ready now?
Is it ready now?
Yes it is ready.