Currently, if I want to use OpenCV as an emscripten dependency, I need to manually add the includes and libraries with some GLOB
. I wished OpenCV, when building the library to wasm, would provide an OpenCVConfig.cmake
file with all the dependencies setting done. It would allow using the classic ${OpenCV_INCLUDE_DIRS}
and ${OpenCV_LIBS}
when targetting wasm.
My current CMakeLists.txt
to compile a simple hello.cpp
looks like below. Is there a better way to use cmake with the OpenCV wasm build?
cmake_minimum_required( VERSION 3.1 )
set( CMAKE_CXX_STANDARD 11 )
project( HelloCV )
# Does not work
# find_package( OpenCV REQUIRED PATHS third-party/opencv-4.1.0/build_wasm NO_DEFAULT_PATH)
# Needed for opencv2/opencv.hpp
include_directories( third-party/opencv-4.1.0/include )
# Needed by opencv.hpp for opencv2/opencv_modules.hpp
include_directories( third-party/opencv-4.1.0/build_wasm )
# Needed by opencv_modules.hpp for every module
file( GLOB opencv_include_modules "third-party/opencv-4.1.0/modules/*/include" )
include_directories( ${opencv_include_modules} )
# Our hello world executable
add_executable( hello hello.cpp )
# Link to opencv.js precompiled libraries
file( GLOB opencv_js "third-party/opencv-4.1.0/build_wasm/lib/*.a" )
target_link_libraries( hello ${opencv_js} )
I have more details in this stack overflow question if needed: https://stackoverflow.com/questions/55869531/how-to-use-emscripten-with-cmake-for-project-dependencies