[opencv4] wasm intrinsics feature (#52505)

This commit is contained in:
Nick D'Ademo 2026-06-23 12:44:28 +08:00 committed by GitHub
parent c3fa266018
commit 299db092ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 2 deletions

View File

@ -63,6 +63,10 @@ elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm")
set(TARGET_IS_ARM 1)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
set(TARGET_IS_X86_64 1)
elseif(VCPKG_TARGET_IS_EMSCRIPTEN)
# wasm32 is not x86: leaving every TARGET_IS_* unset keeps OpenCV off the x86 SSE baseline,
# whose runtime guard aborts on wasm. SIMD comes from the wasm HAL configured below.
set(TARGET_IS_WASM 1)
else()
set(TARGET_IS_X86 1)
endif()
@ -409,6 +413,20 @@ if("qt" IN_LIST FEATURES)
list(APPEND ADDITIONAL_BUILD_FLAGS "-DCMAKE_AUTOMOC=ON")
endif()
if(VCPKG_TARGET_IS_EMSCRIPTEN)
# OpenCV's CPU-optimization machinery assumes a native (x86/ARM) target. On wasm the baseline
# and dispatch lists must be empty, otherwise it bakes an x86 SSE baseline whose runtime guard
# aborts at startup. Mirrors OpenCV's own platforms/js/build_js.py.
list(APPEND ADDITIONAL_BUILD_FLAGS -DCPU_BASELINE= -DCPU_DISPATCH=)
if("intrinsics" IN_LIST FEATURES)
# SIMD via OpenCV's wasm HAL (intrin_wasm.hpp); -msimd128 makes its builtins available.
# CV_ENABLE_INTRINSICS itself is turned on by the "intrinsics" feature.
list(APPEND ADDITIONAL_BUILD_FLAGS
-DOPENCV_EXTRA_C_FLAGS=-msimd128
-DOPENCV_EXTRA_CXX_FLAGS=-msimd128)
endif()
endif()
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS

View File

@ -1,7 +1,7 @@
{
"name": "opencv4",
"version": "4.12.0",
"port-version": 4,
"port-version": 5,
"description": "Open Source Computer Vision Library",
"homepage": "https://opencv.org/",
"documentation": "https://docs.opencv.org/4.12.0/",

View File

@ -7406,7 +7406,7 @@
},
"opencv4": {
"baseline": "4.12.0",
"port-version": 4
"port-version": 5
},
"opendnp3": {
"baseline": "3.1.2",

View File

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "0e28cd8713d7b810bef28ed0d7859dd761215854",
"version": "4.12.0",
"port-version": 5
},
{
"git-tree": "7e25a9ac702b9b94264dc469895c06e82b62d283",
"version": "4.12.0",