diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d76645..3ed4fd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,10 +4,12 @@ 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 example" OFF) +option(TINYGLTF_BUILD_VALIDATOR_EXAMPLE "Build validator exampe" OFF) option(TINYGLTF_BUILD_BUILDER_EXAMPLE "Build glTF builder example" 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 @@ -29,19 +31,46 @@ if (TINYGLTF_BUILD_BUILDER_EXAMPLE) endif (TINYGLTF_BUILD_BUILDER_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/README.md b/README.md index 18c43e9..ee80433 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,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 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" 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