Skip to content

Commit

Permalink
robust discovery & link to openexr in opencv 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm committed Dec 19, 2022
1 parent 764cc04 commit ff32135
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
11 changes: 11 additions & 0 deletions recipes/opencv/3.x/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ sources:
sha256: "c8919dfb5ead6be67534bf794cb0925534311f1cd5c6680f8164ad1813c88d13"
- url: "https://github.com/opencv/opencv_contrib/archive/3.4.12.tar.gz"
sha256: "b207024589674dd2efc7c25740ef192ee4f3e0783e773e2d49a198c37e3e7570"
patches:
"3.4.17":
- patch_file: "patches/3.4.17-0001-find-openexr.patch"
patch_description: "Robust discovery & injection of OpenEXR"
patch_type: "conan"
base_path: "src"
"3.4.12":
- patch_file: "patches/3.4.12-0001-find-openexr.patch"
patch_description: "Robust discovery & injection of OpenEXR"
patch_type: "conan"
base_path: "src"
10 changes: 6 additions & 4 deletions recipes/opencv/3.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import copy, get, rename, replace_in_file, rmdir, save
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rename, replace_in_file, rmdir, save
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version
from conans import CMake
Expand Down Expand Up @@ -51,7 +51,6 @@ class OpenCVConan(ConanFile):
}

short_paths = True
exports_sources = "CMakeLists.txt"
generators = "cmake", "cmake_find_package"
_cmake = None

Expand All @@ -67,6 +66,10 @@ def _contrib_folder(self):
def _build_folder(self):
return os.path.join(self.source_folder, "build")

def export_sources(self):
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand Down Expand Up @@ -126,6 +129,7 @@ def source(self):
destination=self._contrib_folder, strip_root=True)

def _patch_sources(self):
apply_conandata_patches(self)
rmdir(self, os.path.join(self._source_folder, "3rdparty"))
if self.options.contrib:
freetype_cmake = os.path.join(self._contrib_folder, "modules", "freetype", "CMakeLists.txt")
Expand Down Expand Up @@ -277,8 +281,6 @@ def _configure_cmake(self):

if is_msvc(self):
self._cmake.definitions["BUILD_WITH_STATIC_CRT"] = is_msvc_static_runtime(self)
if self.options.with_openexr:
self._cmake.definitions["OPENEXR_ROOT"] = self.dependencies["openexr"].package_folder.replace("\\", "/")
self._cmake.definitions["ENABLE_PIC"] = self.options.get_safe("fPIC", True)
self._cmake.definitions["ENABLE_CCACHE"] = False

Expand Down
18 changes: 18 additions & 0 deletions recipes/opencv/3.x/patches/3.4.12-0001-find-openexr.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- a/cmake/OpenCVFindOpenEXR.cmake
+++ b/cmake/OpenCVFindOpenEXR.cmake
@@ -8,6 +8,15 @@
# OPENEXR_INCLUDE_PATHS = OpenEXR include directories.
# OPENEXR_LIBRARIES = libraries that are needed to use OpenEXR.
#
+find_package(OpenEXR REQUIRED)
+if(TARGET OpenEXR::OpenEXR)
+ set(OPENEXR_LIBRARIES OpenEXR::OpenEXR)
+else()
+ set(OPENEXR_LIBRARIES openexr::openexr)
+endif()
+set(OPENEXR_FOUND TRUE)
+set(OPENEXR_VERSION ${OpenEXR_VERSION})
+return()

SET(OPENEXR_LIBRARIES "")
SET(OPENEXR_LIBSEARCH_SUFFIXES "")
18 changes: 18 additions & 0 deletions recipes/opencv/3.x/patches/3.4.17-0001-find-openexr.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- a/cmake/OpenCVFindOpenEXR.cmake
+++ b/cmake/OpenCVFindOpenEXR.cmake
@@ -8,6 +8,15 @@
# OPENEXR_INCLUDE_PATHS = OpenEXR include directories.
# OPENEXR_LIBRARIES = libraries that are needed to use OpenEXR.
#
+find_package(OpenEXR REQUIRED)
+if(TARGET OpenEXR::OpenEXR)
+ set(OPENEXR_LIBRARIES OpenEXR::OpenEXR)
+else()
+ set(OPENEXR_LIBRARIES openexr::openexr)
+endif()
+set(OPENEXR_FOUND TRUE)
+set(OPENEXR_VERSION ${OpenEXR_VERSION})
+return()

if(NOT HAVE_CXX11)
message(STATUS "OpenEXR: enable C++11 to use external OpenEXR")

0 comments on commit ff32135

Please sign in to comment.