Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openexr 3.x: conan v2 support #12457

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/openexr/3.x/CMakeLists.txt

This file was deleted.

2 changes: 0 additions & 2 deletions recipes/openexr/3.x/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ sources:
patches:
"3.1.5":
- patch_file: "patches/v3.1.4-gcc5-bug-workaround.patch"
base_path: "source_subfolder"
"3.1.4":
- patch_file: "patches/v3.1.4-gcc5-bug-workaround.patch"
base_path: "source_subfolder"
85 changes: 42 additions & 43 deletions recipes/openexr/3.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from conans import ConanFile, CMake, tools
import os, functools
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, get, rmdir
from conan.tools.scm import Version
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.50.2 <1.51.0 || >=1.51.2"


class OpenEXRConan(ConanFile):
Expand All @@ -23,20 +27,9 @@ class OpenEXRConan(ConanFile):
"fPIC": True,
}

generators = "cmake", "cmake_find_package"

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
for p in self.conan_data.get("patches", {}).get(self.version, []):
copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder)

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -53,34 +46,38 @@ def requirements(self):
self.requires("imath/3.1.5")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
if self.info.settings.compiler.cppstd:
check_min_cppstd(self, 11)

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
def layout(self):
cmake_layout(self, src_folder="src")

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["OPENEXR_INSTALL_EXAMPLES"] = False
cmake.definitions["DOCS"] = False
cmake.configure(build_folder=self._build_subfolder)
return cmake
def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["OPENEXR_INSTALL_EXAMPLES"] = False
tc.variables["BUILD_TESTING"] = False
tc.variables["DOCS"] = False
tc.generate()
cd = CMakeDeps(self)
cd.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE.md", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
copy(self, "LICENSE.md", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "share"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

@staticmethod
def _conan_comp(name):
Expand All @@ -101,8 +98,10 @@ def package_info(self):
self.cpp_info.names["cmake_find_package_multi"] = "OpenEXR"
self.cpp_info.names["pkg_config"] = "OpenEXR"

openexr_version = tools.Version(self.version)
lib_suffix = "-{}_{}".format(openexr_version.major, openexr_version.minor)
lib_suffix = ""
if not self.options.shared or self.settings.os == "Windows":
openexr_version = Version(self.version)
lib_suffix += f"-{openexr_version.major}_{openexr_version.minor}"
if self.settings.build_type == "Debug":
lib_suffix += "_d"

Expand All @@ -120,12 +119,12 @@ def package_info(self):

# OpenEXR::Iex
Iex = self._add_component("Iex")
Iex.libs = ["Iex{}".format(lib_suffix)]
Iex.libs = [f"Iex{lib_suffix}"]
Iex.requires = [self._conan_comp("IexConfig")]

# OpenEXR::IlmThread
IlmThread = self._add_component("IlmThread")
IlmThread.libs = ["IlmThread{}".format(lib_suffix)]
IlmThread.libs = [f"IlmThread{lib_suffix}"]
IlmThread.requires = [
self._conan_comp("IlmThreadConfig"), self._conan_comp("Iex"),
]
Expand All @@ -134,20 +133,20 @@ def package_info(self):

# OpenEXR::OpenEXRCore
OpenEXRCore = self._add_component("OpenEXRCore")
OpenEXRCore.libs = ["OpenEXRCore{}".format(lib_suffix)]
OpenEXRCore.libs = [f"OpenEXRCore{lib_suffix}"]
OpenEXRCore.requires = [self._conan_comp("OpenEXRConfig"), "zlib::zlib"]

# OpenEXR::OpenEXR
OpenEXR = self._add_component("OpenEXR")
OpenEXR.libs = ["OpenEXR{}".format(lib_suffix)]
OpenEXR.libs = [f"OpenEXR{lib_suffix}"]
OpenEXR.requires = [
self._conan_comp("OpenEXRCore"), self._conan_comp("IlmThread"),
self._conan_comp("Iex"), "imath::imath",
]

# OpenEXR::OpenEXRUtil
OpenEXRUtil = self._add_component("OpenEXRUtil")
OpenEXRUtil.libs = ["OpenEXRUtil{}".format(lib_suffix)]
OpenEXRUtil.libs = [f"OpenEXRUtil{lib_suffix}"]
OpenEXRUtil.requires = [self._conan_comp("OpenEXR")]

# Add tools directory to PATH
Expand Down
11 changes: 4 additions & 7 deletions recipes/openexr/3.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(OpenEXR REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} OpenEXR::OpenEXR)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenEXR::OpenEXR)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
18 changes: 13 additions & 5 deletions recipes/openexr/3.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
imgfile = os.path.join(self.source_folder, "comp_short_decode_piz.exr")
self.run("{} {}".format(bin_path, imgfile), run_environment=True)
self.run(f"{bin_path} {imgfile}", env="conanrun")
11 changes: 11 additions & 0 deletions recipes/openexr/3.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(OpenEXR REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenEXR::OpenEXR)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
18 changes: 18 additions & 0 deletions recipes/openexr/3.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
imgfile = os.path.join(self.source_folder, os.pardir, "test_package", "comp_short_decode_piz.exr")
self.run(f"{bin_path} {imgfile}", run_environment=True)