diff --git a/jkuhlmann/cgltf/v1.5/CMakeLists.txt b/jkuhlmann/cgltf/v1.5/CMakeLists.txt new file mode 100644 index 0000000..cd2adc8 --- /dev/null +++ b/jkuhlmann/cgltf/v1.5/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.15) +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/jkuhlmann/cgltf/v1.5/cgltf_llar.gox b/jkuhlmann/cgltf/v1.5/cgltf_llar.gox new file mode 100644 index 0000000..46332cf --- /dev/null +++ b/jkuhlmann/cgltf/v1.5/cgltf_llar.gox @@ -0,0 +1,156 @@ +import ( + "os" + "path/filepath" + "slices" + "strings" +) + +const consumerSource = `#define CGLTF_IMPLEMENTATION +#include + +#include +#include + +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"); + std::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; +} +` + +id "jkuhlmann/cgltf" + +fromVer "v1.5" + +defaults { + "shared": "OFF", + "fPIC": "ON", +} + +filter => { + for name, values in target.options { + if name != "shared" && name != "fPIC" { + return false + } + for value in values { + if value != "ON" && value != "OFF" { + return false + } + } + } + return true +} + +onBuild ctx => { + installDir := ctx.outputDir + sourceDir := filepath.join(ctx.SourceDir, "src") + os.mkdirAll(sourceDir, 0o755)! + + cmakeLists := ctx.Proj.readFile("v1.5/CMakeLists.txt")! + os.writeFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"), cmakeLists, 0o644)! + os.writeFile(filepath.join(sourceDir, "cgltf.c"), []byte("#define CGLTF_IMPLEMENTATION\n#include \"cgltf.h\"\n"), 0o644)! + os.writeFile(filepath.join(sourceDir, "cgltf_write.c"), []byte("#define CGLTF_WRITE_IMPLEMENTATION\n#include \"cgltf_write.h\"\n"), 0o644)! + + shared := slices.contains(target.options["shared"], "ON") + fPIC := slices.contains(target.options["fPIC"], "ON") + c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) + c.defineBool "BUILD_SHARED_LIBS", shared + c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC + c.configure + c.build + c.install + + licenseDir := filepath.join(installDir, "licenses") + os.mkdirAll(licenseDir, 0o755)! + os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0o644)! + + markerBegin := "/*\n *\n * Stop now, if you are only interested in the API." + markerEnd := "/* cgltf is distributed under MIT license:" + replacement := "/**\n * Implementation removed by conan during packaging.\n * Don't forget to link libs provided in this package.\n */\n\n" + for header in []string{"cgltf.h", "cgltf_write.h"} { + headerPath := filepath.join(installDir, "include", header) + headerContent := string(os.readFile(headerPath)!) + begin := strings.index(headerContent, markerBegin) + end := strings.index(headerContent, markerEnd) + implementation := headerContent[begin:end] + headerContent = strings.replace(headerContent, implementation, replacement, 1) + os.writeFile(headerPath, []byte(headerContent), 0o644)! + } + + flags := []string{ + "-I" + filepath.join(installDir, "include"), + "-L" + filepath.join(installDir, "lib"), + "-lcgltf", + } + ctx.setMetadata strings.join(flags, " ") +} + +onTest ctx => { + installDir := ctx.outputDir + testDir := filepath.join(ctx.SourceDir, "_llar_consumer") + os.mkdirAll(testDir, 0o755)! + + sourcePath := filepath.join(testDir, "consumer.cpp") + os.writeFile(sourcePath, []byte(consumerSource), 0o644)! + + binary := filepath.join(testDir, "consumer") + args := []string{ + "-std=c++11", + sourcePath, + "-I" + filepath.join(installDir, "include"), + "-L" + filepath.join(installDir, "lib"), + "-lcgltf", + "-o", binary, + } + exec "c++", args... + lastErr! + + if slices.contains(target.options["shared"], "ON") { + os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + } + exec binary + lastErr! +} diff --git a/jkuhlmann/cgltf/versions.json b/jkuhlmann/cgltf/versions.json new file mode 100644 index 0000000..8d50b8a --- /dev/null +++ b/jkuhlmann/cgltf/versions.json @@ -0,0 +1,4 @@ +{ + "path": "jkuhlmann/cgltf", + "deps": {} +}