diff --git a/cmake/helpers/CheckDependentLibraries.cmake b/cmake/helpers/CheckDependentLibraries.cmake index 9568ef043e..94617e3ac9 100644 --- a/cmake/helpers/CheckDependentLibraries.cmake +++ b/cmake/helpers/CheckDependentLibraries.cmake @@ -416,7 +416,7 @@ if (GDAL_USE_JPEG AND (JPEG_LIBRARY MATCHES ".*turbojpeg\.(so|lib)")) "JPEG_LIBRARY should point to a library with libjpeg ABI, not TurboJPEG. See https://libjpeg-turbo.org/About/TurboJPEG for the difference" ) endif () -if (TARGET JPEG::JPEG) +if (GDAL_USE_JPEG AND TARGET JPEG::JPEG) set(EXPECTED_JPEG_LIB_VERSION "" CACHE STRING "Expected libjpeg version number") mark_as_advanced(GDAL_CHECK_PACKAGE_${name}_NAMES) if (EXPECTED_JPEG_LIB_VERSION)