-
Notifications
You must be signed in to change notification settings - Fork 2
/
xmake.lua
146 lines (136 loc) · 4.29 KB
/
xmake.lua
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
138
139
140
141
142
143
144
145
146
add_rules("mode.debug", "mode.releasedbg")
option("cxx20-modules")
set_description("enable c++20 modules")
set_default(false)
set_values(false, true)
option_end()
if has_config("cxx20-modules") then
add_requires("spdlog", {configs = {
header_only = false, fmt_external = true}})
add_defines("PSCM_USE_CXX20_MODULES")
else
add_requires("spdlog", {configs = {header_only = false}})
end
add_requires("doctest")
add_requires("universal_stacktrace")
add_requires("cpp-linenoise")
add_requires("icu4c")
add_requires("mscharconv")
set_version("0.3.0")
target("pscm") do
set_kind("static")
add_options("cxx20-modules")
add_configfiles(
"src/version.cpp.xmake", {
filename = "version.cpp"})
set_languages("cxx20")
add_includedirs("include", {public = true})
add_headerfiles("include/**.h")
add_packages({"spdlog", "universal_stacktrace", "cpp-linenoise"})
add_packages({"icu4c", "mscharconv"}, {public = true})
add_files({
"src/*.cpp",
"src/icu/**.cpp",
"src/logger/**.cpp",
"src/misc/*.cpp",
"$(buildir)/version.cpp"})
if is_mode("coverage") then
add_cxxflags({
"-O0",
"-fprofile-arcs",
"-ftest-coverage"})
add_ldflags("-coverage")
end
if has_config("cxx20-modules") then
add_files({
"src/**.cppm",
"3rd/std.cppm",
"3rd/fmt.cppm",})
-- dirty hack to include .cc file from fmt, which is source file and
-- should not be included
add_includedirs({
"3rd/fmt/src",
})
end
end
target("repl") do
set_kind("binary")
add_options("cxx20-modules")
set_languages("cxx20")
add_deps("pscm")
add_files("main.cpp")
end
---
--- coverage:
--- use `xmake f -m coverage` to enable coverage
--- first `rm -rf build/` to clean build cache
--- then `xmake build` to build
--- then `xmake run --group=tests` to run tests for coverage
--- run `lcov --directory . --capture --output-file cov/coverage.info`
--- run `genhtml cov/coverage.info --output-directory cov/coverage`
--- open `cov/coverage/index.html` in browser
---
for _, filepath in ipairs(os.files("test/**_tests.cpp")) do
local testname = path.basename(filepath)
target(testname) do
add_options("cxx20-modules")
set_group("tests")
add_deps("pscm")
add_packages({"doctest","spdlog","universal_stacktrace"})
set_languages("cxx20")
add_files(filepath)
if is_mode ("coverage") then
add_cxxflags({
"-O0",
"-fprofile-arcs",
"-ftest-coverage"})
add_ldflags("-coverage")
end
end
end
local integrated_tests = {
{"test/r4rs/r4rstest.scm", "DIRENT"},
{"test/r4rs/r4rstest.scm", "REGISTER_MACHINE"},
{"test/r4rs/r4rs_cont_test.scm", "REGISTER_MACHINE"},
{"test/r4rs/load.scm", "DIRENT"},
{"test/r5rs/r5rstest.scm", "DIRENT"},
{"test/r5rs/r5rstest.scm", "REGISTER_MACHINE"},
{"test/r5rs/load.scm", "DIRENT"},
{"test/r5rs/load.scm", "REGISTER_MACHINE"},
{"test/module/r5rs_test.scm", "DIRENT"},
{"test/module/texmacs/init.scm", "DIRENT"},
}
for _, entry in ipairs(integrated_tests) do
local filepath = entry[1]
local mode = entry[2]
local testname = table.concat(
table.join2(table.slice(path.split(filepath), 3), {mode}),
"_")
target(testname) do
add_options("cxx20-modules")
set_kind("phony")
set_group("tests")
add_deps("repl")
on_run(function (target)
import("core.base.option")
import("core.project.project")
os.cd(path.directory(filepath))
local dep = project.target("repl")
local exec = dep:targetfile()
print(testname .. " start!")
local args = {
"-m", mode,
"-s", path.filename(filepath)
}
-- debugging?
if option.get("debug") then
import("devel.debugger")
debugger.run(exec, args)
else
os.iorunv(exec, args)
print(testname .. " success!")
end
end)
add_packages({"doctest","spdlog","universal_stacktrace"})
end
end