diff --git a/cmake/OpenCVFindLibsGrfmt.cmake b/cmake/OpenCVFindLibsGrfmt.cmake index 4ad44fe833..f99bb33c80 100644 --- a/cmake/OpenCVFindLibsGrfmt.cmake +++ b/cmake/OpenCVFindLibsGrfmt.cmake @@ -6,6 +6,7 @@ if(BUILD_ZLIB) ocv_clear_vars(ZLIB_FOUND) else() + ocv_clear_internal_cache_vars(ZLIB_LIBRARY ZLIB_INCLUDE_DIR) find_package(ZLIB "${MIN_VER_ZLIB}") if(ZLIB_FOUND AND ANDROID) if(ZLIB_LIBRARIES MATCHES "/usr/(lib|lib32|lib64)/libz.so$") @@ -31,11 +32,12 @@ if(WITH_JPEG) if(BUILD_JPEG) ocv_clear_vars(JPEG_FOUND) else() + ocv_clear_internal_cache_vars(JPEG_LIBRARY JPEG_INCLUDE_DIR) include(FindJPEG) endif() if(NOT JPEG_FOUND) - ocv_clear_vars(JPEG_LIBRARY JPEG_LIBRARIES JPEG_INCLUDE_DIR) + ocv_clear_vars(JPEG_LIBRARY JPEG_INCLUDE_DIR) if(NOT BUILD_JPEG_TURBO_DISABLE) set(JPEG_LIBRARY libjpeg-turbo CACHE INTERNAL "") @@ -76,6 +78,7 @@ if(WITH_TIFF) if(BUILD_TIFF) ocv_clear_vars(TIFF_FOUND) else() + ocv_clear_internal_cache_vars(TIFF_LIBRARY TIFF_INCLUDE_DIR) include(FindTIFF) if(TIFF_FOUND) ocv_parse_header("${TIFF_INCLUDE_DIR}/tiff.h" TIFF_VERSION_LINES TIFF_VERSION_CLASSIC TIFF_VERSION_BIG TIFF_VERSION TIFF_BIGTIFF_VERSION) @@ -119,6 +122,7 @@ if(WITH_WEBP) if(BUILD_WEBP) ocv_clear_vars(WEBP_FOUND WEBP_LIBRARY WEBP_LIBRARIES WEBP_INCLUDE_DIR) else() + ocv_clear_internal_cache_vars(WEBP_LIBRARY WEBP_INCLUDE_DIR) include(cmake/OpenCVFindWebP.cmake) if(WEBP_FOUND) set(HAVE_WEBP 1) @@ -184,6 +188,7 @@ if(WITH_PNG) if(BUILD_PNG) ocv_clear_vars(PNG_FOUND) else() + ocv_clear_internal_cache_vars(PNG_LIBRARY PNG_INCLUDE_DIR) include(FindPNG) if(PNG_FOUND) include(CheckIncludeFile) @@ -215,6 +220,7 @@ endif() if(WITH_OPENEXR) ocv_clear_vars(HAVE_OPENEXR) if(NOT BUILD_OPENEXR) + ocv_clear_internal_cache_vars(OPENEXR_INCLUDE_PATHS OPENEXR_LIBRARIES OPENEXR_ILMIMF_LIBRARY OPENEXR_VERSION) include("${OpenCV_SOURCE_DIR}/cmake/OpenCVFindOpenEXR.cmake") endif() diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 693a840ffe..6ae2cbcf8b 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -400,6 +400,24 @@ macro(ocv_clear_vars) endforeach() endmacro() + +# Clears passed variables with INTERNAL type from CMake cache +macro(ocv_clear_internal_cache_vars) + foreach(_var ${ARGN}) + get_property(_propertySet CACHE ${_var} PROPERTY TYPE SET) + if(_propertySet) + get_property(_type CACHE ${_var} PROPERTY TYPE) + if(_type STREQUAL "INTERNAL") + message("Cleaning INTERNAL cached variable: ${_var}") + unset(${_var} CACHE) + endif() + endif() + endforeach() + unset(_propertySet) + unset(_type) +endmacro() + + set(OCV_COMPILER_FAIL_REGEX "argument .* is not valid" # GCC 9+ (including support of unicode quotes) "command[- ]line option .* is valid for .* but not for C\\+\\+" # GNU