forked from Bekwnn/Eden
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
118 lines (98 loc) · 3.94 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const std = @import("std");
const buildns = std.build;
const fs = std.fs;
const Builder = buildns.Builder;
const Version = buildns.Version;
fn deleteOldSDLLib() !void {
// delete existing dll if it's there
const workingDir = fs.cwd();
var binDir = try workingDir.openDir("zig-cache", .{});
binDir = try binDir.openDir("bin", .{});
try binDir.deleteFile("SDL2.dll");
}
fn openSDLSrcDir() !fs.Dir {
const workingDir = fs.cwd();
var srcPath = try workingDir.openDir("dependency", .{});
srcPath = try srcPath.openDir("SDL2", .{});
srcPath = try srcPath.openDir("lib", .{});
srcPath = try srcPath.openDir("x64", .{});
return srcPath;
}
fn openSDLDstDir() !fs.Dir {
const workingDir = fs.cwd();
var dstPath = try workingDir.openDir("zig-cache", .{});
dstPath = try dstPath.openDir("bin", .{});
return dstPath;
}
fn copySDLLib() !void {
deleteOldSDLLib() catch |e| { // this is allowed to fail
// make dir if it doesn't exist
const workingDir = fs.cwd();
workingDir.makeDir("zig-cache") catch |e2| {}; // may already exist
var cacheDir = try workingDir.openDir("zig-cache", .{});
cacheDir.makeDir("bin") catch |e2| {}; // may already exist
};
// Copy files to zig-cache/bin
const sdlDLLName = "SDL2.dll";
const srcPath = openSDLSrcDir() catch |e| {
std.debug.warn("Unable to resolve src path\n", .{});
return e;
};
const dstPath = openSDLDstDir() catch |e| {
std.debug.warn("Unable to resolve dst path\n", .{});
return e;
};
srcPath.copyFile(sdlDLLName, dstPath, sdlDLLName, .{}) catch |e| {
std.debug.warn("Unable to copy file from {} to {}\n", .{ srcPath, dstPath });
return e;
};
}
pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("sdl-zig-demo", "src/main.zig");
exe.setBuildMode(mode);
// would be nice to run the makefile for cimgui if it hasn't been run. . .
// for build debugging
//exe.setVerboseLink(true);
//exe.setVerboseCC(true);
exe.linkSystemLibrary("c");
exe.linkSystemLibrary("opengl32");
exe.addIncludeDir("src");
exe.addIncludeDir("dependency/cimgui");
exe.addIncludeDir("dependency/cimgui/imgui");
exe.addIncludeDir("dependency/cimgui/imgui/examples");
const imgui_flags = &[_][]const u8{
"-std=c++11",
"-Wno-return-type-c-linkage",
"-DIMGUI_IMPL_OPENGL_LOADER_GLEW=1",
"-fno-exceptions",
"-fno-rtti",
"-Wno-pragma-pack",
};
exe.addCSourceFile("dependency/cimgui/cimgui.cpp", imgui_flags);
exe.addCSourceFile("dependency/cimgui/imgui/imgui.cpp", imgui_flags);
exe.addCSourceFile("dependency/cimgui/imgui/imgui_demo.cpp", imgui_flags);
exe.addCSourceFile("dependency/cimgui/imgui/imgui_draw.cpp", imgui_flags);
exe.addCSourceFile("dependency/cimgui/imgui/imgui_widgets.cpp", imgui_flags);
exe.addCSourceFile("dependency/cimgui/imgui/examples/imgui_impl_sdl.cpp", imgui_flags);
exe.addCSourceFile("dependency/cimgui/imgui/examples/imgui_impl_opengl3.cpp", imgui_flags);
exe.addIncludeDir("dependency/glew-2.1.0/include");
exe.addLibPath("dependency/glew-2.1.0/lib/Release/x64");
exe.linkSystemLibrary("glew32s"); //only include 1 of the 2 glew libs
exe.addIncludeDir("dependency/SDL2/include");
exe.addLibPath("dependency/SDL2/lib/x64");
exe.linkSystemLibrary("SDL2");
exe.addIncludeDir("dependency/assimp/include");
exe.addLibPath("dependency/assimp/lib/Release");
exe.linkSystemLibrary("assimp-vc142-mt");
exe.linkSystemLibrary("user32");
exe.linkSystemLibrary("gdi32");
exe.install();
copySDLLib() catch |e| {
std.debug.warn("Could not copy SDL2.dll, {}\n", .{e});
};
const run_exe_cmd = exe.run();
run_exe_cmd.step.dependOn(b.getInstallStep());
const run_exe_step = b.step("run", "Run the demo");
run_exe_step.dependOn(&run_exe_cmd.step);
}