/
SConstruct
102 lines (76 loc) · 2.15 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
from __future__ import print_function
import os.path
# try to import an environment first
try:
Import('env')
except:
exec open(os.path.join('config', "build-env.py"))
env = Environment()
siteconf = {}
siteconf['THRUST_DIR'] = None
siteconf['CXX'] = None
if os.path.exists("siteconf.py"):
glb = {}
execfile("siteconf.py", glb, siteconf)
else:
print("""
*************** siteconf.py not found ***************
We will try building anyway, but may not succeed.
Read the README for more details.
""")
f = open("siteconf.py", 'w')
print("""#! /usr/bin/env python
#
# Configuration file.
# Use Python syntax, e.g.:
# VARIABLE = "value"
#
# The following information can be recorded:
#
# THRUST_DIR : Directory where Thrust include files are found.
#
# CXX : C++ compiler
#
""", file=f)
for k, v in sorted(siteconf.items()):
if isinstance(v, str):
v = '"' + str(v) + '"'
print('%s = %s' % (k, v), file=f)
f.close()
Export('siteconf')
if siteconf['CXX']:
env.Replace(CXX=siteconf['CXX'])
if siteconf['THRUST_DIR']:
#Must prepend because build-env.py might have found an old system Thrust
env.Prepend(CPPPATH=siteconf['THRUST_DIR'])
conf = Configure(env)
def check_header(header, name, var):
if not conf.CheckCXXHeader(header):
print("%s headers not found." % name)
print("Once they are installed, update %s in siteconf.py" % var)
Exit(1)
#Check for Thrust
check_header('thrust/version.h', 'Thrust', 'THRUST_DIR')
if conf.CheckLib('cudart'):
#Add cudart
env.Append(LIBS=['cudart'])
conf.Finish()
#Parallelize the build maximally
import multiprocessing
n_jobs = multiprocessing.cpu_count()
SetOption('num_jobs', n_jobs)
env.Append(CCFLAGS=['-fopenmp'])
env.Append(LIBS=['gomp'])
#Add stdc++
env.Append(LIBS=['stdc++'])
Export('env')
#Build library
inplace = SConscript(os.path.join('inplace', 'SConscript'),
variant_dir='build', duplicate=1)
#test_env adds inplace
test_env = env.Clone()
test_env.Append(CPPPATH=[os.path.join(os.getcwd(), 'inplace')])
test_env.Append(LIBS=inplace)
Export('test_env')
#Build tests
SConscript(os.path.join('test', 'SConscript'))