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

opensubdiv: Add recipe #11450

Merged
merged 16 commits into from
Aug 12, 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: 7 additions & 0 deletions recipes/opensubdiv/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup(KEEP_RPATHS)

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/opensubdiv/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"3.4.4":
url: "https://github.com/PixarAnimationStudios/OpenSubdiv/archive/v3_4_4.zip"
sha256: "04b52a67e90a56b18d9ddd0384630f43b5263a8fdee1afae081e32d7b23cd5ec"
169 changes: 169 additions & 0 deletions recipes/opensubdiv/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import functools
import os

from conan import ConanFile
from conan.tools.files import get, replace_in_file
from conans import CMake, tools
from conan.errors import ConanInvalidConfiguration

required_conan_version = ">=1.48.0"


class OpenSubdivConan(ConanFile):
name = "opensubdiv"
license = "LicenseRef-LICENSE.txt"
homepage = "https://github.com/PixarAnimationStudios/OpenSubdiv"
url = "https://github.com/conan-io/conan-center-index"
description = "An Open-Source subdivision surface library"
topics = ("cgi", "vfx", "animation", "subdivision surface")

settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"with_tbb": [True, False],
"with_opengl": [True, False],
"with_omp": [True, False],
"with_cuda": [True, False],
"with_clew": [True, False],
"with_opencl": [True, False],
"with_dx": [True, False],
"with_metal": [True, False],
}
default_options = {
"shared": False,
"with_tbb": False,
"with_opengl": False,
"with_omp": False,
"with_cuda": False,
"with_clew": False,
"with_opencl": False,
"with_dx": False,
"with_metal": False,
}

short_paths = True
generators = "cmake"

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

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

@property
def _minimum_cpp_standard(self):
if self.options.get_safe("with_metal"):
return 14
return 11

@property
def _minimum_compilers_version(self):
return {
"Visual Studio": "15",
"gcc": "5",
"clang": "11",
"apple-clang": "11.0",
}

def export_sources(self):
self.copy("CMakeLists.txt")

def config_options(self):
if self.settings.os != "Windows":
del self.options.with_dx
if self.settings.os != "Macos":
del self.options.with_metal

def configure(self):
if self.settings.os == "Windows":
del self.options.shared

def requirements(self):
if self.options.with_tbb:
self.requires("onetbb/2020.3")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, self._minimum_cpp_standard)
min_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if not min_version:
self.output.warn("{} recipe lacks information about the {} compiler support.".format(self.name, self.settings.compiler))
else:
if tools.Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(
"{} requires C++{} support. The current compiler {} {} does not support it.".format(self.name, self._minimum_cpp_standard, self.settings.compiler, self.settings.compiler.version)
)

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

@property
def _osd_gpu_enabled(self):
return any(
[
self.options.with_opengl,
self.options.with_opencl,
self.options.with_cuda,
self.options.get_safe("with_dx"),
self.options.get_safe("with_metal"),
]
)

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["NO_TBB"] = not self.options.with_tbb
cmake.definitions["NO_OPENGL"] = not self.options.with_opengl
cmake.definitions["BUILD_SHARED_LIBS"] = self.options.get_safe("shared")
cmake.definitions["NO_OMP"] = not self.options.with_omp
cmake.definitions["NO_CUDA"] = not self.options.with_cuda
cmake.definitions["NO_DX"] = not self.options.get_safe("with_dx")
cmake.definitions["NO_METAL"] = not self.options.get_safe("with_metal")
cmake.definitions["NO_CLEW"] = not self.options.with_clew
cmake.definitions["NO_OPENCL"] = not self.options.with_opencl
cmake.definitions["NO_PTEX"] = True # Note: PTEX is for examples only, but we skip them..
cmake.definitions["NO_DOC"] = True
cmake.definitions["NO_EXAMPLES"] = True
cmake.definitions["NO_TUTORIALS"] = True
cmake.definitions["NO_REGRESSION"] = True
cmake.definitions["NO_TESTS"] = True
cmake.definitions["NO_GLTESTS"] = True

cmake.configure(build_folder=self._build_subfolder)

return cmake

def build(self):
if self.settings.os == "Macos":
path = os.path.join(self._source_subfolder, "opensubdiv", "CMakeLists.txt")
replace_in_file(self, path, "${CMAKE_SOURCE_DIR}/opensubdiv", "${CMAKE_SOURCE_DIR}/source_subfolder/opensubdiv")
if not self._osd_gpu_enabled:
replace_in_file(self, path, "$<TARGET_OBJECTS:osd_gpu_obj>", "")
cmake = self._configure_cmake()
cmake.build()

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

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "OpenSubdiv")

self.cpp_info.names["cmake_find_package"] = "OpenSubdiv"
self.cpp_info.names["cmake_find_package_multi"] = "OpenSubdiv"

self.cpp_info.components["osdcpu"].libs = ["osdCPU"]
self.cpp_info.components["osdcpu"].set_property("cmake_target_name", "OpenSubdiv::osdcpu")

if self.options.with_tbb:
self.cpp_info.components["osdcpu"].requires = ["onetbb::onetbb"]

if self._osd_gpu_enabled:
self.cpp_info.components["osdgpu"].libs = ["osdGPU"]
self.cpp_info.components["osdgpu"].set_property("cmake_target_name", "OpenSubdiv::osdgpu")
dl_required = self.options.with_opengl or self.options.with_opencl
if self.settings.os in ["Linux", "FreeBSD"] and dl_required:
self.cpp_info.components["osdgpu"].system_libs = ["dl"]
13 changes: 13 additions & 0 deletions recipes/opensubdiv/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

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

find_package(OpenSubdiv REQUIRED)

add_executable(example example.cpp)
target_link_libraries(example OpenSubdiv::OpenSubdiv)
19 changes: 19 additions & 0 deletions recipes/opensubdiv/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

from conans import ConanFile, CMake
from conan.tools.build import cross_building


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

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

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)
41 changes: 41 additions & 0 deletions recipes/opensubdiv/all/test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <opensubdiv/far/topologyDescriptor.h>

static int g_nverts = 8,
g_nfaces = 6;

static int g_vertsperface[6] = {4, 4, 4, 4, 4, 4};

static int g_vertIndices[24] = {0, 1, 3, 2,
2, 3, 5, 4,
4, 5, 7, 6,
6, 7, 1, 0,
1, 7, 5, 3,
6, 0, 2, 4};

using namespace OpenSubdiv;

//------------------------------------------------------------------------------
int main(int, char **) {
typedef Far::TopologyDescriptor Descriptor;

Sdc::SchemeType type = OpenSubdiv::Sdc::SCHEME_CATMARK;

Sdc::Options options;
options.SetVtxBoundaryInterpolation(Sdc::Options::VTX_BOUNDARY_EDGE_ONLY);

Descriptor desc;
desc.numVertices = g_nverts;
desc.numFaces = g_nfaces;
desc.numVertsPerFace = g_vertsperface;
desc.vertIndicesPerFace = g_vertIndices;

Far::TopologyRefiner *refiner =
Far::TopologyRefinerFactory<Descriptor>::Create(desc,
Far::TopologyRefinerFactory<Descriptor>::Options(type,
options));

refiner->RefineUniform(Far::TopologyRefiner::UniformOptions(2));

delete refiner;
return 0;
}
3 changes: 3 additions & 0 deletions recipes/opensubdiv/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"3.4.4":
folder: all