1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

cmake: warn when external grfmt library requested but not found

When a user disables a bundled image-codec dependency (e.g.
BUILD_ZLIB=OFF) to supply an external build but find_package()
cannot locate it, OpenCVFindLibsGrfmt.cmake silently falls back to
compiling the bundled 3rdparty version. As reported in the issue,
this is misleading: the editable ZLIB_LIBRARY_DEBUG/RELEASE cache
entries have no effect after the fallback and nothing points the
user at the real knob (ZLIB_ROOT / ZLIB_DIR).

Emit a message(WARNING) in each fallback branch, guarded by
NOT BUILD_<lib>, so the built-in fallback is no longer silent when
the user explicitly opted out of the bundled build. The warning
names the correct search variables for that library and points to
the CMake find_package / Find<lib> documentation. Applied
consistently to the zlib, libjpeg, libtiff, libpng and libwebp
fallback branches.

The existing fallback behavior is intentionally left unchanged, so
configurations that rely on the built-in fallback continue to build.

Fixes #26746
This commit is contained in:
Matt Van Horn
2026-07-18 09:57:20 -07:00
parent 6f402272e7
commit a859f3feff
+27
View File
@@ -45,6 +45,11 @@ else()
endif()
if(NOT ZLIB_FOUND)
if(NOT BUILD_ZLIB)
message(WARNING "ZLIB library has not been found, falling back to built-in version. "
"Set ZLIB_ROOT or ZLIB_DIR variable so that find_package(ZLIB) would be able to find it. "
"See find_package and FindZLIB cmake documentation for details.")
endif()
ocv_clear_vars(ZLIB_LIBRARY ZLIB_LIBRARIES ZLIB_INCLUDE_DIR)
set(ZLIB_LIBRARY zlib CACHE INTERNAL "")
@@ -83,6 +88,12 @@ if(WITH_JPEG)
endif()
if(NOT JPEG_FOUND)
if(NOT BUILD_JPEG)
message(WARNING "JPEG library has not been found, falling back to built-in version. "
"Add the external installation prefix to CMAKE_PREFIX_PATH, or set JPEG_INCLUDE_DIR "
"and JPEG_LIBRARY, so that FindJPEG can locate it. "
"See FindJPEG cmake documentation for details.")
endif()
ocv_clear_vars(JPEG_LIBRARY JPEG_INCLUDE_DIR)
if(NOT BUILD_JPEG_TURBO_DISABLE)
@@ -153,6 +164,12 @@ if(WITH_TIFF)
endif()
if(NOT TIFF_FOUND)
if(NOT BUILD_TIFF)
message(WARNING "TIFF library has not been found, falling back to built-in version. "
"Add the external installation prefix to CMAKE_PREFIX_PATH, or set TIFF_INCLUDE_DIR "
"and TIFF_LIBRARY, so that FindTIFF can locate it. "
"See FindTIFF cmake documentation for details.")
endif()
ocv_clear_vars(TIFF_LIBRARY TIFF_LIBRARIES TIFF_INCLUDE_DIR)
set(TIFF_LIBRARY libtiff CACHE INTERNAL "")
@@ -201,6 +218,11 @@ endif()
if(WITH_WEBP AND NOT WEBP_FOUND
AND (NOT ANDROID OR HAVE_CPUFEATURES)
)
if(NOT BUILD_WEBP)
message(WARNING "WebP library has not been found, falling back to built-in version. "
"Set WEBP_INCLUDE_DIR and WEBP_LIBRARY, or add the external installation prefix to "
"CMAKE_PREFIX_PATH, so that the external WebP can be located.")
endif()
ocv_clear_vars(WEBP_LIBRARY WEBP_INCLUDE_DIR)
set(WEBP_LIBRARY libwebp CACHE INTERNAL "")
set(WEBP_LIBRARIES ${WEBP_LIBRARY})
@@ -353,6 +375,11 @@ if(NOT HAVE_SPNG AND WITH_PNG)
endif()
if(NOT PNG_FOUND)
if(NOT BUILD_PNG)
message(WARNING "PNG library has not been found, falling back to built-in version. "
"Set PNG_ROOT or PNG_DIR variable so that find_package(PNG) would be able to find it. "
"See find_package and FindPNG cmake documentation for details.")
endif()
ocv_clear_vars(PNG_LIBRARY PNG_LIBRARIES PNG_INCLUDE_DIR PNG_DEFINITIONS)
set(PNG_LIBRARY libpng CACHE INTERNAL "")