ImGui demo window
This commit is contained in:
93
cimgui/build.zig
Normal file
93
cimgui/build.zig
Normal file
@@ -0,0 +1,93 @@
|
||||
const std = @import("std");
|
||||
const vkgen = @import("vulkan-zig");
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const imgui_dep = b.dependency("imgui", .{});
|
||||
const cimgui_dep = b.dependency("cimgui", .{});
|
||||
|
||||
const luajit = try b.findProgram(&.{"luajit"}, &.{});
|
||||
|
||||
const gen = b.addSystemCommand(&.{luajit});
|
||||
gen.setCwd(cimgui_dep.path("generator/"));
|
||||
gen.addFileArg(cimgui_dep.path("generator/generator.lua"));
|
||||
gen.addArgs(&.{
|
||||
"zig cc",
|
||||
"comments internal noimstrv",
|
||||
"glfw",
|
||||
"vulkan",
|
||||
});
|
||||
_ = gen.captureStdOut(); // to quiet output
|
||||
|
||||
{
|
||||
const relpath = try std.fs.path.relative(
|
||||
b.allocator,
|
||||
cimgui_dep.path("generator").getPath(b),
|
||||
imgui_dep.path("").getPath(b),
|
||||
);
|
||||
defer b.allocator.free(relpath);
|
||||
gen.setEnvironmentVariable(
|
||||
"IMGUI_PATH",
|
||||
relpath,
|
||||
);
|
||||
}
|
||||
|
||||
const copy = b.addWriteFiles();
|
||||
copy.step.dependOn(&gen.step);
|
||||
_ = copy.addCopyDirectory(imgui_dep.path(""), "imgui", .{
|
||||
.include_extensions = &.{ ".h", ".cpp" },
|
||||
});
|
||||
_ = copy.addCopyFile(cimgui_dep.path("cimgui.h"), "cimgui.h");
|
||||
_ = copy.addCopyFile(cimgui_dep.path("cimgui.cpp"), "cimgui.cpp");
|
||||
_ = copy.addCopyFile(cimgui_dep.path("generator/output/cimgui_impl.h"), "cimgui_impl.h");
|
||||
|
||||
const cimgui = b.addSharedLibrary(.{
|
||||
.name = "cimgui",
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
cimgui.step.dependOn(©.step);
|
||||
cimgui.linkLibC();
|
||||
cimgui.linkLibCpp();
|
||||
cimgui.addIncludePath(copy.getDirectory());
|
||||
cimgui.addIncludePath(copy.getDirectory().path(b, "imgui"));
|
||||
cimgui.addCSourceFiles(.{
|
||||
.root = copy.getDirectory(),
|
||||
.files = &.{
|
||||
"cimgui.cpp",
|
||||
"imgui/imgui.cpp",
|
||||
"imgui/imgui_tables.cpp",
|
||||
"imgui/imgui_widgets.cpp",
|
||||
"imgui/imgui_demo.cpp",
|
||||
"imgui/imgui_draw.cpp",
|
||||
"imgui/backends/imgui_impl_glfw.cpp",
|
||||
"imgui/backends/imgui_impl_vulkan.cpp",
|
||||
},
|
||||
.flags = &.{
|
||||
"-DIMGUI_IMPL_VULKAN_NO_PROTOTYPES",
|
||||
"-DCIMGUI_USE_GLFW",
|
||||
"-DCIMGUI_USE_VULKAN",
|
||||
"-DIMGUI_IMPL_API=extern \"C\"",
|
||||
},
|
||||
});
|
||||
cimgui.installHeader(copy.getDirectory().path(b, "cimgui.h"), "cimgui.h");
|
||||
cimgui.installHeader(copy.getDirectory().path(b, "cimgui_impl.h"), "cimgui_impl.h");
|
||||
|
||||
// todo separate impls into different shared libraries for easier linkage
|
||||
cimgui.linkSystemLibrary2("glfw3", .{
|
||||
.needed = true,
|
||||
.preferred_link_mode = .static,
|
||||
.use_pkg_config = .force,
|
||||
});
|
||||
|
||||
b.installArtifact(cimgui);
|
||||
|
||||
const cimgui_mod = b.addModule("cimgui", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.root_source_file = b.path("src/root.zig"),
|
||||
});
|
||||
cimgui_mod.linkLibrary(cimgui);
|
||||
}
|
19
cimgui/build.zig.zon
Normal file
19
cimgui/build.zig.zon
Normal file
@@ -0,0 +1,19 @@
|
||||
.{
|
||||
.name = "cimgui",
|
||||
.version = "0.0.0",
|
||||
|
||||
.dependencies = .{
|
||||
.cimgui = .{
|
||||
.url = "https://github.com/cimgui/cimgui/archive/refs/tags/1.90.8dock.tar.gz",
|
||||
.hash = "12207ee69164f88f4b41ee5d44edf3835ec4dab0c0cd885799da67d56668f4a3d46b",
|
||||
},
|
||||
.imgui = .{
|
||||
.url = "https://github.com/ocornut/imgui/archive/refs/tags/v1.90.8-docking.tar.gz",
|
||||
.hash = "122065151b97161e25abb71c9df2fd9fba42aaca8c33d689a480b883d82411c8fabe",
|
||||
},
|
||||
},
|
||||
|
||||
.paths = .{
|
||||
"",
|
||||
},
|
||||
}
|
10
cimgui/src/root.zig
Normal file
10
cimgui/src/root.zig
Normal file
@@ -0,0 +1,10 @@
|
||||
pub const c = @cImport({
|
||||
@cDefine("CIMGUI_DEFINE_ENUMS_AND_STRUCTS", {});
|
||||
@cInclude("cimgui.h");
|
||||
|
||||
@cInclude("vulkan/vulkan.h");
|
||||
|
||||
@cDefine("CIMGUI_USE_VULKAN", {});
|
||||
@cDefine("CIMGUI_USE_GLFW", {});
|
||||
@cInclude("cimgui_impl.h");
|
||||
});
|
Reference in New Issue
Block a user