-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSConstruct
146 lines (110 loc) · 3.54 KB
/
SConstruct
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
"""The compilation script for this project using SCons."""
import os
import fnmatch
import re
# create a separate build directory
VariantDir('build_src', 'src/dsp', duplicate=0)
VariantDir('build_benchmark', 'benchmark', duplicate=0)
VariantDir('build_test', 'test', duplicate=0)
# the compiler and linker flags for the production C++ environment
PROD_FLAGS = [
'-std=c++11',
'-pthread',
'-O3',
'-march=native',
'-pipe',
'-pedantic',
'-Wall'
]
# include for the production environment
INCLUDES = [
'#src',
]
# the compiler and linker flags for the testing C++ environment
TEST_FLAGS = [
'-std=c++11',
'-pthread',
'-march=native',
'-pipe',
'-pedantic',
'-Wall'
]
# include for the testing and benchmarking environment
TEST_INCLUDES = [
'#dep/Catch2/single_include/catch2',
]
TESTING_ENV = Environment(
ENV=os.environ,
CXX='g++',
CPPFLAGS=['-Wno-unused-value'],
CXXFLAGS=TEST_FLAGS,
LINKFLAGS=TEST_FLAGS,
CPPPATH=INCLUDES + TEST_INCLUDES,
)
PRODUCTION_ENV = Environment(
ENV=os.environ,
CXX='g++',
CPPFLAGS=['-Wno-unused-value'],
CXXFLAGS=PROD_FLAGS,
LINKFLAGS=PROD_FLAGS,
CPPPATH=INCLUDES,
)
BENCHMARK_ENV = Environment(
ENV=os.environ,
CXX='g++',
CPPFLAGS=['-Wno-unused-value'],
CXXFLAGS=PROD_FLAGS,
LINKFLAGS=PROD_FLAGS,
CPPPATH=INCLUDES + TEST_INCLUDES,
)
def find_source_files(src_dir, build_dir):
"""
Find all the source files in the given directory.
Args:
src_dir: the source directory to search through
build_dir: the build directory (to replace src_dir with)
Returns:
a list of paths to cpp files where src_dir is replaced by build_dir
"""
files = []
for root, dirnames, filenames in os.walk(src_dir):
root = re.sub(src_dir, build_dir, root)
for filename in fnmatch.filter(filenames, '*.cpp'):
files.append(os.path.join(root, filename))
return sorted(files)
# Locate all the C++ source files
SRC = find_source_files('src/dsp', 'build_src/')
# create separate object files for testing and production environments
TEST_SRC = [TESTING_ENV.Object(f.replace('.cpp', '') + '-test', f) for f in SRC]
PROD_SRC = [PRODUCTION_ENV.Object(f.replace('.cpp', '') + '-prod', f) for f in SRC]
BENCHMARK_SRC = [BENCHMARK_ENV.Object(f.replace('.cpp', '') + '-bench', f) for f in SRC]
#
# MARK: Unit Tests
#
# locate all the testing source files
TEST_FILES = find_source_files('test/', 'build_test/')
# create a list to store all the test target aliases in
UNIT_TEST_ALIASES = []
for file in TEST_FILES: # iterate over all the test source files
UNIT_TEST_PROGRAM = TESTING_ENV.Program(file.replace('.cpp', ''), [file] + TEST_SRC)
UNIT_TEST_ALIASES.append(Alias('test/' + file.replace('build_test/', ''), [UNIT_TEST_PROGRAM], UNIT_TEST_PROGRAM[0].path))
AlwaysBuild(UNIT_TEST_ALIASES[-1])
# create an alias to run all test suites
Alias("test", UNIT_TEST_ALIASES)
#
# MARK: Benchmarks
#
for benchmark in find_source_files('benchmark', 'build_benchmark'):
# create the binary
binary_name = benchmark.replace('.cpp', '')
program = BENCHMARK_ENV.Program(binary_name, [benchmark] + BENCHMARK_SRC)
# create a scons alias for the binary
shell_name = benchmark.replace('build_', '')
benchmark_alias = Alias(shell_name, [program], program[0].path)
AlwaysBuild(benchmark_alias)
#
# MARK: DSP Library
#
# Create a shared library (it will add "lib" to the front automatically)
lib = PRODUCTION_ENV.SharedLibrary('_PotatoChips.so', SRC)
AlwaysBuild(lib)