From f43fec7ee674d9fc65be21119066c3e67c856357 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 23 Dec 2021 10:39:43 +0000 Subject: [PATCH] cmake: use find_package(OpenEXR) to support OpenEXR 3+ --- CMakeLists.txt | 4 ++-- cmake/OpenCVFindLibsGrfmt.cmake | 1 + cmake/OpenCVFindOpenEXR.cmake | 21 +++++++++++++++++++++ modules/imgcodecs/src/grfmt_exr.hpp | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 169c385fad..ba2d477501 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -224,7 +224,7 @@ OCV_OPTION(BUILD_TIFF "Build libtiff from source" (WIN32 OCV_OPTION(BUILD_JASPER "Build libjasper from source" (WIN32 OR ANDROID OR APPLE OR OPENCV_FORCE_3RDPARTY_BUILD) ) OCV_OPTION(BUILD_JPEG "Build libjpeg from source" (WIN32 OR ANDROID OR APPLE OR OPENCV_FORCE_3RDPARTY_BUILD) ) OCV_OPTION(BUILD_PNG "Build libpng from source" (WIN32 OR ANDROID OR APPLE OR OPENCV_FORCE_3RDPARTY_BUILD) ) -OCV_OPTION(BUILD_OPENEXR "Build openexr from source" (((WIN32 OR ANDROID OR APPLE) AND NOT WINRT) OR OPENCV_FORCE_3RDPARTY_BUILD) ) +OCV_OPTION(BUILD_OPENEXR "Build openexr from source" (OPENCV_FORCE_3RDPARTY_BUILD) ) OCV_OPTION(BUILD_WEBP "Build WebP from source" (((WIN32 OR ANDROID OR APPLE) AND NOT WINRT) OR OPENCV_FORCE_3RDPARTY_BUILD) ) OCV_OPTION(BUILD_TBB "Download and build TBB from source" (ANDROID OR OPENCV_FORCE_3RDPARTY_BUILD) ) OCV_OPTION(BUILD_IPP_IW "Build IPP IW from source" (NOT MINGW OR OPENCV_FORCE_3RDPARTY_BUILD) IF (X86_64 OR X86) AND NOT WINRT ) @@ -306,7 +306,7 @@ OCV_OPTION(WITH_JPEG "Include JPEG support" ON OCV_OPTION(WITH_WEBP "Include WebP support" ON VISIBLE_IF NOT WINRT VERIFY HAVE_WEBP) -OCV_OPTION(WITH_OPENEXR "Include ILM support via OpenEXR" BUILD_OPENEXR OR NOT CMAKE_CROSSCOMPILING +OCV_OPTION(WITH_OPENEXR "Include ILM support via OpenEXR" ((WIN32 OR ANDROID OR APPLE) OR BUILD_OPENEXR) OR NOT CMAKE_CROSSCOMPILING VISIBLE_IF NOT APPLE_FRAMEWORK AND NOT WINRT VERIFY HAVE_OPENEXR) OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF diff --git a/cmake/OpenCVFindLibsGrfmt.cmake b/cmake/OpenCVFindLibsGrfmt.cmake index 2d28dff875..a31de898c5 100644 --- a/cmake/OpenCVFindLibsGrfmt.cmake +++ b/cmake/OpenCVFindLibsGrfmt.cmake @@ -241,6 +241,7 @@ if(WITH_OPENEXR) add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/openexr") if(OPENEXR_VERSION) # check via TARGET doesn't work set(HAVE_OPENEXR YES) + set(BUILD_OPENEXR ON) endif() endif() endif() diff --git a/cmake/OpenCVFindOpenEXR.cmake b/cmake/OpenCVFindOpenEXR.cmake index ef633e853a..94b3f9f098 100644 --- a/cmake/OpenCVFindOpenEXR.cmake +++ b/cmake/OpenCVFindOpenEXR.cmake @@ -9,6 +9,27 @@ # OPENEXR_LIBRARIES = libraries that are needed to use OpenEXR. # +if(NOT HAVE_CXX11) + message(STATUS "OpenEXR: enable C++11 to use external OpenEXR") + return() +endif() + +if(NOT OPENCV_SKIP_OPENEXR_FIND_PACKAGE) + find_package(OpenEXR 3 QUIET) + #ocv_cmake_dump_vars(EXR) + if(OpenEXR_FOUND) + if(TARGET OpenEXR::OpenEXR) # OpenEXR 3+ + set(OPENEXR_LIBRARIES OpenEXR::OpenEXR) + set(OPENEXR_INCLUDE_PATHS "") + set(OPENEXR_VERSION "${OpenEXR_VERSION}") + set(OPENEXR_FOUND 1) + return() + else() + message(STATUS "Unsupported find_package(OpenEXR) - missing OpenEXR::OpenEXR target (version ${OpenEXR_VERSION})") + endif() + endif() +endif() + SET(OPENEXR_LIBRARIES "") SET(OPENEXR_LIBSEARCH_SUFFIXES "") file(TO_CMAKE_PATH "$ENV{ProgramFiles}" ProgramFiles_ENV_PATH) diff --git a/modules/imgcodecs/src/grfmt_exr.hpp b/modules/imgcodecs/src/grfmt_exr.hpp index 99acd775c2..a86874d228 100644 --- a/modules/imgcodecs/src/grfmt_exr.hpp +++ b/modules/imgcodecs/src/grfmt_exr.hpp @@ -53,6 +53,7 @@ #include #include #include +#include #include "grfmt_base.hpp" namespace cv