-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxmake.lua
78 lines (69 loc) · 2.21 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
add_rules("mode.debug", "mode.release")
set_languages("c++2b")
set_warnings("allextra", "error")
add_rules("plugin.compile_commands.autoupdate", {outputdir = "build"})
add_cxxflags("cl::/EHsc") -- doesn't build on msvc otherwise.
if is_mode("debug") then
add_defines("DEBUG")
set_symbols("debug")
set_optimize("none")
set_policy("build.sanitizer.address", true)
set_policy("build.sanitizer.undefined", true)
elseif is_mode("release") then
add_defines("NDEBUG")
set_optimize("faster") -- Arch Linux builds its packages with -O2
add_cxflags("-fstack-protector-strong", "-fstack-clash-protection")
end
local format = function(target)
import("lib.detect.find_program")
local clang_format = find_program("clang-format")
if not clang_format then
return print("Skipped clang-format run for target: %s", target:name())
end
local paramlist = {"--sort-includes", "-i"}
for _, file in pairs(target:headerfiles()) do
table.insert(paramlist, file)
end
for _, file in pairs(target:sourcefiles()) do
table.insert(paramlist, file)
end
os.execv(clang_format, paramlist)
print("Finished clang-format for target: %s", target:name())
end
-- Library
target("rdricpp")
add_includedirs("src")
add_headerfiles("src/types.h", "src/rdricpp.h", {prefixdir = "rdricpp"})
set_kind("static")
add_files("src/*.cpp")
remove_files("src/main.cpp")
-- Run clang-format before build
before_build(format)
target_end()
-- Main
target("main")
set_kind("binary")
add_files("src/*.cpp")
add_deps("rdricpp")
target_end()
-- Tests
-- xmake f --tests=y
-- xmake run tests
option("tests", {default = false, description = "Enable tests"})
if has_config("tests") then
add_requires("catch2 3.x")
-- Tests target
target("tests")
set_kind("binary")
add_packages("catch2")
add_files("src/*.cpp", "tests/*.cpp")
remove_files("src/main.cpp")
add_headerfiles("src/*.h")
add_includedirs("src")
-- Run clang-format before build
before_build(format)
before_run(function (target)
print("Running unit tests on target: %s", target:name())
end)
target_end()
end