Repository navigation
Expand file tree
/
Copy pathmake.mjs
More file actions
61 lines (47 loc) · 1.64 KB
/
Copy pathmake.mjs
File metadata and controls
61 lines (47 loc) · 1.64 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
import { cli, Path } from "esmakefile";
import { writeFile } from "node:fs/promises";
import { createRequire } from "node:module";
import { errorCodes } from "./jslib/errorCodes.mjs";
import { Distribution, addCompileCommands } from "esmakefile-cmake";
const require = createRequire(import.meta.url);
const nunjucks = require("nunjucks");
const { version } = require("./package.json");
function addRenderWithErrorCodes(make, dest, srcRaw) {
const src = Path.src(srcRaw);
make.add(dest, [src], async (args) => {
const output = nunjucks.render(args.abs(Path.src(src)), { errorCodes });
await writeFile(args.abs(dest), output, "utf8");
});
}
cli((make) => {
const include = Path.src("include");
const genInclude = Path.build("include");
const errcH = genInclude.join("msgstream/errc.h");
const errcC = Path.build("src/errc.c");
make.add("all", []);
addRenderWithErrorCodes(make, errcH, "src/njx/errc.h");
addRenderWithErrorCodes(make, errcC, "src/njx/errc.c");
const d = new Distribution(make, {
name: "msgstream",
version,
cStd: 11,
cxxStd: 20,
});
const msg = d.addLibrary({
name: "msgstream",
src: ["src/msgstream.c", errcC],
includeDirs: [include, genInclude],
});
// TODO - esmakefile-cmake should support obj for src lookup
const err = Path.gen(errcC, { ext: ".o" });
make.add(err, [errcH]);
const gtest = d.findPackage("gtest_main");
d.addTest({
name: "msgstream_test",
src: ["test/msgstream_test.cpp"],
linkTo: [msg, gtest],
});
make.add("test", [d.test], () => {});
const compileCommands = addCompileCommands(make, d);
make.add("all", [d.test, compileCommands]);
});