Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions jkuhlmann/cgltf/v1.5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
156 changes: 156 additions & 0 deletions jkuhlmann/cgltf/v1.5/cgltf_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reference recp/cglm/v0.7.2/Cglm_llar.gox documents its build contract, option mapping, metadata fallback, and test rationale; this formula has no explanatory comments. A few genuinely non-obvious steps would benefit from a short note:

  • Synthetic build (lines 88–94): cgltf is header-only and ships no CMake build, so this formula manufactures a CMakeLists.txt + .c translation units that #define ..._IMPLEMENTATION.
  • Header stripping (lines 109–120): the implementation is now compiled into libcgltf, so the CGLTF_IMPLEMENTATION block is excised from the shipped headers to avoid duplicate-symbol conflicts for consumers.
  • Options (lines 67–70): sharedBUILD_SHARED_LIBS, fPICCMAKE_POSITION_INDEPENDENT_CODE.

"os"
"path/filepath"
"slices"
"strings"
)

const consumerSource = `#define CGLTF_IMPLEMENTATION
#include <cgltf.h>

#include <cstdio>
#include <cstdlib>

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)!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cgltf_write.c (and cgltf_write.h) is compiled into the cgltf library and installed, but the consumer test only defines CGLTF_IMPLEMENTATION and never exercises any cgltf_write API. So the write half of the shipped interface is untested. Either add a small CGLTF_WRITE_IMPLEMENTATION / write-API call to the consumer so the installed write header + object code are validated, or drop cgltf_write.* from the build to keep the formula minimal if write support isn't intended.


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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replacement text is written into the shipped cgltf.h / cgltf_write.h that consumers see, and it states the implementation was "removed by conan during packaging" — but this is an LLAR package; Conan isn't involved. The string looks copied from the Conan Center recipe. Suggest wording that's accurate for this project, e.g. "Implementation removed by LLAR during packaging."

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]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guard the marker lookups before slicing. strings.index returns -1 when a marker is absent, so headerContent[begin:end] will panic (negative low bound) or slice incorrectly if either marker is missing — or if begin > end. For v1.5 both markers exist and are correctly ordered, so this works today, but since the whole point of this step is silent header rewriting, any future upstream reformat (or extending fromVer) would fail confusingly instead of cleanly. Suggest checking begin >= 0 && end > begin and failing with a clear error before slicing.

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!
}
4 changes: 4 additions & 0 deletions jkuhlmann/cgltf/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "jkuhlmann/cgltf",
"deps": {}
}
Loading