Skip to content

Instantly share code, notes, and snippets.

@jacobly0
Last active February 28, 2024 17:11
Show Gist options
  • Save jacobly0/d82bb07e6b8ff9b737d2c347e33d15c0 to your computer and use it in GitHub Desktop.
Save jacobly0/d82bb07e6b8ff9b737d2c347e33d15c0 to your computer and use it in GitHub Desktop.
zmesh build changes
const std = @import("std");
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const shape_use_32bit_indices = b.option(bool, "shape_use_32bit_indices", "Enable par shapes 32-bit indices") orelse true;
const shared = b.option(bool, "shared", "Build as shared library") orelse false;
const zmesh_options = b.addOptions();
zmesh_options.addOption(bool, "shape_use_32bit_indices", shape_use_32bit_indices);
zmesh_options.addOption(bool, "shared", shared);
const zmesh = b.addModule("zmesh", .{
.root_source_file = .{ .path = "src/main.zig" },
.imports = &.{ .{
.name = "zmesh_options",
.module = b.addModule("zmesh_options", .{
.root_source_file = zmesh_options.getOutput(),
}),
} },
});
const zmesh_c_cpp = if (shared) blk: {
const lib = b.addSharedLibrary(.{
.name = "zmesh",
.target = target,
.optimize = optimize,
});
if (target.result.os.tag == .windows) {
lib.defineCMacro("CGLTF_API", "__declspec(dllexport)");
lib.defineCMacro("MESHOPTIMIZER_API", "__declspec(dllexport)");
lib.defineCMacro("ZMESH_API", "__declspec(dllexport)");
}
break :blk lib;
} else b.addStaticLibrary(.{
.name = "zmesh",
.target = target,
.optimize = optimize,
});
zmesh_c_cpp.linkLibC();
if (target.result.abi != .msvc)
zmesh_c_cpp.linkLibCpp();
const par_shapes_t = if (shape_use_32bit_indices)
"-DPAR_SHAPES_T=uint32_t"
else
"-DPAR_SHAPES_T=uint16_t";
zmesh_c_cpp.addIncludePath(.{ .path = "libs/par_shapes" });
zmesh_c_cpp.addCSourceFile(.{
.file = .{ .path = "libs/par_shapes/par_shapes.c" },
.flags = &.{ "-std=c99", "-fno-sanitize=undefined", par_shapes_t },
});
zmesh_c_cpp.addCSourceFiles(.{
.root = .{ .path = "libs/meshoptimizer" },
.files = &.{
"clusterizer.cpp",
"indexgenerator.cpp",
"vcacheoptimizer.cpp",
"vcacheanalyzer.cpp",
"vfetchoptimizer.cpp",
"vfetchanalyzer.cpp",
"overdrawoptimizer.cpp",
"overdrawanalyzer.cpp",
"simplifier.cpp",
"allocator.cpp",
},
});
zmesh_c_cpp.addIncludePath(.{ .path = "libs/cgltf" });
zmesh_c_cpp.addCSourceFile(.{
.file = .{ .path = "libs/cgltf/cgltf.c" },
.flags = &.{"-std=c99"},
});
const zmesh_tests = b.addTest(.{
.name = "zmesh-tests",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
zmesh_tests.addIncludePath(.{ .path = "libs/cgltf" });
const test_step = b.step("test", "Run zmesh tests");
test_step.dependOn(&b.addRunArtifact(zmesh_tests).step);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment