-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathSConscript
204 lines (165 loc) · 7.21 KB
/
SConscript
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import os
import platform
Import('env')
# Build environment configuration --------------------------------------------
# Insert LIBRARY_PATH explicitly because some compilers
# ignore it in the system environment.
env.PrependUnique(LIBPATH=env['ENV'].get('LIBRARY_PATH', '').split(':'))
# Use Intel C++ compiler if requested by the user.
icpc = None
if env['tool'] == 'intelc':
icpc = env.WhereIs('icpc')
if not icpc:
print("Cannot find the Intel C/C++ compiler 'icpc'.")
Exit(1)
env.Tool('intelc', topdir=icpc[:icpc.rfind('/bin')])
fast_linkflags = ['-s']
# Specify minimum C++ standard. Allow later standard from sconscript.local.
# In case of multiple `-std` options the last option holds.
# Platform specific intricacies.
if env['PLATFORM'] == 'darwin':
env.AppendUnique(CXXFLAGS='-ftemplate-depth-256')
env.Append(SHLINKFLAGS=['-install_name', '$TARGET.abspath'])
env.AppendUnique(SHLINKFLAGS='-headerpad_max_install_names')
fast_linkflags[:] = []
# Compiler specific options
if platform.system().lower() == "windows":
# Visual c++
env.PrependUnique(CCFLAGS=['/Ox', '/EHsc', '/MD', '/std:c++14', '/Wall'])
env.AppendUnique(CPPDEFINES={'NDEBUG': None})
env.AppendUnique(LINKFLAGS=['/OPT:NOREF', '/OPT:NOICF', '/WHOLEARCHIVE:diffpy.lib'])
# env.AppendUnique(LINKFLAGS='/EXPORT')
else:
env.PrependUnique(CXXFLAGS='-std=c++11')
if icpc:
# options for Intel C++ compiler on hpc dev-intel07
env.PrependUnique(CCFLAGS=['-w1', '-fp-model', 'precise'])
env.PrependUnique(LIBS=['imf'])
fast_optimflags = ['-fast', '-no-ipo']
else:
# g++ options
env.PrependUnique(CCFLAGS=['-Wall'])
fast_optimflags = ['-ffast-math']
# Configure build variants
if env['build'] == 'debug':
env.Append(CCFLAGS='-g')
elif env['build'] == 'coverage':
env.CacheDir(None)
env.Append(CCFLAGS=['-g', '--coverage', '-O0'])
env.Append(LINKFLAGS='--coverage')
elif env['build'] == 'fast':
env.AppendUnique(CCFLAGS=['-O3'] + fast_optimflags)
env.AppendUnique(CPPDEFINES={'NDEBUG' : None})
env.AppendUnique(LINKFLAGS=fast_linkflags)
if env['profile']:
env.AppendUnique(CCFLAGS='-pg')
env.AppendUnique(LINKFLAGS='-pg')
# configure boost and ObjCryst libraries unless non-relevant.
skip_configure = (GetOption('clean') or GetOption('help') or
(['sdist'] == list(COMMAND_LINE_TARGETS)))
if not skip_configure:
SConscript('SConscript.configure')
# when cleaning make sure to also purge ObjCryst files
if GetOption('clean'):
env['has_objcryst'] = True
# Define lists for storing library source and include files.
env['lib_includes'] = []
env['lib_sources'] = []
env['lib_datafiles'] = []
# Subsidiary SConscripts -----------------------------------------------------
# The targets that concern unit tests.
targets_that_test = set(('test', 'alltests'))
# Short circuit if we test an already installed library. Do not define
# any further targets as they may conflict with the installed files.
if env['test_installed']:
SConscript('tests/SConscript')
if not targets_that_test.issuperset(COMMAND_LINE_TARGETS):
print('Warning: only test targets are available when '
'"test_installed=True".')
Return()
assert not env['test_installed']
# Here we do not test the installed library. Any diffpy headers
# should thus be looked up from our source tree.
env.PrependUnique(CPPPATH=Dir('.'))
# Load the version script first to resolve the majorminor tuple
SConscript('diffpy/SConscript.version')
# Path where datafiles should be installed
env['runtimepath'] = os.path.join(
env['datadir'], 'diffpy/libdiffpy-%i.%i' % env['majorminor'])
SConscript('runtime/SConscript')
# Load all other sconscripts that update lib_includes and lib_sources
SConscript('diffpy/SConscript')
# Define sdist target for creating source distribution bundle
# Do so only if required to avoid extra git executions.
# Note: See .gitattributes for files excluded from sdist.
if 'sdist' in COMMAND_LINE_TARGETS:
SConscript('SConscript.sdist')
# Top Level Targets ----------------------------------------------------------
# lib -- shared library object
# use new environment with extra libraries needed for libdiffpy.
env_lib = env.Clone()
# Setup GSL, the GNU Scientific library.
# The dladdr call in runtimepath.cpp requires the dl library.
env_lib.AppendUnique(LIBS=['dl', 'gsl', 'gslcblas'])
if platform.system().lower() == "windows":
# Use a static library (does not require __declspec(dllexport) all over the code)
libdiffpy = env_lib.StaticLibrary('diffpy', env['lib_sources'])
else:
libdiffpy = env_lib.SharedLibrary('diffpy', env['lib_sources'])
# Clean up .gcda and .gcno files from coverage analysis.
env_lib.Clean(libdiffpy, Glob('diffpy/*.gc??'))
env_lib.Clean(libdiffpy, Glob('diffpy/srreal/*.gc??'))
env_lib.Depends(libdiffpy, env['lib_includes'])
Export('libdiffpy')
lib = Alias('lib', [libdiffpy])
Default(lib)
# Define targets related to testing. Do so only when testing is requested.
# This enables library build on machines without cxxtest.
if targets_that_test.intersection(COMMAND_LINE_TARGETS):
SConscript('tests/SConscript')
# Installation targets.
prefix = env['prefix']
# install-lib
install_lib = env.Install(env['libdir'], libdiffpy)
if env['PLATFORM'] == 'darwin':
# DARWIN_INSTALL_NAME can be pre-set in sconscript.local
env.SetDefault(DARWIN_INSTALL_NAME='$TARGET.abspath')
env.AddPostAction(install_lib,
'install_name_tool -id $DARWIN_INSTALL_NAME $TARGET')
if env['PLATFORM'] == 'posix' and WhereIs('ldconfig'):
opts = '' if os.getuid() == 0 else '-n'
env.AddPostAction(install_lib,
'ldconfig %s $TARGET.dir' % opts)
Alias('install-lib', install_lib)
# install-include
ninc = len(Dir('.').path) + 1
inc_target_path = lambda f: os.path.join(env['includedir'], f.path[ninc:])
include_targets = [inc_target_path(f) for f in env['lib_includes']]
install_include = InstallAs(include_targets, env['lib_includes'])
Alias('install-include', install_include)
# install-data
nrt = len(Dir('runtime').path) + 1
data_target_path = lambda f: os.path.join(env['runtimepath'], f.path[nrt:])
data_targets = [data_target_path(f) for f in env['lib_datafiles']]
install_data = InstallAs(data_targets, env['lib_datafiles'])
Alias('install-data', install_data)
# install
Alias('install', ['install-lib', 'install-include', 'install-data'])
# do not install headers and data when shared library cannot be installed.
if 'install' in COMMAND_LINE_TARGETS:
Requires(install_include, install_lib)
Requires(install_data, install_lib)
# Coverage related targets.
# zerocounters
cdatadirs = ['diffpy', 'diffpy/srreal', 'tests']
cdatafiles = [f for d in cdatadirs for f in Glob(d + '/*.gcda')]
zerocounters = Alias('zerocounters', [], [Delete(f) for f in cdatafiles])
Ignore(cdatadirs, cdatafiles)
AlwaysBuild(zerocounters)
# when both 'test' and 'zerocounters' are requested, make sure
# to build them in correct order.
require_ordered_targets = ('test' in COMMAND_LINE_TARGETS and
'zerocounters' in COMMAND_LINE_TARGETS)
if require_ordered_targets:
Depends('test', zerocounters)
# vim: ft=python