Heavily based on: https://sources.debian.org/src/tinygltf/2.8.15%2Bdfsg-2/debian/patches/0001-Fix-build-system.patch/ Enables use of the ports 'nlohmann-json' and 'stb', instead of using the embedded versions. --- CMakeLists.txt.orig +++ CMakeLists.txt @@ -1,14 +1,18 @@ cmake_minimum_required(VERSION 3.6) -project(tinygltf) +project( + TinyGLTF + VERSION ${TINYGLTF_VERSION} + LANGUAGES CXX) include(GNUInstallDirs) include(CMakePackageConfigHelpers) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED On) -set(CMAKE_CXX_EXTENSIONS Off) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +find_package(nlohmann_json 3 REQUIRED) +find_path( + stb_INCLUDE_DIRS + NAMES stb_image.h + PATH_SUFFIXES stb) 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) @@ -36,44 +40,28 @@ add_subdirectory ( examples/build-gltf ) endif (TINYGLTF_BUILD_BUILDER_EXAMPLE) -# -# for add_subdirectory and standalone build -# -if (TINYGLTF_HEADER_ONLY) - add_library(tinygltf INTERFACE) +add_library(${PROJECT_NAME} tiny_gltf.h tiny_gltf.cc) +target_include_directories( + ${PROJECT_NAME} + PUBLIC $ + $ + PRIVATE ${stb_INCLUDE_DIRS}) +target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json::nlohmann_json) +set_target_properties( + ${PROJECT_NAME} + PROPERTIES OUTPUT_NAME "tinygltf" + VERSION ${PROJECT_VERSION}) +add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) - target_include_directories(tinygltf - INTERFACE - $ - $ - ) - -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) - install(TARGETS tinygltf EXPORT tinygltfTargets) - install(EXPORT tinygltfTargets NAMESPACE tinygltf:: FILE TinyGLTFTargets.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) - configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/TinyGLTFConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/TinyGLTFConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/TinyGLTFConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) - # 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 - ) - -endif(TINYGLTF_INSTALL) +install( + TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +export(EXPORT ${PROJECT_NAME}Targets NAMESPACE ${PROJECT_NAME}::) +install( + EXPORT ${PROJECT_NAME}Targets + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) +install(FILES tiny_gltf.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})