Sfoglia il codice sorgente

fastgltf: add package (#3594)

* fastgltf: add package

* add patch

* limit plat

* shared readonly for gcc
star9029 1 anno fa
parent
commit
ae568566aa

+ 56 - 0
packages/f/fastgltf/patches/0.7.1/cmake-simdjson.patch

@@ -0,0 +1,56 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index ba4ea84..d5eedcb 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -47,50 +47,7 @@ if (TARGET simdjson::simdjson)
+     target_link_libraries(fastgltf PRIVATE simdjson::simdjson)
+ else()
+     # Try to find simdjson through a find_package call.
+-    find_package(simdjson CONFIG)
+-    if (simdjson_FOUND)
+-        message(STATUS "fastgltf: Found simdjson config")
+-        target_link_libraries(fastgltf PUBLIC simdjson::simdjson)
+-    else()
+-        # Download and configure simdjson
+-        set(SIMDJSON_TARGET_VERSION "3.7.0")
+-        set(SIMDJSON_DL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/deps/simdjson")
+-        file(MAKE_DIRECTORY ${SIMDJSON_DL_DIR})
+-
+-        set(SIMDJSON_HEADER_FILE "${SIMDJSON_DL_DIR}/simdjson.h")
+-        set(SIMDJSON_SOURCE_FILE "${SIMDJSON_DL_DIR}/simdjson.cpp")
+-
+-        macro(download_simdjson)
+-            file(DOWNLOAD "https://raw.githubusercontent.com/simdjson/simdjson/v${SIMDJSON_TARGET_VERSION}/singleheader/simdjson.h" ${SIMDJSON_HEADER_FILE})
+-            file(DOWNLOAD "https://raw.githubusercontent.com/simdjson/simdjson/v${SIMDJSON_TARGET_VERSION}/singleheader/simdjson.cpp" ${SIMDJSON_SOURCE_FILE})
+-        endmacro()
+-
+-        if (EXISTS ${SIMDJSON_HEADER_FILE})
+-            # Look for the SIMDJSON_VERSION define in the header to check the version.
+-            file(STRINGS ${SIMDJSON_HEADER_FILE} SIMDJSON_HEADER_VERSION_LINE REGEX "^#define SIMDJSON_VERSION ")
+-            string(REGEX MATCHALL "[0-9.]+" SIMDJSON_HEADER_VERSION "${SIMDJSON_HEADER_VERSION_LINE}")
+-            message(STATUS "fastgltf: Found simdjson (Version ${SIMDJSON_HEADER_VERSION})")
+-
+-            if (SIMDJSON_HEADER_VERSION STREQUAL "")
+-                message(FATAL_ERROR "fastgltf: Failed to download simdjson")
+-            endif()
+-
+-            if (SIMDJSON_HEADER_VERSION VERSION_LESS SIMDJSON_TARGET_VERSION)
+-                message(STATUS "fastgltf: simdjson outdated, downloading...")
+-                download_simdjson()
+-            endif()
+-        else()
+-            message(STATUS "fastgltf: Did not find simdjson, downloading...")
+-            download_simdjson()
+-
+-            if (NOT EXISTS "${SIMDJSON_HEADER_FILE}")
+-                message(FATAL_ERROR "fastgltf: Failed to download simdjson.")
+-            endif()
+-        endif()
+-
+-        fastgltf_add_source_directory(TARGET fastgltf FOLDER ${SIMDJSON_DL_DIR})
+-        target_include_directories(fastgltf PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/deps/simdjson> $<INSTALL_INTERFACE:include>)
+-    endif()
++
+ endif()
+ 
+ if (SIMDJSON_TARGET_VERSION)

+ 37 - 0
packages/f/fastgltf/xmake.lua

@@ -0,0 +1,37 @@
+package("fastgltf")
+    set_homepage("https://fastgltf.readthedocs.io/v0.7.x/")
+    set_description("A modern C++17 glTF 2.0 library focused on speed, correctness, and usability")
+    set_license("MIT")
+
+    add_urls("https://github.com/spnda/fastgltf/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/spnda/fastgltf.git")
+
+    add_versions("v0.7.1", "44bcb025dd5cd480236a3bc7a3f8c9a708a801ed773b7859677440d22e0e1e7c")
+
+    add_patches("0.7.1", "patches/0.7.1/cmake-simdjson.patch", "943828708f0e011122249196dc70d9a1f026e3212e1c1c35f6988907a6ea4e49")
+
+    add_configs("small_vector", {description = "Uses a custom SmallVector type optimised for small arrays", default = false, type = "boolean"})
+    add_configs("memory_pool", {description = "Disables the memory allocation algorithm based on polymorphic resources", default = false, type = "boolean"})
+    add_configs("f64", {description = "Default to 64-bit double precision floats for everything", default = false, type = "boolean"})
+    add_configs("cxx_standard", {description = "Select c++ standard to build.", default = "17", type = "string", values = {"17", "20"}})
+    if is_plat("linux", "mingw") then
+        add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
+    end
+
+    add_deps("cmake")
+    add_deps("simdjson")
+
+    on_install("windows|x64", "mingw|x86_64", "macosx|x86_64", "linux|x86_64", "linux|arm64", function (package)
+        local configs = {}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+        table.insert(configs, "-DFASTGLTF_USE_CUSTOM_SMALLVECTOR=" .. (package:config("small_vector") and "ON" or "OFF"))
+        table.insert(configs, "-DFASTGLTF_DISABLE_CUSTOM_MEMORY_POOL=" .. (package:config("memory_pool") and "ON" or "OFF"))
+        table.insert(configs, "-DFASTGLTF_USE_64BIT_FLOAT=" .. (package:config("f64") and "ON" or "OFF"))
+        table.insert(configs, "-DFASTGLTF_COMPILE_AS_CPP20=" .. ((package:config("cxx_standard") == "20") and "ON" or "OFF"))
+        import("package.tools.cmake").install(package, configs, {packagedeps = "simdjson"})
+    end)
+
+    on_test(function (package)
+        assert(package:has_cxxtypes("fastgltf::Parser", {configs = {languages = "c++" .. package:config("cxx_standard")}, includes = "fastgltf/core.hpp"}))
+    end)