From a0e48b4f7afb9a03bf63f1191a0b34dff60e0cce Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Sat, 14 May 2022 10:24:29 +0200 Subject: [PATCH] (#10765) openvdb: fix CMake imported target + modernize * 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 --- recipes/openvdb/8.0.1/conandata.yml | 8 - .../openvdb/8.0.1/test_package/CMakeLists.txt | 16 -- recipes/openvdb/{8.0.1 => all}/CMakeLists.txt | 2 +- recipes/openvdb/all/conandata.yml | 8 + recipes/openvdb/{8.0.1 => all}/conanfile.py | 181 ++++++++++-------- .../patches/0001-Find-packages-fixes.patch | 0 .../openvdb/all/test_package/CMakeLists.txt | 11 ++ .../{8.0.1 => all}/test_package/conanfile.py | 8 +- .../test_package/test_package.cpp | 0 recipes/openvdb/config.yml | 2 +- 10 files changed, 122 insertions(+), 114 deletions(-) delete mode 100644 recipes/openvdb/8.0.1/conandata.yml delete mode 100644 recipes/openvdb/8.0.1/test_package/CMakeLists.txt rename recipes/openvdb/{8.0.1 => all}/CMakeLists.txt (80%) create mode 100644 recipes/openvdb/all/conandata.yml rename recipes/openvdb/{8.0.1 => all}/conanfile.py (61%) rename recipes/openvdb/{8.0.1 => all}/patches/0001-Find-packages-fixes.patch (100%) create mode 100644 recipes/openvdb/all/test_package/CMakeLists.txt rename recipes/openvdb/{8.0.1 => all}/test_package/conanfile.py (66%) rename recipes/openvdb/{8.0.1 => all}/test_package/test_package.cpp (100%) diff --git a/recipes/openvdb/8.0.1/conandata.yml b/recipes/openvdb/8.0.1/conandata.yml deleted file mode 100644 index 6e81a34a28cfb..0000000000000 --- a/recipes/openvdb/8.0.1/conandata.yml +++ /dev/null @@ -1,8 +0,0 @@ -sources: - "8.0.1": - url: https://github.com/AcademySoftwareFoundation/openvdb/archive/refs/tags/v8.0.1.tar.gz - sha256: a6845da7c604d2c72e4141c898930ac8a2375521e535f696c2cd92bebbe43c4f -patches: - "8.0.1": - - base_path: "source_subfolder" - patch_file: "patches/0001-Find-packages-fixes.patch" diff --git a/recipes/openvdb/8.0.1/test_package/CMakeLists.txt b/recipes/openvdb/8.0.1/test_package/CMakeLists.txt deleted file mode 100644 index cb24de6bc913a..0000000000000 --- a/recipes/openvdb/8.0.1/test_package/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -project(test_package CXX) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() - -find_package(OpenVDB REQUIRED CONFIG) - -add_executable(${PROJECT_NAME} test_package.cpp) -set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) - -if(TARGET OpenVDB::openvdb_static) - target_link_libraries(${PROJECT_NAME} PRIVATE OpenVDB::openvdb_static) -else() - target_link_libraries(${PROJECT_NAME} PRIVATE OpenVDB::openvdb_shared) -endif() diff --git a/recipes/openvdb/8.0.1/CMakeLists.txt b/recipes/openvdb/all/CMakeLists.txt similarity index 80% rename from recipes/openvdb/8.0.1/CMakeLists.txt rename to recipes/openvdb/all/CMakeLists.txt index bd3083b512cb9..b71c882d9d33f 100644 --- a/recipes/openvdb/8.0.1/CMakeLists.txt +++ b/recipes/openvdb/all/CMakeLists.txt @@ -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) diff --git a/recipes/openvdb/all/conandata.yml b/recipes/openvdb/all/conandata.yml new file mode 100644 index 0000000000000..902318df1e3ae --- /dev/null +++ b/recipes/openvdb/all/conandata.yml @@ -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" diff --git a/recipes/openvdb/8.0.1/conanfile.py b/recipes/openvdb/all/conanfile.py similarity index 61% rename from recipes/openvdb/8.0.1/conanfile.py rename to recipes/openvdb/all/conanfile.py index 6b5912aba3097..f36eb55cee0f2 100644 --- a/recipes/openvdb/8.0.1/conanfile.py +++ b/recipes/openvdb/all/conanfile.py @@ -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): @@ -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], @@ -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): @@ -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: @@ -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" @@ -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": @@ -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") diff --git a/recipes/openvdb/8.0.1/patches/0001-Find-packages-fixes.patch b/recipes/openvdb/all/patches/0001-Find-packages-fixes.patch similarity index 100% rename from recipes/openvdb/8.0.1/patches/0001-Find-packages-fixes.patch rename to recipes/openvdb/all/patches/0001-Find-packages-fixes.patch diff --git a/recipes/openvdb/all/test_package/CMakeLists.txt b/recipes/openvdb/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..1016f9a6ff31e --- /dev/null +++ b/recipes/openvdb/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/openvdb/8.0.1/test_package/conanfile.py b/recipes/openvdb/all/test_package/conanfile.py similarity index 66% rename from recipes/openvdb/8.0.1/test_package/conanfile.py rename to recipes/openvdb/all/test_package/conanfile.py index abcaeed3f89b6..19e6a0c06e3d8 100644 --- a/recipes/openvdb/8.0.1/test_package/conanfile.py +++ b/recipes/openvdb/all/test_package/conanfile.py @@ -1,10 +1,10 @@ -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) @@ -12,6 +12,6 @@ def build(self): 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) diff --git a/recipes/openvdb/8.0.1/test_package/test_package.cpp b/recipes/openvdb/all/test_package/test_package.cpp similarity index 100% rename from recipes/openvdb/8.0.1/test_package/test_package.cpp rename to recipes/openvdb/all/test_package/test_package.cpp diff --git a/recipes/openvdb/config.yml b/recipes/openvdb/config.yml index 740980ba8f133..d603f0308422b 100644 --- a/recipes/openvdb/config.yml +++ b/recipes/openvdb/config.yml @@ -1,3 +1,3 @@ versions: "8.0.1": - folder: "8.0.1" + folder: all