diff --git a/cmake/macros/TargetCgltf.cmake b/cmake/macros/TargetCgltf.cmake new file mode 100644 index 00000000000..1a211b6933c --- /dev/null +++ b/cmake/macros/TargetCgltf.cmake @@ -0,0 +1,4 @@ +macro(TARGET_CGLTF) + find_package(cgltf REQUIRED) + target_link_libraries(${TARGET_NAME} cgltf::cgltf) +endmacro() diff --git a/conan-recipes/cgltf/all/CMakeLists.txt b/conan-recipes/cgltf/all/CMakeLists.txt new file mode 100644 index 00000000000..86b1d0c12f5 --- /dev/null +++ b/conan-recipes/cgltf/all/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.4) +project(cgltf C) + +set(SOURCES_DIR ${CMAKE_CURRENT_LIST_DIR}/src) + +set(SRC_FILES + ${SOURCES_DIR}/cgltf.c + ${SOURCES_DIR}/cgltf_write.c +) +set(HEADER_FILES + ${SOURCES_DIR}/cgltf.h + ${SOURCES_DIR}/cgltf_write.h +) + +add_library(${PROJECT_NAME} ${SRC_FILES}) +set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99) +if(MSVC AND BUILD_SHARED_LIBS) + set_property(TARGET ${PROJECT_NAME} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) +endif() + +include(GNUInstallDirs) +install(TARGETS ${PROJECT_NAME}) +install(FILES ${HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/conan-recipes/cgltf/all/conandata.yml b/conan-recipes/cgltf/all/conandata.yml new file mode 100644 index 00000000000..ce570d96f34 --- /dev/null +++ b/conan-recipes/cgltf/all/conandata.yml @@ -0,0 +1,31 @@ +sources: + "2024.02": + url: "https://github.com/jkuhlmann/cgltf/archive/de399881c65c438a635627c749440eeea7e05599.tar.gz" + sha256: "82f66737421cbd2a0797d7eb1dda61707317c44091dd514bf4a55401ba03fc8f" + "1.13": + url: "https://github.com/jkuhlmann/cgltf/archive/v1.13.tar.gz" + sha256: "053d5320097334767486c6e33d01dd1b1c6224eac82aac2d720f4ec456d8c50b" + "1.12": + url: "https://github.com/jkuhlmann/cgltf/archive/v1.12.tar.gz" + sha256: "2c429bb26256b49bfed2510aef1e5fa9321b27fe4cf226c9ece9a5867150974f" + "1.11": + url: "https://github.com/jkuhlmann/cgltf/archive/v1.11.tar.gz" + sha256: "e086c9e886cf786a091f5aac05250f9ea836488bd799f327f87e95c8f4247cc6" + "1.10": + url: "https://github.com/jkuhlmann/cgltf/archive/v1.10.tar.gz" + sha256: "13047916886298c11fb97a4145e24753847f4dd674423cd5e3c572ccc34fad22" + "1.9": + url: "https://github.com/jkuhlmann/cgltf/archive/v1.9.tar.gz" + sha256: "dcbe3f35b6447a4b867d1acc9c64545b8d4483c9f7df390035489fa41f145b80" + "1.8": + url: "https://github.com/jkuhlmann/cgltf/archive/v1.8.tar.gz" + sha256: "65f4b00c234bc526c3143bb93ed811803fb761cdf25370a378632c8478375938" + "1.7": + url: "https://github.com/jkuhlmann/cgltf/archive/v1.7.tar.gz" + sha256: "a2c16bbfbc3efcddd004e6fb2dd86e664966163b3f70a030b2bb70a89015130b" + "1.6": + url: "https://github.com/jkuhlmann/cgltf/archive/v1.6.tar.gz" + sha256: "d0856911ab0a36b4c7ceba254c39651bbe5b8daec5127a03634e16434bb5e583" + "1.5": + url: "https://github.com/jkuhlmann/cgltf/archive/v1.5.tar.gz" + sha256: "66c09ed6539e64cc8b7a5130172e33605ae42ee57be26bd523e7d820b230bbd1" diff --git a/conan-recipes/cgltf/all/conanfile.py b/conan-recipes/cgltf/all/conanfile.py new file mode 100644 index 00000000000..df487c5e826 --- /dev/null +++ b/conan-recipes/cgltf/all/conanfile.py @@ -0,0 +1,88 @@ +import os + +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import copy, export_conandata_patches, get, load, replace_in_file, save, rename + +required_conan_version = ">=1.53.0" + + +class CgltfConan(ConanFile): + name = "cgltf" + description = "Single-file glTF 2.0 loader and writer written in C99." + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/jkuhlmann/cgltf" + topics = ("gltf", "header-only") + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + 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 + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + + def layout(self): + cmake_layout(self, src_folder="src") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def _create_source_files(self): + cgltf_c = '#define CGLTF_IMPLEMENTATION\n#include "cgltf.h"\n' + cgltf_write_c = '#define CGLTF_WRITE_IMPLEMENTATION\n#include "cgltf_write.h"\n' + save(self, os.path.join(self.build_folder, self.source_folder, "cgltf.c"), cgltf_c) + save(self, os.path.join(self.build_folder, self.source_folder, "cgltf_write.c"), cgltf_write_c) + + def generate(self): + tc = CMakeToolchain(self) + tc.generate() + + def build(self): + self._create_source_files() + cmake = CMake(self) + cmake.configure(build_script_folder=self.source_path.parent) + cmake.build() + + def _remove_implementation(self, header_fullpath): + header_content = load(self, header_fullpath) + begin = header_content.find("/*\n *\n * Stop now, if you are only interested in the API.") + end = header_content.find("/* cgltf is distributed under MIT license:", begin) + implementation = header_content[begin:end] + replace_in_file( + self, + header_fullpath, + implementation, + "/**\n * Implementation removed by conan during packaging.\n * Don't forget to link libs provided in this package.\n */\n\n", + ) + + def package(self): + copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) + cmake.install() + for header_file in ["cgltf.h", "cgltf_write.h"]: + header_fullpath = os.path.join(self.package_folder, "include", header_file) + self._remove_implementation(header_fullpath) + for dll in (self.package_path / "lib").glob("*.dll"): + rename(self, dll, self.package_path / "bin" / dll.name) + + def package_info(self): + self.cpp_info.libs = ["cgltf"] diff --git a/conan-recipes/cgltf/all/test_package/CMakeLists.txt b/conan-recipes/cgltf/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000..ca0a3cec6c7 --- /dev/null +++ b/conan-recipes/cgltf/all/test_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(cgltf REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE cgltf::cgltf) +if(MSVC) + target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS) +endif() diff --git a/conan-recipes/cgltf/all/test_package/conanfile.py b/conan-recipes/cgltf/all/test_package/conanfile.py new file mode 100644 index 00000000000..ef5d7042163 --- /dev/null +++ b/conan-recipes/cgltf/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + 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 can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/conan-recipes/cgltf/all/test_package/test_package.cpp b/conan-recipes/cgltf/all/test_package/test_package.cpp new file mode 100644 index 00000000000..d356cb14c6d --- /dev/null +++ b/conan-recipes/cgltf/all/test_package/test_package.cpp @@ -0,0 +1,54 @@ +#define CGLTF_IMPLEMENTATION // can be defined or not +#include + +#include +#include + +// Performs matrix-vector multiplication, as in (4x4) * (4x1) = (4x1) +static void transform(const cgltf_float matrix[16], const cgltf_float source[4], cgltf_float target[4]) { + target[0] = matrix[0] * source[0] + matrix[4] * source[1] + matrix[ 8] * source[2] + matrix[12] * source[3]; + target[1] = matrix[1] * source[0] + matrix[5] * source[1] + matrix[ 9] * source[2] + matrix[13] * source[3]; + target[2] = matrix[2] * source[0] + matrix[6] * source[1] + matrix[10] * source[2] + matrix[14] * source[3]; + target[3] = matrix[3] * source[0] + matrix[7] * source[1] + matrix[11] * source[2] + matrix[15] * source[3]; +} + +static void set(cgltf_float target[3], float x, float y, float z) { + target[0] = x; + target[1] = y; + target[2] = z; +} + +static void check(cgltf_float target[3], float x, float y, float z) { + if (target[0] != x || target[1] != y || target[2] != z) { + std::fprintf(stderr, "Mismatch detected.\n"); + exit(1); + } +} + +int main() { + cgltf_node node = {}; + + cgltf_float matrix[16]; + cgltf_float source[4] = {1, 2, 3, 1}; + cgltf_float target[4]; + + set(node.scale, 1, 1, 1); + set(node.translation, 1, 0, 0); + cgltf_node_transform_local(&node, matrix); + transform(matrix, source, target); + check(target, 2, 2, 3); + + set(node.scale, 3, 1, 1); + set(node.translation, 0, 0, 0); + cgltf_node_transform_local(&node, matrix); + transform(matrix, source, target); + check(target, 3, 2, 3); + + set(node.scale, 1, 3, 1); + set(node.translation, 1, 0, 0); + cgltf_node_transform_local(&node, matrix); + transform(matrix, source, target); + check(target, 2, 6, 3); + + return 0; +} diff --git a/conan-recipes/cgltf/all/test_v1_package/CMakeLists.txt b/conan-recipes/cgltf/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000..91630d79f4a --- /dev/null +++ b/conan-recipes/cgltf/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/conan-recipes/cgltf/all/test_v1_package/conanfile.py b/conan-recipes/cgltf/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000..84ee68733e5 --- /dev/null +++ b/conan-recipes/cgltf/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +import os + +from conans import ConanFile, CMake, tools + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + 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.settings): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/conan-recipes/cgltf/config.yml b/conan-recipes/cgltf/config.yml new file mode 100644 index 00000000000..9f334f27c89 --- /dev/null +++ b/conan-recipes/cgltf/config.yml @@ -0,0 +1,19 @@ +versions: + "1.13": + folder: all + "1.12": + folder: all + "1.11": + folder: all + "1.10": + folder: all + "1.9": + folder: all + "1.8": + folder: all + "1.7": + folder: all + "1.6": + folder: all + "1.5": + folder: all diff --git a/conanfile.py b/conanfile.py index 938eaff8292..5f9fd72be79 100644 --- a/conanfile.py +++ b/conanfile.py @@ -45,6 +45,7 @@ def requirements(self): # self.requires("shaderc/2021.1") # Broken # self.requires("crashpad/cci.20220219") # Broken self.requires("bullet3/3.25") + self.requires("cgltf/2024.02@overte/stable") self.requires("discord-rpc/3.4.0@anotherfoxguy/stable") self.requires("draco/1.3.5") self.requires("etc2comp/cci.20170424") diff --git a/libraries/model-serializers/CMakeLists.txt b/libraries/model-serializers/CMakeLists.txt index 76775896dcc..0e376515c60 100644 --- a/libraries/model-serializers/CMakeLists.txt +++ b/libraries/model-serializers/CMakeLists.txt @@ -5,3 +5,4 @@ link_hifi_libraries(shared graphics networking image hfm) include_hifi_library_headers(gpu image) target_draco() +target_cgltf() \ No newline at end of file