Skip to content

Commit 56bd6d2

Browse files
committed
Merge branch 'improve-build-script'
Improvements to the scons build script: - use separate scons environment for building the shared library. - simplify configuration of include and library compiler paths. - load configure script after setting compiler-related flags. - provide only test-related scons targets when test_installed=true. This fixes #9.
2 parents 2eb2d4d + b1881b1 commit 56bd6d2

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

.travis-sconscript.local

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env.Prepend(CCFLAGS='-isystem{}/include'.format(P))
1010

1111
# Define path to the shared libraries from Anaconda environment.
1212
L = P + '/lib'
13+
env.Append(LIBPATH=L)
1314
env.Append(LINKFLAGS='-Wl,-rpath,{!r}'.format(L))
1415

1516
# vim: ft=python

SConstruct

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def subdictionary(d, keyset):
2727

2828
# copy system environment variables related to compilation
2929
DefaultEnvironment(ENV=subdictionary(os.environ, '''
30-
PATH PYTHONPATH
31-
CPATH CPLUS_INCLUDE_PATH LIBRARY_PATH LD_RUN_PATH
30+
PATH CPATH CPLUS_INCLUDE_PATH LIBRARY_PATH LD_RUN_PATH
3231
LD_LIBRARY_PATH DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH
3332
MACOSX_DEPLOYMENT_TARGET
3433
'''.split())

conda-recipe/run_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
export CPATH="${PREFIX}/include:${CPATH}"
4+
export LIBRARY_PATH="${PREFIX}/lib:${LIBRARY_PATH}"
5+
36
MYNCPU=$(( (CPU_COUNT > 8) ? 8 : CPU_COUNT ))
47

58
# Apply sconscript.local customizations.

src/SConscript

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ Import('env')
88
flagnames = 'CFLAGS CXXFLAGS LDFLAGS'.split()
99
env.MergeFlags([os.environ.get(n, '') for n in flagnames])
1010

11-
# The directory of this SConscript should be searched first for any headers.
12-
env.PrependUnique(CPPPATH=Dir('.'))
13-
1411
# Insert LIBRARY_PATH explicitly because some compilers
1512
# ignore it in the system environment.
1613
env.PrependUnique(LIBPATH=env['ENV'].get('LIBRARY_PATH', '').split(':'))
@@ -24,11 +21,6 @@ if env['tool'] == 'intelc':
2421
Exit(1)
2522
env.Tool('intelc', topdir=icpc[:icpc.rfind('/bin')])
2623

27-
# Declare external libraries.
28-
env.ParseConfig("gsl-config --cflags --libs")
29-
# dladdr in runtimepath.cpp requires the dl library.
30-
env.AppendUnique(LIBS=['dl'])
31-
3224
fast_linkflags = ['-s']
3325

3426
# Platform specific intricacies.
@@ -38,15 +30,6 @@ if env['PLATFORM'] == 'darwin':
3830
env.AppendUnique(SHLINKFLAGS='-headerpad_max_install_names')
3931
fast_linkflags[:] = []
4032

41-
# configure version specific options.
42-
skip_configure = (GetOption('clean') or GetOption('help') or
43-
(['sdist'] == list(COMMAND_LINE_TARGETS)))
44-
if not skip_configure:
45-
SConscript('SConscript.configure')
46-
elif GetOption('clean'):
47-
# make sure ObjCryst files will be also cleaned
48-
env['has_objcryst'] = True
49-
5033
# Compiler specific options
5134
if icpc:
5235
# options for Intel C++ compiler on hpc dev-intel07
@@ -74,22 +57,41 @@ if env['coverage']:
7457
env.Append(CCFLAGS=['--coverage', '-O0'])
7558
env.Append(LINKFLAGS='--coverage')
7659

60+
# configure boost and ObjCryst libraries unless non-relevant.
61+
skip_configure = (GetOption('clean') or GetOption('help') or
62+
(['sdist'] == list(COMMAND_LINE_TARGETS)))
63+
if not skip_configure:
64+
SConscript('SConscript.configure')
65+
66+
# when cleaning make sure to also purge ObjCryst files
67+
if GetOption('clean'):
68+
env['has_objcryst'] = True
69+
7770
# Define lists for storing library source and include files.
7871
env['lib_includes'] = []
7972
env['lib_sources'] = []
8073
env['lib_datafiles'] = []
8174

8275
# Subsidiary SConscripts -----------------------------------------------------
8376

84-
# Determine if unit tests need to be built.
85-
build_tests = set(('test', 'alltests')).intersection(COMMAND_LINE_TARGETS)
77+
# The targets that concern unit tests.
78+
targets_that_test = set(('test', 'alltests'))
8679

8780
# Short circuit if we test an already installed library. Do not define
8881
# any further targets as they may conflict with the installed files.
89-
if build_tests and env['test_installed']:
82+
if env['test_installed']:
9083
SConscript('tests/SConscript')
84+
if not targets_that_test.issuperset(COMMAND_LINE_TARGETS):
85+
print('Warning: only test targets are available when '
86+
'"test_installed=True".')
9187
Return()
9288

89+
assert not env['test_installed']
90+
91+
# Here we do not test the installed library. Any diffpy headers
92+
# should thus be looked up from our source tree.
93+
env.PrependUnique(CPPPATH=Dir('.'))
94+
9395
# Load the version script first to resolve the majorminor tuple
9496
SConscript('diffpy/SConscript.version')
9597

@@ -110,15 +112,22 @@ if 'sdist' in COMMAND_LINE_TARGETS:
110112
# Top Level Targets ----------------------------------------------------------
111113

112114
# lib -- shared library object
113-
libdiffpy = env.SharedLibrary('diffpy', env['lib_sources'])
115+
116+
# use new environment with extra libraries needed for libdiffpy.
117+
env_lib = env.Clone()
118+
# Setup GSL, the GNU Scientific library.
119+
env_lib.ParseConfig("gsl-config --cflags --libs")
120+
# The dladdr call in runtimepath.cpp requires the dl library.
121+
env_lib.AppendUnique(LIBS=['dl'])
122+
123+
libdiffpy = env_lib.SharedLibrary('diffpy', env['lib_sources'])
114124
Export('libdiffpy')
115125
lib = Alias('lib', [libdiffpy, env['lib_includes']])
116126
Default(lib)
117127

118128
# Define targets related to testing. Do so only when testing is requested.
119129
# This enables library build on machines without cxxtest.
120-
if build_tests:
121-
assert not env['test_installed']
130+
if targets_that_test.intersection(COMMAND_LINE_TARGETS):
122131
SConscript('tests/SConscript')
123132

124133
# Installation targets.

src/tests/SConscript

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ env_test.Tool('cxxtest')
99

1010
if env['test_installed']:
1111
# build unit tests for the installed library
12-
env_test['CPPPATH'].remove(Dir('..'))
1312
env_test.PrependUnique(CPPPATH=env['includedir'], delete_existing=1)
1413
lib_dir = env['libdir']
1514
else:
@@ -21,11 +20,6 @@ use_our_library = not env['test_installed']
2120
env_test.PrependUnique(LIBS='diffpy', LIBPATH=lib_dir, delete_existing=1)
2221
env_test.PrependUnique(LINKFLAGS="-Wl,-rpath,%r" % lib_dir)
2322

24-
# Use only libraries needed for building the unit tests.
25-
pat = 'diffpy|boost_serialization|ObjCryst'
26-
keeplibs = lambda s: re.search(pat, str(s))
27-
env_test.Replace(LIBS=filter(keeplibs, env_test['LIBS']))
28-
2923
# Targets --------------------------------------------------------------------
3024

3125
def srcsupported(f):

0 commit comments

Comments
 (0)