-
Notifications
You must be signed in to change notification settings - Fork 1
/
xmake.lua
110 lines (94 loc) · 2.76 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
add_rules("mode.release", "mode.debug", "mode.releasedbg")
add_requires("catch2 2.13.9")
set_arch("x64")
set_plat("windows")
-- Generates a hash key made of packages confs/version, for CI
task("dephash")
on_run(function ()
import("core.project.project")
import("private.action.require.impl.package")
local requires, requires_extra = project.requires_str()
local key = {}
for _, instance in irpairs(package.load_packages(requires, {requires_extra = requires_extra})) do
table.insert(key, instance:name() .. "-" .. instance:version_str() .. "-" .. instance:buildhash())
end
table.sort(key)
key = table.concat(key, ",")
print(hash.uuid4(key):gsub('-', ''):lower())
end)
set_menu {
usage = "xmake dephash",
description = "Outputs a hash key of current dependencies version/configuration"
}
task_end()
rule("format_before_build")
before_build(function(target)
import("detect.sdks.find_vstudio")
import("lib.detect.find_program")
local vstudio = find_vstudio()
local vs = vstudio["2022"]
if vs == nil then
vs = vstudio["2019"]
if vs == nil then
raise("Visual Studio 2022 or 2019 is required")
end
end
local clangformat = find_program("clang-format.exe", {envs = {PATH = vs.vcvarsall.x64.PATH}})
if clangformat == nil or clangformat == "" then
print("clang-format.exe not found in", vs.vcvarsall.x64.PATH)
raise("clang-format is required. Please install the C++ Clang Compiler for Windows >= 15.0.1 in Visual Studio Install Individual components (Tools/Get Tools and Features...)")
end
local sourcefiles = target:sourcefiles()
local headerfiles = target:headerfiles()
for k, v in pairs(sourcefiles) do
os.exec(clangformat .. " --style=file -i " .. v)
end
for k, v in pairs(headerfiles) do
os.exec(clangformat .. " --style=file -i " .. v)
end
end)
rule_end()
target("cdm")
set_kind("phony")
set_languages("c++20")
add_rules("format_before_build")
add_headerfiles("*.hpp")
add_includedirs(".")
target_end()
local tests = {
"direction",
"line",
"matrix3",
"matrix4",
"misc",
"perspective",
"plane",
"quaternion",
"segment2",
"segment3",
"static_pi_fraction_cos",
"static_pi_fraction_sin",
"static_pi_fraction_tan",
"transform3",
"transform3__multiplication",
-- "transform3__rotation",
"transform3__translation",
"value_domain",
"vector2",
"vector3",
"vector4",
}
for _,v in pairs(tests) do
target("cdm_test_"..v)
set_kind("binary")
set_languages("c++20")
add_deps("cdm")
add_rules("format_before_build")
add_files("tests/"..v..".cpp")
add_headerfiles("*.hpp")
add_headerfiles("tests/*.hpp")
add_packages("catch2")
add_includedirs(".", "tests")
set_group("test")
target_end()
end