Establish a consistent pattern for feature flags and dependency management in configuration files: 1. Use `WITH_*` or `OPENCV_ENABLE_*` variables to represent user intentions (features to enable if available)
Establish a consistent pattern for feature flags and dependency management in configuration files:
WITH_*
or OPENCV_ENABLE_*
variables to represent user intentions (features to enable if available)find_package()
and preferably try_compile()
to validate dependenciesHAVE_*
variables based on actual availability check resultsHAVE_*
checksExample:
# User intention
ocv_option(OPENCV_ENABLE_EGL_INTEROP "Build with EGL interoperability support" ON)
# Actual detection (in main CMakeLists.txt)
if(OPENCV_ENABLE_EGL_INTEROP)
find_package(EGL)
if(EGL_FOUND)
set(HAVE_EGL_INTEROP ON)
endif()
endif()
# Usage in module CMakeLists.txt
if(HAVE_EGL_INTEROP)
# Prefer target-based dependencies
target_link_libraries(${the_module} PUBLIC ocv.3rdparty.egl)
# Make definitions PUBLIC if used in headers
target_compile_definitions(${the_module} PUBLIC HAVE_EGL_INTEROP)
endif()
This convention ensures all dependencies are properly detected during configuration stage, not build stage, preventing build failures due to missing dependencies. It clearly separates user intent from actual availability and promotes modern CMake practices.
Enter the URL of a public GitHub repository