|
| 1 | +const std = @import("std"); |
| 2 | + |
| 3 | +pub fn build(b: *std.Build) !void { |
| 4 | + const target = b.standardTargetOptions(.{}); |
| 5 | + const optimize = b.standardOptimizeOption(.{}); |
| 6 | + |
| 7 | + const include = b.path("include"); |
| 8 | + |
| 9 | + const lib = b.addStaticLibrary(.{ |
| 10 | + .name = "demo", |
| 11 | + .target = target, |
| 12 | + .optimize = optimize, |
| 13 | + }); |
| 14 | + lib.addIncludePath(include); |
| 15 | + lib.addCSourceFiles(.{ |
| 16 | + .root = b.path("src"), |
| 17 | + .files = &.{"source.cpp"}, |
| 18 | + .flags = &CXXFLAGS, |
| 19 | + }); |
| 20 | + lib.linkLibCpp(); |
| 21 | + lib.installHeadersDirectory(include, "demo", .{ .include_extensions = &.{".hpp"} }); |
| 22 | + b.installArtifact(lib); |
| 23 | + |
| 24 | + { // Test |
| 25 | + const test_step = b.step("test", "Run tests"); |
| 26 | + const test_exe = b.addExecutable(.{ .name = "test_demo", .target = target, .optimize = optimize }); |
| 27 | + const run_test = b.addRunArtifact(test_exe); |
| 28 | + |
| 29 | + const catch2_dep = b.dependency("catch2", .{ .target = target, .optimize = optimize }); |
| 30 | + const catch2_lib = catch2_dep.artifact("Catch2"); |
| 31 | + const catch2_main = catch2_dep.artifact("Catch2WithMain"); |
| 32 | + |
| 33 | + test_exe.addCSourceFiles(.{ .root = b.path("test"), .files = &.{"test.cpp"}, .flags = &CXXFLAGS }); |
| 34 | + test_exe.linkLibrary(lib); |
| 35 | + test_exe.linkLibrary(catch2_lib); |
| 36 | + test_exe.linkLibrary(catch2_main); |
| 37 | + test_step.dependOn(&run_test.step); |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +const CXXFLAGS = .{ |
| 42 | + "--std=c++23", |
| 43 | + "-Wall", |
| 44 | + "-Wextra", |
| 45 | + "-Werror", |
| 46 | +}; |
0 commit comments