-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTupfile.lua
135 lines (111 loc) Β· 3.29 KB
/
Tupfile.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
--
-- _______ __ __ __ __ __
-- | | | |_|__| |__| |_.--.--.
-- | | | _| | | | _| | |
-- |_______|____|__|__|__|____|___ |
-- |_____|
--
function eval(cmd)
local file = assert(io.popen(cmd, 'r'))
local output = file:read('*all')
file:close()
return output:gsub("[\r\n]", "")
end
--
-- _______ __ __
-- | |.-----.| |_|__|.-----.-----.-----.
-- | - || _ || _| || _ | |__ --|
-- |_______|| __||____|__||_____|__|__|_____|
-- |__|
--
CXX = 'g++'
CXX_FLAGS = '-std=c++17 '
INCLUDE_FLAGS = '-I src/ -isystem lib/ '
LINK_FLAGS = ''
SRC_FILES = tup.glob("src/*.cpp")
DEBUG = true
COVERAGE = true
RELEASE = false
if not (RELEASE != DEBUG) then
error("RELEASE and DEBUG mutually exclusive")
end
if RELEASE then
CXX_FLAGS = CXX_FLAGS .. ' -O2'
end
if DEBUG then
CXX_FLAGS = CXX_FLAGS .. ' -O0 -g -pg '
end
if COVERAGE then
CXX_FLAGS = CXX_FLAGS .. '-fprofile-arcs -ftest-coverage '
LINK_FLAGS = LINK_FLAGS .. '-lgcov --coverage '
end
--
-- _____ __ __ __
-- | |_|__| |--.----.---.-.----.|__|.-----.-----.
-- | | | _ | _| _ | _|| || -__|__ --|
-- |_______|__|_____|__| |___._|__| |__||_____|_____|
--
for _, v in ipairs({'clipp', 'linalg', 'sol3', 'spdlog', 'tinyobjloader'}) do
INCLUDE_FLAGS = INCLUDE_FLAGS .. '-isystem ' .. 'lib/' .. v .. ' '
end
LINK_FLAGS = LINK_FLAGS .. eval('pkg-config --libs --static glfw3 lua glew gl') .. ' '
--
-- _____ __ __ ___ ______ __ __
-- | |_|__|.-----.| |--. / / | |.-----.--------.-----.|__| |.-----.
-- | | || || < ,' ,' | ---|| _ | | _ || | || -__|
-- |_______|__||__|__||__|__| /__/ |______||_____|__|__|__| __||__|__||_____|
--
function compile_source()
local command = string.format(
'%s %s -c %%f -o %%o %s',
CXX,
CXX_FLAGS,
INCLUDE_FLAGS
)
for _, file in pairs(SRC_FILES) do
local rule = {
inputs = file,
outputs = 'build/%B.o',
command = command
}
if COVERAGE then
rule.extra_outputs = { 'build/%B.gcno' }
end
tup.frule(rule)
end
end
function link_source()
local command = string.format('%s %s %%f -o %%o %s', CXX, CXX_FLAGS, LINK_FLAGS)
tup.frule({
inputs = tup.glob('build/*.o'),
outputs = 'build/raytracer',
command = command
})
end
function compile_tests()
for _, file in pairs(tup.glob('test/*.cpp')) do
local rule = {
inputs = file,
outputs = 'build_test/%B.o',
command = string.format('%s %s %s -c %%f -o %%o', CXX, CXX_FLAGS, INCLUDE_FLAGS),
}
if COVERAGE then
rule.extra_outputs = { 'build_test/%B.gcno' }
end
tup.frule(rule)
end
end
function link_tests()
local amalgamated = {}
tup.append_table(amalgamated, tup.glob("build/*.o"))
tup.append_table(amalgamated, tup.glob("build_test/*.o"))
tup.frule({
inputs = amalgamated,
outputs = 'build_test/test',
command = string.format('%s %s %%f -o %%o', CXX, LINK_FLAGS)
})
end
compile_source()
link_source()
--compile_tests()
--link_tests()