summaryrefslogtreecommitdiff
path: root/vere/ext/natpmp/build.zig
blob: 1dfe1ba399542d8bf4d69dcb14531d87518751a8 (plain)
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
const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const t = target.result;
    const optimize = b.standardOptimizeOption(.{});

    const lib = b.addStaticLibrary(.{
        .name = "natpmp",
        .target = target,
        .optimize = optimize,
    });

    const dep_c = b.dependency("natpmp", .{
        .target = target,
        .optimize = optimize,
    });

    lib.addIncludePath(dep_c.path("include"));

    lib.addCSourceFiles(.{
        .root = dep_c.path(""),
        .files = &.{
            "natpmp.c",
            "getgateway.c",
            "wingettimeofday.c",
        },
        .flags = &.{
            "-fno-sanitize=all",
        },
    });

    lib.installHeader(dep_c.path("natpmp.h"), "natpmp.h");
    lib.installHeader(dep_c.path("getgateway.h"), "getgateway.h");
    lib.installHeader(dep_c.path("natpmp_declspec.h"), "natpmp_declspec.h");

    if (t.os.tag == .windows and t.cpu.arch == .x86_64) {
        lib.root_module.addCMacro("WIN32", "");
        lib.root_module.addCMacro("NATPMP_STATICLIB", "");
        lib.root_module.addCMacro("ENABLE_STRNATPMPERR", "");
    }

    lib.linkLibC();
    b.installArtifact(lib);
}