Skip to content

Commit

Permalink
(#10765) openvdb: fix CMake imported target + modernize
Browse files Browse the repository at this point in the history
* modernize

- relocatable shared lib on macOS
- cache CMake configuration with functools.lru_cache
- fix min msvc version when compiler=msvc in profile
- move checks to validate
- fix CMake imported target, it's always OpenVDB::openvdb in upstream FindOpenVDB.cmake file (there is no config file upstream)
- CMakeDeps support

* bump dependencies

also require onetbb instead of deprecated tbb recipe

* move to all folder
  • Loading branch information
SpaceIm authored May 14, 2022
1 parent 66f9091 commit a0e48b4
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 114 deletions.
8 changes: 0 additions & 8 deletions recipes/openvdb/8.0.1/conandata.yml

This file was deleted.

16 changes: 0 additions & 16 deletions recipes/openvdb/8.0.1/test_package/CMakeLists.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(KEEP_RPATHS)

add_subdirectory(source_subfolder)
8 changes: 8 additions & 0 deletions recipes/openvdb/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
"8.0.1":
url: "https://github.com/AcademySoftwareFoundation/openvdb/archive/refs/tags/v8.0.1.tar.gz"
sha256: "a6845da7c604d2c72e4141c898930ac8a2375521e535f696c2cd92bebbe43c4f"
patches:
"8.0.1":
- patch_file: "patches/0001-Find-packages-fixes.patch"
base_path: "source_subfolder"
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os

from conan.tools.microsoft import is_msvc
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import functools
import os

required_conan_version = ">=1.33.0"

required_conan_version = ">=1.45.0"


class OpenVDBConan(ConanFile):
Expand All @@ -17,8 +19,7 @@ class OpenVDBConan(ConanFile):
topics = ("voxel", "voxelizer", "volume-rendering", "fx")
homepage = "https://github.com/AcademySoftwareFoundation/openvdb"
url = "https://github.com/conan-io/conan-center-index"
exports_sources = ["CMakeLists.txt", "patches/*.patch"]
generators = "cmake", "cmake_find_package"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -39,16 +40,7 @@ class OpenVDBConan(ConanFile):
"simd": None,
}

_cmake = None

_compilers_min_version = {
"msvc": "19.10",
"Visual Studio": "15", # Should we check toolset?
"gcc": "6.3.1",
"clang": "3.8",
"apple-clang": "3.8",
"intel": "17",
}
generators = "cmake", "cmake_find_package"

@property
def _source_subfolder(self):
Expand All @@ -58,44 +50,65 @@ def _source_subfolder(self):
def _build_subfolder(self):
return "build_subfolder"

@property
def _compilers_min_version(self):
return {
"msvc": "191",
"Visual Studio": "15", # Should we check toolset?
"gcc": "6.3.1",
"clang": "3.8",
"apple-clang": "3.8",
"intel": "17",
}

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

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def _check_compilier_version(self):
compiler = str(self.settings.compiler)
version = tools.Version(self.settings.compiler.version)
if version < self._compilers_min_version[compiler]:
raise ConanInvalidConfiguration("%s requires a %s version greater than %s" % (self.name, compiler, self._compilers_min_version[compiler]))

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 14)
if self.settings.arch not in ("x86", "x86_64"):
if self.options.simd:
raise ConanInvalidConfiguration("Only intel architectures support SSE4 or AVX.")
self._check_compilier_version()

def requirements(self):
self.requires("boost/1.75.0")
self.requires("tbb/2020.3")
self.requires("openexr/2.5.5") # required for IlmBase::Half
self.requires("boost/1.79.0")
self.requires("onetbb/2020.3")
self.requires("openexr/2.5.7") # required for IlmBase::Half
if self.options.with_zlib:
self.requires("zlib/1.2.11")
self.requires("zlib/1.2.12")
if self.options.with_exr:
# Not necessary now. Required for IlmBase::IlmImf
self.requires("openexr/2.5.5")
self.requires("openexr/2.5.7")
if self.options.with_blosc:
self.requires("c-blosc/1.20.1")
self.requires("c-blosc/1.21.1")
if self.options.with_log4cplus:
self.requires("log4cplus/2.0.5")
self.requires("log4cplus/2.0.7")

def _check_compilier_version(self):
compiler = str(self.settings.compiler)
version = tools.Version(self.settings.compiler.version)
minimum_version = self._compilers_min_version.get(compiler, False)
if minimum_version and version < minimum_version:
raise ConanInvalidConfiguration(f"{self.name} requires a {compiler} version greater than {minimum_version}")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 14)
if self.settings.arch not in ("x86", "x86_64"):
if self.options.simd:
raise ConanInvalidConfiguration("Only intel architectures support SSE4 or AVX.")
self._check_compilier_version()

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

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
# Remove FindXXX files from OpenVDB. Let Conan do the job
tools.remove_files_by_mask(os.path.join(self._source_subfolder, "cmake"), "Find*")
with open("FindBlosc.cmake", "w") as f:
Expand Down Expand Up @@ -130,74 +143,67 @@ def _patch_sources(self):
endif()
"""
)
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()

@functools.lru_cache(1)
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
cmake = CMake(self)
# exposed options
self._cmake.definitions["USE_BLOSC"] = self.options.with_blosc
self._cmake.definitions["USE_ZLIB"] = self.options.with_zlib
self._cmake.definitions["USE_LOG4CPLUS"] = self.options.with_log4cplus
self._cmake.definitions["USE_EXR"] = self.options.with_exr
self._cmake.definitions["OPENVDB_SIMD"] = self.options.simd
cmake.definitions["USE_BLOSC"] = self.options.with_blosc
cmake.definitions["USE_ZLIB"] = self.options.with_zlib
cmake.definitions["USE_LOG4CPLUS"] = self.options.with_log4cplus
cmake.definitions["USE_EXR"] = self.options.with_exr
cmake.definitions["OPENVDB_SIMD"] = self.options.simd

self._cmake.definitions["OPENVDB_CORE_SHARED"] = self.options.shared
self._cmake.definitions["OPENVDB_CORE_STATIC"] = not self.options.shared
cmake.definitions["OPENVDB_CORE_SHARED"] = self.options.shared
cmake.definitions["OPENVDB_CORE_STATIC"] = not self.options.shared

# All available options but not exposed yet. Set to default values
self._cmake.definitions["OPENVDB_BUILD_CORE"] = True
self._cmake.definitions["OPENVDB_BUILD_BINARIES"] = False
self._cmake.definitions["OPENVDB_BUILD_PYTHON_MODULE"] = False
self._cmake.definitions["OPENVDB_BUILD_UNITTESTS"] = False
self._cmake.definitions["OPENVDB_BUILD_DOCS"] = False
self._cmake.definitions["OPENVDB_BUILD_HOUDINI_PLUGIN"] = False
self._cmake.definitions["OPENVDB_BUILD_HOUDINI_ABITESTS"] = False

self._cmake.definitions["OPENVDB_BUILD_AX"] = False
self._cmake.definitions["OPENVDB_BUILD_AX_BINARIES"] = False
self._cmake.definitions["OPENVDB_BUILD_AX_UNITTESTS"] = False

self._cmake.definitions["OPENVDB_BUILD_MAYA_PLUGIN"] = False
self._cmake.definitions["OPENVDB_ENABLE_RPATH"] = False
self._cmake.definitions["OPENVDB_CXX_STRICT"] = False
self._cmake.definitions["USE_HOUDINI"] = False
self._cmake.definitions["USE_MAYA"] = False
self._cmake.definitions["USE_STATIC_DEPENDENCIES"] = False
self._cmake.definitions["USE_PKGCONFIG"] = False
self._cmake.definitions["OPENVDB_INSTALL_CMAKE_MODULES"] = False

self._cmake.definitions["Boost_USE_STATIC_LIBS"] = not self.options["boost"].shared
self._cmake.definitions["OPENEXR_USE_STATIC_LIBS"] = not self.options["openexr"].shared

self._cmake.definitions["OPENVDB_DISABLE_BOOST_IMPLICIT_LINKING"] = True

self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
cmake.definitions["OPENVDB_BUILD_CORE"] = True
cmake.definitions["OPENVDB_BUILD_BINARIES"] = False
cmake.definitions["OPENVDB_BUILD_PYTHON_MODULE"] = False
cmake.definitions["OPENVDB_BUILD_UNITTESTS"] = False
cmake.definitions["OPENVDB_BUILD_DOCS"] = False
cmake.definitions["OPENVDB_BUILD_HOUDINI_PLUGIN"] = False
cmake.definitions["OPENVDB_BUILD_HOUDINI_ABITESTS"] = False

cmake.definitions["OPENVDB_BUILD_AX"] = False
cmake.definitions["OPENVDB_BUILD_AX_BINARIES"] = False
cmake.definitions["OPENVDB_BUILD_AX_UNITTESTS"] = False

cmake.definitions["OPENVDB_BUILD_MAYA_PLUGIN"] = False
cmake.definitions["OPENVDB_ENABLE_RPATH"] = False
cmake.definitions["OPENVDB_CXX_STRICT"] = False
cmake.definitions["USE_HOUDINI"] = False
cmake.definitions["USE_MAYA"] = False
cmake.definitions["USE_STATIC_DEPENDENCIES"] = False
cmake.definitions["USE_PKGCONFIG"] = False
cmake.definitions["OPENVDB_INSTALL_CMAKE_MODULES"] = False

cmake.definitions["Boost_USE_STATIC_LIBS"] = not self.options["boost"].shared
cmake.definitions["OPENEXR_USE_STATIC_LIBS"] = not self.options["openexr"].shared

cmake.definitions["OPENVDB_DISABLE_BOOST_IMPLICIT_LINKING"] = True

cmake.configure(build_folder=self._build_subfolder)
return cmake

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()

tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "OpenVDB"
self.cpp_info.names["cmake_find_package_multi"] = "OpenVDB"

target_suffix = "_shared" if self.options.shared else "_static"
lib_prefix = "" if self.options.shared or self.settings.os != "Windows" else "lib"
self.cpp_info.components["openvdb-core"].names["cmake_find_package"] = "openvdb" + target_suffix
self.cpp_info.components["openvdb-core"].names["cmake_find_package_multi"] = "openvdb" + target_suffix
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "OpenVDB")
self.cpp_info.set_property("cmake_target_name", "OpenVDB::openvdb")

# TODO: back to global scope in conan v2 once cmake_find_package_* generators removed
lib_prefix = "lib" if is_msvc(self) and not self.options.shared else ""
self.cpp_info.components["openvdb-core"].libs = [lib_prefix + "openvdb"]

lib_define = "OPENVDB_DLL" if self.options.shared else "OPENVDB_STATICLIB"
Expand All @@ -217,7 +223,7 @@ def package_info(self):
self.cpp_info.components["openvdb-core"].requires = [
"boost::iostreams",
"boost::system",
"tbb::tbb",
"onetbb::onetbb",
"openexr::openexr", # should be "openexr::Half",
]
if self.settings.os == "Windows":
Expand All @@ -232,3 +238,10 @@ def package_info(self):

if self.settings.os in ("Linux", "FreeBSD"):
self.cpp_info.components["openvdb-core"].system_libs = ["pthread"]

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "OpenVDB"
self.cpp_info.names["cmake_find_package_multi"] = "OpenVDB"
self.cpp_info.components["openvdb-core"].names["cmake_find_package"] = "openvdb"
self.cpp_info.components["openvdb-core"].names["cmake_find_package_multi"] = "openvdb"
self.cpp_info.components["openvdb-core"].set_property("cmake_target_name", "OpenVDB::openvdb")
11 changes: 11 additions & 0 deletions recipes/openvdb/all/test_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 CXX)

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

find_package(OpenVDB REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenVDB::openvdb)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import os
from conans import ConanFile, CMake, tools
import os


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

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

def test(self):
if not tools.cross_building(self.settings):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
2 changes: 1 addition & 1 deletion recipes/openvdb/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
versions:
"8.0.1":
folder: "8.0.1"
folder: all

0 comments on commit a0e48b4

Please sign in to comment.