85 lines
2.7 KiB
Zig
85 lines
2.7 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const miclib_include = b.option(
|
|
[]const u8,
|
|
"miclib_include",
|
|
"Directory containing miclib.h and scif.h. Example: -Dmiclib_include=/usr/local/include",
|
|
);
|
|
|
|
const miclib_libdir = b.option(
|
|
[]const u8,
|
|
"miclib_libdir",
|
|
"Directory containing libmicmgmt.so/libscif.so. Example: -Dmiclib_libdir=/usr/local/lib",
|
|
);
|
|
|
|
const miclib_name = b.option(
|
|
[]const u8,
|
|
"miclib_name",
|
|
"System library name for miclib without lib/extension. Default: micmgmt",
|
|
) orelse "micmgmt";
|
|
|
|
const module = b.addModule("miclib", .{
|
|
.root_source_file = b.path("src/lib.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
});
|
|
configureMiclibModule(module, miclib_include, miclib_libdir, miclib_name);
|
|
|
|
const test_module = b.createModule(.{
|
|
.root_source_file = b.path("src/lib.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
});
|
|
configureMiclibModule(test_module, miclib_include, miclib_libdir, miclib_name);
|
|
|
|
const c_includes = b.addTranslateC(.{
|
|
.root_source_file = b.path("src/c_includes.h"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.link_libc = true,
|
|
});
|
|
|
|
module.addImport("miclib_c", c_includes.createModule());
|
|
|
|
const lib_tests = b.addTest(.{ .root_module = test_module });
|
|
const run_tests = b.addRunArtifact(lib_tests);
|
|
const test_step = b.step("test", "Run unit tests");
|
|
test_step.dependOn(&run_tests.step);
|
|
|
|
const enumerate_module = b.createModule(.{
|
|
.root_source_file = b.path("examples/enumerate.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.imports = &.{.{ .name = "miclib", .module = module }},
|
|
});
|
|
|
|
const enumerate = b.addExecutable(.{
|
|
.name = "miclib-enumerate",
|
|
.root_module = enumerate_module,
|
|
});
|
|
|
|
b.installArtifact(enumerate);
|
|
|
|
const run_enumerate = b.addRunArtifact(enumerate);
|
|
const run_step = b.step("example", "Run examples/enumerate.zig");
|
|
run_step.dependOn(&run_enumerate.step);
|
|
}
|
|
|
|
fn configureMiclibModule(module: *std.Build.Module, miclib_include: ?[]const u8, miclib_libdir: ?[]const u8, miclib_name: []const u8) void {
|
|
if (miclib_include) |path|
|
|
module.addIncludePath(.{ .cwd_relative = path });
|
|
|
|
if (miclib_libdir) |path|
|
|
module.addLibraryPath(.{ .cwd_relative = path });
|
|
|
|
module.link_libcpp = true;
|
|
module.linkSystemLibrary(miclib_name, .{});
|
|
module.linkSystemLibrary("scif", .{});
|
|
}
|