From 001c870051359804ec467a1b702f4f26c5f4590d Mon Sep 17 00:00:00 2001 From: syoyo Date: Fri, 18 Dec 2020 01:09:44 +0900 Subject: [PATCH 1/3] Make cmake script `add_subdirectory` friendly. --- CMakeLists.txt | 58 ++++++++++++++++++++++++++++++++++++++------------ tiny_gltf.cc | 4 ++++ 2 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 tiny_gltf.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 30cc854..fea36aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,9 +4,11 @@ PROJECT (tinygltf) SET(CMAKE_CXX_STANDARD 11) -option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example" ON) +option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example(load glTF and dump infos)" ON) option(TINYGLTF_BUILD_GL_EXAMPLES "Build GL exampels(requires glfw, OpenGL, etc)" OFF) option(TINYGLTF_BUILD_VALIDATOR_EXAMPLE "Build validator exampe" OFF) +option(TINYGLTF_HEADER_ONLY "On: header-only mode. Off: create tinygltf library(No TINYGLTF_IMPLEMENTATION required in your project)" OFF) +option(TINYGLTF_INSTALL "Install tinygltf files during install step. Usually set to OFF if you include tinygltf through add_subdirectory()" ON) if (TINYGLTF_BUILD_LOADER_EXAMPLE) ADD_EXECUTABLE ( loader_example @@ -22,20 +24,48 @@ endif (TINYGLTF_BUILD_GL_EXAMPLES) if (TINYGLTF_BUILD_VALIDATOR_EXAMPLE) ADD_SUBDIRECTORY ( examples/validator ) endif (TINYGLTF_BUILD_VALIDATOR_EXAMPLE) + # -# TinuGLTF is a header-only library, so no library build. just install header files. +# for add_subdirectory and standalone build # -INSTALL ( FILES - json.hpp - stb_image.h - stb_image_write.h - tiny_gltf.h - DESTINATION - include +if (TINYGLTF_HEADER_ONLY) + add_library(tinygltf INTERFACE) + + target_include_directories(tinygltf + INTERFACE + $ + $ ) -INSTALL ( FILES - cmake/TinyGLTFConfig.cmake - DESTINATION - cmake - ) +else (TINYGLTF_HEADER_ONLY) + add_library(tinygltf) + target_sources(tinygltf PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/tiny_gltf.cc) + target_include_directories(tinygltf + INTERFACE + $ + $ + ) +endif (TINYGLTF_HEADER_ONLY) + +if (TINYGLTF_INSTALL) + + # Do not install .lib even if !TINYGLTF_HEADER_ONLY + + INSTALL ( FILES + json.hpp + stb_image.h + stb_image_write.h + tiny_gltf.h + ${TINYGLTF_EXTRA_SOUECES} + DESTINATION + include + ) + + INSTALL ( FILES + cmake/TinyGLTFConfig.cmake + DESTINATION + cmake + ) + +endif(TINYGLTF_INSTALL) diff --git a/tiny_gltf.cc b/tiny_gltf.cc new file mode 100644 index 0000000..3f27915 --- /dev/null +++ b/tiny_gltf.cc @@ -0,0 +1,4 @@ +#define TINYGLTF_IMPLEMENTATION +#define STB_IMAGE_IMPLEMENTATION +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include "tiny_gltf.h" From 0f76561ebf21f56b4f38887ec4e6ae89c2d95c03 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sat, 3 Jul 2021 22:06:29 +0900 Subject: [PATCH 2/3] Add readme to use tinygtf through cmake + add_subdirectory. --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 6297778..c3b4da8 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,20 @@ if (!ret) { * `TINYGLTF_USE_RAPIDJSON` : Use RapidJSON as a JSON parser/serializer. RapidJSON files are not included in TinyGLTF repo. Please set an include path to RapidJSON if you enable this featrure. * `TINYGLTF_USE_CPP14` : Use C++14 feature(requires C++14 compiler). This may give better performance than C++11. +## CMake options + +You can add tinygltf using `add_subdirectory` feature. +If you add tinygltf to your project using `add_subdirectory`, it would be better to set `TINYGLTF_HEADER_ONLY` on(just add an include path to tinygltf) and `TINYGLTF_INSTALL` off(Which does not install tinygltf files). + +``` +// Your project's CMakeLists.txt +... + +set(TINYGLTF_HEADER_ONLY ON CACHE INTERNAL "" FORCE) +set(TINYGLTF_INSTALL OFF CACHE INTERNAL "" FORCE) +add_subdirectory(/path/to/tinygltf) +``` + ### Saving gltTF 2.0 model From 0598a20cce8e66355643a2fef13afb7867852ed9 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Wed, 25 Aug 2021 12:06:08 +0100 Subject: [PATCH 3/3] Fix for OpenBSD - wordexp.h not available. --- tiny_gltf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index c5fa225..185bb0d 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -1605,7 +1605,7 @@ class TinyGLTF { #endif -#elif !defined(__ANDROID__) +#elif !defined(__ANDROID__) && !defined(__OpenBSD__) #include #endif @@ -2629,7 +2629,7 @@ std::string ExpandFilePath(const std::string &filepath, void *) { #else #if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || \ - defined(__ANDROID__) || defined(__EMSCRIPTEN__) + defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__OpenBSD__) // no expansion std::string s = filepath; #else