0
0
mirror of https://github.com/opencv/opencv.git synced 2026-01-18 17:21:42 +01:00

Merge pull request #28179 from Kumataro:fix28178

js: add C++17 requirement check for Emscripten 4.0.20+ #28179
 
Close https://github.com/opencv/opencv/issues/28178

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Kumataro
2025-12-16 16:41:43 +09:00
committed by GitHub
parent fdb1ad3aa4
commit 9c48c69c8a
2 changed files with 18 additions and 3 deletions

View File

@@ -84,7 +84,12 @@ Building OpenCV.js from Source
@endcode
@note
It requires `python` and `cmake` installed in your development environment.
- It requires `python` and `cmake` installed in your development environment.
- To build with Emscripten 4.0.20 or later, append --cmake_option="-DCMAKE_CXX_STANDARD=17" .
Embind requires C++17 or later since Emscripten 4.0.20.
@code{.bash}
emcmake python ./opencv/platforms/js/build_js.py build_js --cmake_option="-DCMAKE_CXX_STANDARD=17"
@endcode
-# [Optional] To build the OpenCV.js loader, append `--build_loader`.

View File

@@ -74,13 +74,23 @@ else()
endif()
endif()
# Embind requires C++17 or newer from Emscripten 4.0.20.
# See https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md#4020---111825
if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "4.0.20")
if(NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD STREQUAL "98"
OR CMAKE_CXX_STANDARD STREQUAL "11" OR CMAKE_CXX_STANDARD STREQUAL "14")
message(FATAL_ERROR "[OpenCV.js Build Error] "
"Emscripten ${EMSCRIPTEN_VERSION} requires C++17 or newer for Embind, "
"but CMAKE_CXX_STANDARD is set to '${CMAKE_CXX_STANDARD}'.\n"
"Please re-run emcmake with --cmake_option=\"-DCMAKE_CXX_STANDARD=17\"\n")
endif()
endif()
ocv_add_module(js BINDINGS PRIVATE_REQUIRED opencv_js_bindings_generator)
ocv_module_include_directories(${EMSCRIPTEN_INCLUDE_DIR})
add_definitions("-std=c++11")
set(deps ${OPENCV_MODULE_${the_module}_DEPS})
list(REMOVE_ITEM deps opencv_js_bindings_generator) # don't add dummy module
link_libraries(${deps})