flutter_native_opencv icon indicating copy to clipboard operation
flutter_native_opencv copied to clipboard

Windows CMakeLists.txt can be optimized

Open yanshouwang opened this issue 3 years ago • 0 comments

This project opened my mind a lot, it's very helpful for us to use dart:ffi on all platforms. But after some tests I found the windows' CMakeLists.txt is seems worng when bundle OpenCV library

target_compile_definitions(${PLUGIN_NAME} PRIVATE
  OpenCV_DLL_NAME=
  $<$<CONFIG:Debug>:${OpenCV_DEBUG_DLL_NAME}>
  $<$<CONFIG:Profile>:${OpenCV_RELEASE_DLL_NAME}>
  $<$<CONFIG:Release>:${OpenCV_RELEASE_DLL_NAME}>
)

I am not familiar with CMake syntax but this seems not correct, it's just defined a OpenCV_DLL_NAME= macro and will bundle the whole OpenCV bin folder to the flutter windows build folder with ${_OpenCV_LIB_PATH}/${OpenCV_DLL_NAME}

After some research, I found a better way to bundle the OpenCV dll

get_target_property(OPENCV_DLL_DEBUG opencv_world IMPORTED_LOCATION_DEBUG)
get_target_property(OPENCV_DLL_RELEASE opencv_world IMPORTED_LOCATION_RELEASE)

set(OPENCV_DLL
  $<$<CONFIG:Debug>:${OPENCV_DLL_DEBUG}>
  $<$<CONFIG:Profile>:${OPENCV_DLL_RELEASE}>
  $<$<CONFIG:Release>:${OPENCV_DLL_RELEASE}>
)

# List of absolute paths to libraries that should be bundled with the plugin
set(opencv_bundled_libraries
  ""
  ${OPENCV_DLL}
  PARENT_SCOPE
)

We can use this to avoid define OpenCV dll name in the CMakeLists.txt

yanshouwang avatar Apr 16 '22 07:04 yanshouwang