forked from erincatto/box2d
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
137 lines (122 loc) · 3.81 KB
/
build.zig
File metadata and controls
137 lines (122 loc) · 3.81 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const std = @import("std");
const builtin = @import("builtin");
const min_supported_ver = "0.14.0";
comptime {
const order = std.SemanticVersion.order;
const parse = std.SemanticVersion.parse;
if (order(builtin.zig_version, parse(min_supported_ver) catch unreachable) == .lt)
@compileError("Box2d requires zig version " ++ min_supported_ver);
}
fn compileBox2d(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
var box2d_flags_arr = std.ArrayList([]const u8).init(b.allocator);
defer box2d_flags_arr.deinit();
try box2d_flags_arr.appendSlice(&[_][]const u8{
"-std=gnu99",
"-D_GNU_SOURCE",
});
if (options.shared) {
try box2d_flags_arr.appendSlice(&[_][]const u8{
"-fPIC",
"-DBUILD_LIBTYPE_SHARED",
});
}
const box2d = if (options.shared)
b.addSharedLibrary(.{
.name = "box2d",
.target = target,
.optimize = optimize,
})
else
b.addStaticLibrary(.{
.name = "box2d",
.target = target,
.optimize = optimize,
});
box2d.linkLibC();
const c_source_files = &[_][]const u8{
"src/aabb.c",
"src/aabb.h",
"src/arena_allocator.c",
"src/arena_allocator.h",
"src/array.c",
"src/array.h",
"src/atomic.h",
"src/bitset.c",
"src/bitset.h",
"src/body.c",
"src/body.h",
"src/broad_phase.c",
"src/broad_phase.h",
"src/constants.h",
"src/constraint_graph.c",
"src/constraint_graph.h",
"src/contact.c",
"src/contact.h",
"src/contact_solver.c",
"src/contact_solver.h",
"src/core.c",
"src/core.h",
"src/ctz.h",
"src/distance.c",
"src/distance_joint.c",
"src/dynamic_tree.c",
"src/geometry.c",
"src/hull.c",
"src/id_pool.c",
"src/id_pool.h",
"src/island.c",
"src/island.h",
"src/joint.c",
"src/joint.h",
"src/manifold.c",
"src/math_functions.c",
"src/motor_joint.c",
"src/mouse_joint.c",
"src/mover.c",
"src/prismatic_joint.c",
"src/revolute_joint.c",
"src/sensor.c",
"src/sensor.h",
"src/shape.c",
"src/shape.h",
"src/solver.c",
"src/solver.h",
"src/solver_set.c",
"src/solver_set.h",
"src/table.c",
"src/table.h",
"src/timer.c",
"src/types.c",
"src/weld_joint.c",
"src/wheel_joint.c",
"src/world.c",
"src/world.h",
};
box2d.addIncludePath(b.path("include"));
box2d.root_module.addCSourceFiles(.{
.files = c_source_files,
.flags = box2d_flags_arr.items,
});
return box2d;
}
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = try compileBox2d(b, target, optimize, Options.getOptions(b));
lib.installHeader(b.path("include/box2d/base.h"), "base.h");
lib.installHeader(b.path("include/box2d/box2d.h"), "box2d/box2d.h");
lib.installHeader(b.path("include/box2d/collision.h"), "collision.h");
lib.installHeader(b.path("include/box2d/id.h"), "id.h");
lib.installHeader(b.path("include/box2d/math_functions.h"), "math_functions.h");
lib.installHeader(b.path("include/box2d/types.h"), "types.h");
b.installArtifact(lib);
}
pub const Options = struct {
shared: bool = false,
const defaults = Options{};
pub fn getOptions(b: *std.Build) Options {
return .{
.shared = b.option(bool, "shared", "Compile as shared library") orelse defaults.shared,
};
}
};