Files
zig-experiments/package-glfw/README.md
David Allemang c147c624a7 Add 'package-glfw/' from commit 'a8f2a899cdd0bb4316b7d50f2ee3296bf6fb208f'
git-subtree-dir: package-glfw
git-subtree-mainline: cddb3ce509
git-subtree-split: a8f2a899cd
2025-08-04 22:14:49 -04:00

1.3 KiB

Fetch GLFW via experimental zig package manager build.zig.zon

Invoke CMake commands to build and install GLFW to zig-cache

Add Zig executable which includes and links to GLFW.

Drawing inspiration from CMake ExternalProject.


Ideally there would be some mechanism like b.addCMakeProject with options to:

  • provide CMake CLI or CACHE_ARGS
  • infer source/config/install dirs
  • infer installed libraries and linkage (pkgconfig?)
  • inf
  • set CMAKE_CXX_COMPILER to zig c++
  • set CMAKE_C_COMPILER to zig c
  • Infer modules/artifacts from installed targets.
    • inspect/evaluate glfw3Targets.cmake and produce a module/artifact for each cmake target

I imagine usage like:

const glfw = b.dependency("glfw", .{
    // automatically use zig for CMAKE_C_COMPILER, CMAKE_CXX_COMPILER
    .target = target,  // pass on as compiler flags
    .optimize = optimize, // convert to CMAKE_BUILD_TYPE
    .cache_args = .{
        "GLFW_BUILD_SHARED_LIBS:BOOL=OFF",
        "GLFW_BUILD_WAYLAND:BOOL=OFF",
        "GLFW_BUILD_X11:BOOL=ON",
        "GLFW_BUILD_TESTS:BOOL=OFF",
    },
});

exe.addModule(
    "glfw",  // the name of the @import which defers to @cImport.
    glfw.module("glfw"), // the name of the cmake target
);
exe.linkLibrary(
    glfw.artifact("glfw"), // the name of the cmake target
);