-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
76 lines (56 loc) · 2.49 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
import fnmatch
import os
# read variables from the cache, a user's custom.py file or command line arguments
vars = Variables(['variables.cache', 'custom.py'], ARGUMENTS)
vars.Add(BoolVariable('debug', 'Debug build', 'no'))
vars.Add(BoolVariable('edebug', 'Extreme debug', 'no'))
# The LAPKT path can be optionally specified, otherwise we fetch it from the corresponding environment variable.
vars.Add(PathVariable('lapkt', 'Path where the LAPKT library is installed', os.getenv('LAPKT', ''), PathVariable.PathIsDir))
def which(program):
""" Helper function emulating unix 'which' command """
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
return exe_file
return None
def locate_source_files(base_dir, pattern):
matches = []
for root, dirnames, filenames in os.walk(base_dir):
for filename in fnmatch.filter(filenames, pattern):
matches.append(os.path.join(root, filename))
return matches
# Read the preferred compiler from the environment - if none specified, choose CLANG if possible
default_compiler = 'clang++' if which("clang++") else 'g++'
gcc = os.environ.get('CXX', default_compiler)
env = Environment(variables=vars, ENV=os.environ, CXX=gcc)
if env['debug']:
build_dirname = '_build/debug'
else:
build_dirname = '_build/prod'
env.VariantDir(build_dirname, '.')
Help(vars.GenerateHelpText(env))
env.Append(CCFLAGS = ['-Wall', '-pedantic', '-std=c++14' ]) # Flags common to all options
# Extreme debug implies normal debug as well
if env['debug'] or env['edebug']:
env.Append(CCFLAGS = ['-g', '-DDEBUG' ])
lib_name = 'lapkt-novelty-debug'
else:
env.Append(CCFLAGS = ['-g', '-O3', '-DNDEBUG' ])
lib_name = 'lapkt-novelty'
# Additionally, extreme debug implies a different name plus extra compilation flags
if env['edebug']:
env.Append(CCFLAGS = ['-DEDEBUG'])
lib_name = 'lapkt-novelty-edebug'
# Base include directories
include_paths = ['src', os.path.join(env['lapkt'], 'include')]
isystem_paths = []
sources = locate_source_files('src', '*.cxx')
env.Append( CPPPATH = [ os.path.abspath(p) for p in include_paths ] )
env.Append( CCFLAGS = [ '-isystem' + os.path.abspath(p) for p in isystem_paths ] )
# Determine all the build files
build_files = [build_dirname + '/' + src for src in sources]
shared_lib = env.SharedLibrary('lib/' + lib_name, build_files)
#static_lib = env.Library('lib/' + lib_name, build_files)
Default([shared_lib])
#Default([static_lib, shared_lib])