@@ -93,63 +93,66 @@ pub fn build(b: *std.Build) void {
9393 "-Wno-availability" ,
9494 };
9595
96- const imgui = if (options .shared ) blk : {
97- const lib = b .addSharedLibrary (.{
98- .name = "imgui" ,
99- .target = target ,
100- .optimize = optimize ,
101- });
102-
103- if (target .result .os .tag == .windows ) {
104- lib .root_module .addCMacro ("IMGUI_API" , "__declspec(dllexport)" );
105- lib .root_module .addCMacro ("IMPLOT_API" , "__declspec(dllexport)" );
106- lib .root_module .addCMacro ("ZGUI_API" , "__declspec(dllexport)" );
107- }
108-
109- if (target .result .os .tag == .macos ) {
110- lib .linker_allow_shlib_undefined = true ;
111- }
112-
113- break :blk lib ;
114- } else b .addStaticLibrary (.{
115- .name = "imgui" ,
96+ const imgui_dep = b .dependency ("imgui" , .{
11697 .target = target ,
11798 .optimize = optimize ,
11899 });
119100
120- b .installArtifact (imgui );
121-
122- const emscripten = target .result .os .tag == .emscripten ;
123-
124- imgui .addIncludePath (b .path ("libs" ));
125- imgui .addIncludePath (b .path ("libs/imgui" ));
126-
127- imgui .linkLibC ();
128- if (target .result .abi != .msvc )
129- imgui .linkLibCpp ();
101+ const imgui_mod = b .addModule ("imgui" , .{
102+ .target = target ,
103+ .optimize = optimize ,
104+ .link_libcpp = true ,
105+ });
130106
131- imgui . addCSourceFile (.{
132- .file = b . path ( "src/zgui.cpp" ) ,
133- .flags = cflags ,
107+ const imgui = b . addLibrary (.{
108+ .name = "imgui" ,
109+ .root_module = imgui_mod ,
134110 });
135111
136112 imgui .addCSourceFiles (.{
113+ .root = imgui_dep .path ("" ),
137114 .files = &.{
138- "libs/imgui/imgui.cpp" ,
139- "libs/imgui/imgui_widgets.cpp" ,
140- "libs/imgui/imgui_tables.cpp" ,
141- "libs/imgui/imgui_draw.cpp" ,
142- "libs/imgui/imgui_demo.cpp" ,
115+ "imgui.cpp" ,
116+ "imgui_widgets.cpp" ,
117+ "imgui_tables.cpp" ,
118+ "imgui_draw.cpp" ,
119+ "imgui_demo.cpp" ,
120+ //TODO <tonitch>: add the backend from option
143121 },
144122 .flags = cflags ,
145123 });
124+ imgui .installHeadersDirectory (imgui_dep .path ("" ), "imgui" , .{});
125+
126+ const cimgui_dep = b .dependency ("cimgui" , .{
127+ .target = target ,
128+ .optimize = optimize ,
129+ });
130+
131+ const cimgui_mod = b .addModule ("cimgui" , .{
132+ .target = target ,
133+ .optimize = optimize ,
134+ .link_libcpp = true ,
135+ });
136+
137+ const cimgui = b .addLibrary (.{
138+ .name = "cimgui" ,
139+ .root_module = cimgui_mod ,
140+ });
141+
142+ cimgui .linkLibrary (imgui );
143+ cimgui .addCSourceFile (.{
144+ .file = cimgui_dep .path ("cimgui.cpp" ),
145+ });
146+ cimgui .installHeadersDirectory (cimgui_dep .path ("" ), "" , .{});
147+
148+ // b.installArtifact(cimgui);
146149
147150 if (options .with_freetype ) {
148151 if (b .lazyDependency ("freetype" , .{})) | freetype | {
149152 imgui .linkLibrary (freetype .artifact ("freetype" ));
150153 }
151154 imgui .addCSourceFile (.{
152- .file = b .path ("libs/imgui/ misc/freetype/imgui_freetype.cpp" ),
155+ .file = imgui_dep .path ("misc/freetype/imgui_freetype.cpp" ),
153156 .flags = cflags ,
154157 });
155158 imgui .root_module .addCMacro ("IMGUI_ENABLE_FREETYPE" , "1" );
@@ -226,6 +229,9 @@ pub fn build(b: *std.Build) void {
226229 imgui .addCSourceFile (.{ .file = b .path ("libs/imgui_test_engine/imgui_te_utils.cpp" ), .flags = cflags });
227230 }
228231
232+ const emscripten = target .result .os .tag == .emscripten ;
233+
234+ imgui .addIncludePath (imgui_dep .path ("" )); //For backend to find imgui.h
229235 switch (options .backend ) {
230236 .glfw_wgpu = > {
231237 if (emscripten ) {
@@ -241,9 +247,10 @@ pub fn build(b: *std.Build) void {
241247 }
242248 }
243249 imgui .addCSourceFiles (.{
250+ .root = imgui_dep .path ("" ),
244251 .files = &.{
245- "libs/imgui/ backends/imgui_impl_glfw.cpp" ,
246- "libs/imgui/ backends/imgui_impl_wgpu.cpp" ,
252+ "backends/imgui_impl_glfw.cpp" ,
253+ "backends/imgui_impl_wgpu.cpp" ,
247254 },
248255 .flags = cflags ,
249256 });
@@ -253,9 +260,10 @@ pub fn build(b: *std.Build) void {
253260 imgui .addIncludePath (zglfw .path ("libs/glfw/include" ));
254261 }
255262 imgui .addCSourceFiles (.{
263+ .root = imgui_dep .path ("" ),
256264 .files = &.{
257- "libs/imgui/ backends/imgui_impl_glfw.cpp" ,
258- "libs/imgui/ backends/imgui_impl_opengl3.cpp" ,
265+ "backends/imgui_impl_glfw.cpp" ,
266+ "backends/imgui_impl_opengl3.cpp" ,
259267 },
260268 .flags = &(cflags .* ++ .{"-DIMGUI_IMPL_OPENGL_LOADER_CUSTOM" }),
261269 });
@@ -265,19 +273,21 @@ pub fn build(b: *std.Build) void {
265273 imgui .addIncludePath (zglfw .path ("libs/glfw/include" ));
266274 }
267275 imgui .addCSourceFiles (.{
276+ .root = imgui_dep .path ("" ),
268277 .files = &.{
269- "libs/imgui/ backends/imgui_impl_glfw.cpp" ,
270- "libs/imgui/ backends/imgui_impl_dx12.cpp" ,
278+ "backends/imgui_impl_glfw.cpp" ,
279+ "backends/imgui_impl_dx12.cpp" ,
271280 },
272281 .flags = cflags ,
273282 });
274283 imgui .linkSystemLibrary ("d3dcompiler_47" );
275284 },
276285 .win32_dx12 = > {
277286 imgui .addCSourceFiles (.{
287+ .root = imgui_dep .path ("" ),
278288 .files = &.{
279- "libs/imgui/ backends/imgui_impl_win32.cpp" ,
280- "libs/imgui/ backends/imgui_impl_dx12.cpp" ,
289+ "backends/imgui_impl_win32.cpp" ,
290+ "backends/imgui_impl_dx12.cpp" ,
281291 },
282292 .flags = cflags ,
283293 });
@@ -295,9 +305,10 @@ pub fn build(b: *std.Build) void {
295305 }
296306
297307 imgui .addCSourceFiles (.{
308+ .root = imgui_dep .path ("" ),
298309 .files = &.{
299- "libs/imgui/ backends/imgui_impl_glfw.cpp" ,
300- "libs/imgui/ backends/imgui_impl_vulkan.cpp" ,
310+ "backends/imgui_impl_glfw.cpp" ,
311+ "backends/imgui_impl_vulkan.cpp" ,
301312 },
302313 .flags = &(cflags .* ++ .{ "-DVK_NO_PROTOTYPES" , "-DZGUI_DEGAMMA" }),
303314 });
@@ -307,8 +318,9 @@ pub fn build(b: *std.Build) void {
307318 imgui .addIncludePath (zglfw .path ("libs/glfw/include" ));
308319 }
309320 imgui .addCSourceFiles (.{
321+ .root = imgui_dep .path ("" ),
310322 .files = &.{
311- "libs/imgui/ backends/imgui_impl_glfw.cpp" ,
323+ "backends/imgui_impl_glfw.cpp" ,
312324 },
313325 .flags = cflags ,
314326 });
@@ -318,10 +330,11 @@ pub fn build(b: *std.Build) void {
318330 imgui .addIncludePath (zsdl .path ("libs/sdl2/include" ));
319331 }
320332 imgui .addCSourceFiles (.{
333+ .root = imgui_dep .path ("" ),
321334 .files = &.{
322- "libs/imgui/ backends/imgui_impl_opengl3_loader.h" ,
323- "libs/imgui/ backends/imgui_impl_sdl2.cpp" ,
324- "libs/imgui/ backends/imgui_impl_opengl3.cpp" ,
335+ "backends/imgui_impl_opengl3_loader.h" ,
336+ "backends/imgui_impl_sdl2.cpp" ,
337+ "backends/imgui_impl_opengl3.cpp" ,
325338 },
326339 .flags = &(cflags .* ++ .{"-DIMGUI_IMPL_OPENGL_LOADER_IMGL3W" }),
327340 });
@@ -332,9 +345,10 @@ pub fn build(b: *std.Build) void {
332345 imgui .linkFramework ("Cocoa" );
333346 imgui .linkFramework ("QuartzCore" );
334347 imgui .addCSourceFiles (.{
348+ .root = imgui_dep .path ("" ),
335349 .files = &.{
336- "libs/imgui/ backends/imgui_impl_osx.mm" ,
337- "libs/imgui/ backends/imgui_impl_metal.mm" ,
350+ "backends/imgui_impl_osx.mm" ,
351+ "backends/imgui_impl_metal.mm" ,
338352 },
339353 .flags = objcflags ,
340354 });
@@ -344,8 +358,9 @@ pub fn build(b: *std.Build) void {
344358 imgui .addIncludePath (zsdl .path ("libs/sdl2/include" ));
345359 }
346360 imgui .addCSourceFiles (.{
361+ .root = imgui_dep .path ("" ),
347362 .files = &.{
348- "libs/imgui/ backends/imgui_impl_sdl2.cpp" ,
363+ "backends/imgui_impl_sdl2.cpp" ,
349364 },
350365 .flags = cflags ,
351366 });
@@ -355,9 +370,10 @@ pub fn build(b: *std.Build) void {
355370 imgui .addIncludePath (zsdl .path ("libs/sdl2/include" ));
356371 }
357372 imgui .addCSourceFiles (.{
373+ .root = imgui_dep .path ("" ),
358374 .files = &.{
359- "libs/imgui/ backends/imgui_impl_sdl2.cpp" ,
360- "libs/imgui/ backends/imgui_impl_sdlrenderer2.cpp" ,
375+ "backends/imgui_impl_sdl2.cpp" ,
376+ "backends/imgui_impl_sdlrenderer2.cpp" ,
361377 },
362378 .flags = cflags ,
363379 });
@@ -367,9 +383,10 @@ pub fn build(b: *std.Build) void {
367383 imgui .addIncludePath (zsdl .path ("libs/sdl3/include" ));
368384 }
369385 imgui .addCSourceFiles (.{
386+ .root = imgui_dep .path ("" ),
370387 .files = &.{
371- "libs/imgui/ backends/imgui_impl_sdl3.cpp" ,
372- "libs/imgui/ backends/imgui_impl_sdlgpu3.cpp" ,
388+ "backends/imgui_impl_sdl3.cpp" ,
389+ "backends/imgui_impl_sdlgpu3.cpp" ,
373390 },
374391 .flags = cflags ,
375392 });
@@ -379,9 +396,10 @@ pub fn build(b: *std.Build) void {
379396 imgui .addIncludePath (zsdl .path ("libs/sdl3/include" ));
380397 }
381398 imgui .addCSourceFiles (.{
399+ .root = imgui_dep .path ("" ),
382400 .files = &.{
383- "libs/imgui/ backends/imgui_impl_sdl3.cpp" ,
384- "libs/imgui/ backends/imgui_impl_sdlrenderer3.cpp" ,
401+ "backends/imgui_impl_sdl3.cpp" ,
402+ "backends/imgui_impl_sdlrenderer3.cpp" ,
385403 },
386404 .flags = cflags ,
387405 });
@@ -391,9 +409,10 @@ pub fn build(b: *std.Build) void {
391409 imgui .addIncludePath (zsdl .path ("libs/sdl3/include/SDL3" ));
392410 }
393411 imgui .addCSourceFiles (.{
412+ .root = imgui_dep .path ("" ),
394413 .files = &.{
395- "libs/imgui/ backends/imgui_impl_sdl3.cpp" ,
396- "libs/imgui/ backends/imgui_impl_opengl3.cpp" ,
414+ "backends/imgui_impl_sdl3.cpp" ,
415+ "backends/imgui_impl_opengl3.cpp" ,
397416 },
398417 .flags = &(cflags .* ++ .{"-DIMGUI_IMPL_OPENGL_LOADER_IMGL3W" }),
399418 });
@@ -403,8 +422,9 @@ pub fn build(b: *std.Build) void {
403422 imgui .addIncludePath (zsdl .path ("libs/sdl3/include" ));
404423 }
405424 imgui .addCSourceFiles (.{
425+ .root = imgui_dep .path ("" ),
406426 .files = &.{
407- "libs/imgui/ backends/imgui_impl_sdl3.cpp" ,
427+ "backends/imgui_impl_sdl3.cpp" ,
408428 },
409429 .flags = cflags ,
410430 });
@@ -430,7 +450,8 @@ pub fn build(b: *std.Build) void {
430450 b .installArtifact (tests );
431451
432452 tests .root_module .addImport ("zgui_options" , options_module );
433- tests .linkLibrary (imgui );
453+ tests .linkLibrary (cimgui );
454+ tests .addIncludePath (cimgui_dep .path ("" ));
434455
435456 test_step .dependOn (& b .addRunArtifact (tests ).step );
436457}
0 commit comments