-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
181 lines (153 loc) · 7.58 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
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
# -*- mode:python; coding:utf-8; -*-
# Aeryn2 -- a unit test framework for C++.
#
# Copyright © 2005, 2007–2009, 2012 Russel Winder
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
import os.path
import platform
import re
try:
versionNumber = file('VERSION').readline().strip()
except:
print 'Version file not present, build will not be undertaken.'
Exit(1)
# Support concurrent builds for different platforms in the same tree (i.e. shared fielstore) by creating a
# discrminator that is used to provide platform specific names for the build directory and the SCons
# control files. This does not provide for concurrent builds using the same platform of course.
unameResult = platform.uname()
osName = unameResult[0]
archName = re.sub('i.86', 'ix86', unameResult[4].replace('sun4u', 'sparc'))
discriminator = '_' + osName + '_' + archName
# The project directory structure.
coreSrcDir = 'src'
incSrcDir = 'include'
testsSrcDir = 'aeryntests'
testrunnerSrcDir = 'testrunner'
mainSrcDir = os.path.join('extras', 'mainlib')
testrunner2SrcDir = os.path.join('extras', 'testrunner2')
buildDir = 'build' + discriminator
buildBinDir = os.path.join(buildDir, 'bin')
buildLibDir = os.path.join(buildDir, 'lib')
# Deduce the installation locations. There is a default. This can be overridden using environment
# variables. This can be overwritten using the content of a file in the current directory. This can be
# overwritten using command line arguments.
defaultPrefix = '/usr/local'
defaultInstallIncDirSubdirectory = 'include'
defaultInstallLibDirSubdirectory = 'lib'
defaultInstallIncDir = os.path.join(defaultPrefix, defaultInstallIncDirSubdirectory)
defaultInstallLibDir = os.path.join(defaultPrefix, defaultInstallLibDirSubdirectory)
prefix = defaultPrefix
installIncDir = defaultInstallIncDir
installLibDir = defaultInstallLibDir
if 'PREFIX' in os.environ:
prefix = os.environ['PREFIX']
installIncDir = os.path.join(prefix, defaultInstallIncDirSubdirectory)
installLibDir = os.path.join(prefix, defaultInstallLibDirSubdirectory)
if 'INCDIR' in os.environ:
installIncDir = os.environ['INCDIR']
if 'LIBDIR' in os.environ:
installLibDir = os.environ['LIBDIR']
defaultPrefix = prefix
defaultInstallIncDir = installIncDir
defaultInstallLibDir = installLibDir
localBuildOptions = 'local.build.options'
if os.access(localBuildOptions, os.R_OK):
execfile(localBuildOptions)
if prefix != defaultPrefix:
if installIncDir == defaultInstallIncDir:
installIncDir = os.path.join(prefix, defaultInstallIncDirSubdirectory)
if installLibDir == defaultInstallLibDir:
installLibDir = os.path.join(prefix, defaultInstallLibDirSubdirectory)
if 'prefix' in ARGUMENTS:
prefix = ARGUMENTS.get('prefix')
installIncDir = os.path.join(prefix, defaultInstallIncDirSubdirectory)
installLibDir = os.path.join(prefix, defaultInstallLibDirSubdirectory)
installIncDir = ARGUMENTS.get('installIncDir', installIncDir)
installLibDir = ARGUMENTS.get('installLibDir', installLibDir)
env = Environment(
CXXFLAGS=['-W', '-Wall', '-Werror', '-pedantic', '-Wcast-qual', '-Wcast-align', '-Wwrite-strings', '-Winline', '-finline-limit=1048576', '-g3', '-DNO_OUTPUT_OPERATOR_DETECTION'],
CPPPATH=['#' + incSrcDir],
SHLIBVERSION=versionNumber,
)
env.SConsignFile('.sconsign' + discriminator)
Export('env')
def constructLibraryDependencies(libraryName):
'''
Create all the necessary constructions to make the static and dynamic libraries.
Return a tuple containing the build product list and the install product list.
'''
# This will be called in subdirectories so ensure all paths are given # prefixes.
librarySource = Glob('*.cpp')
buildProducts = []
installProducts = []
staticLibrary = env.StaticLibrary(os.path.join('#' + buildLibDir, libraryName), librarySource)
buildProducts += [staticLibrary]
installProducts += [staticLibrary]
# Linux appears to deliver posix as the platform.
if env['PLATFORM'] in ['sunos', 'posix']:
sharedLibrary = env.SharedLibrary(os.path.join('#' + buildLibDir, libraryName), librarySource)
buildProducts += [sharedLibrary]
installProducts += [sharedLibrary]
elif env['PLATFORM'] == 'darwin':
env.Append(SHLINKFLAGS='-undefined dynamic_lookup')
#sharedLibrary = env.SharedLibrary(os.path.join('#' + buildLibDir, libraryName), librarySource)
sharedLibrary = env.SharedLibrary(os.path.join('#' + buildLibDir, libraryName), librarySource)
buildProducts += [sharedLibrary]
installProducts += [sharedLibrary]
elif env['PLATFORM'] in ['win32', 'cygwin']:
pass # For the moment ignore shared libraries on Windows.
else:
raise ValueError("PLATFORM had value " + env['PLATFORM'] + " which is not catered for.")
return(buildProducts, installProducts)
env['ConstructLibraryDependencies'] = constructLibraryDependencies
def constructExecutableDependencies(name, sources, libraries):
'''
Create all the necessary constructions to make the executables used for testing.
Return the list of build products.
'''
# This will be called in subdirectories so ensure all paths are given # prefixes.
return env.Program(os.path.join('#' + buildBinDir, name), sources, LIBPATH='#' + buildLibDir, LIBS=libraries)
env['ConstructExecutableDependencies'] = constructExecutableDependencies
(buildProducts, installProducts) = SConscript(os.path.join(coreSrcDir, 'SConscript'), variant_dir=os.path.join(buildDir, coreSrcDir), duplicate=0)
Alias('build', buildProducts)
testBuildProducts = \
SConscript(os.path.join(mainSrcDir, 'SConscript'), variant_dir=os.path.join(buildDir, mainSrcDir), duplicate=0) \
+ SConscript(os.path.join(testsSrcDir, 'SConscript'), variant_dir=os.path.join(buildDir, testsSrcDir), duplicate=0)
testExecuteProducts = \
SConscript(os.path.join(testrunnerSrcDir, 'SConscript'), variant_dir=os.path.join(buildDir, testrunnerSrcDir), duplicate=0) \
+ SConscript(os.path.join(testrunner2SrcDir, 'SConscript'), variant_dir=os.path.join(buildDir, testrunner2SrcDir), duplicate=0)
Alias('buildTests', [buildProducts, testBuildProducts, testExecuteProducts])
if env['PLATFORM'] in ['sunos', 'posix']:
commandPrefix = 'LD_LIBRARY_PATH=' + buildLibDir
elif env['PLATFORM'] == 'darwin':
commandPrefix = 'DYLD_LIBRARY_PATH=' + buildLibDir
elif env['PLATFORM'] in ['win32', 'cygwin']:
commandPrefix = ''
else:
raise ValueError("PLATFORM had value " + env['PLATFORM'] + " which is not catered for.")
Command('runTests', 'buildTests', [commandPrefix + ' ' + item.abspath for item in testExecuteProducts])
Alias('installWithoutTesting',
[Install(os.path.join(installIncDir, '..', root), os.path.join(root, f)) for root, dirs, files in os.walk(incSrcDir) for f in files] +
[Install(installLibDir, installProducts)])
Alias('install', ['runTests', 'installWithoutTesting'])
Clean('.', [buildDir])
Default('runTests')
Help('''
The possible targets are:
build
buildTests
runTests
install
installWithoutTesting
The default target is test.
''')