source: branches/hpc34/SConstruct@ 2703

Last change on this file since 2703 was 2580, checked in by ShinnosukeKawakami, 12 years ago

hpc33 merged asap-trunk

File size: 9.3 KB
Line 
1import os
2import sys
3import distutils.sysconfig
4import platform
5import SCons
6
7# try to autodetect numpy
8def get_numpy_incdir():
9 try:
10 # try to find an egg
11 from pkg_resources import require
12 tmp = require("numpy")
13 import numpy
14 return numpy.__path__[0]+"/core/include"
15 except Exception:
16 # now try standard package
17 try:
18 import numpy
19 return numpy.__path__[0]+"/core/include"
20 except ImportError:
21 pass
22 return ""
23
24def get_libdir():
25 return os.path.basename(distutils.sysconfig.get_config_var('LIBDIR'))
26
27LIBDIR = 'lib' #get_libdir()
28
29EnsureSConsVersion(1,0,0)
30
31opts = Variables("options.cache")
32opts.AddVariables(
33 ("extraroot", "Addition tree to look for packages", None),
34 ("extraflags", "Additional build flags", None),
35 ("FORTRAN", "The fortran compiler", None),
36 ("f2clib", "The fortran to c library", None),
37 PathVariable("casacoreroot", "The location of casacore",
38 "/usr/local"),
39 BoolVariable("casacorestatic",
40 "Link statically against casacore",
41 False),
42 ("boostroot", "The root dir where boost is installed", None),
43 ("boostlib", "The name of the boost python library",
44 "boost_python"),
45 ("boostlibdir", "The boost library location", None),
46 ("boostincdir", "The boost header file location", None),
47 ("lapackroot",
48 "The root directory where lapack is installed", None),
49 ("lapacklibdir", "The lapack library location", None),
50 ("lapacklib",
51 "The lapack library name (e.g. for specialized AMD libraries",
52 "lapack"),
53 ("blasroot",
54 "The root directory where blas is installed", None),
55 ("blaslibdir", "The blas library location", None),
56 ("blaslib",
57 "The blas library name (e.g. for specialized AMD libraries",
58 "blas"),
59 ("cfitsioroot",
60 "The root directory where cfistio is installed", None),
61 ("cfitsiolibdir", "The cfitsio library location", None),
62 ("cfitsiolib", "The cfitsio library name", "cfitsio"),
63 ("cfitsioincdir", "The cfitsio include location", None),
64 ("wcslib", "The wcs library name", "wcs"),
65 ("wcsroot",
66 "The root directory where wcs is installed", None),
67 ("wcslibdir", "The wcs library location", None),
68 ("rpfitslib", "The rpfits library name", "rpfits"),
69 ("rpfitsroot",
70 "The root directory where rpfits is installed", None),
71 ("rpfitslibdir", "The rpfits library location", None),
72
73 ("pyraproot", "The root directory where libpyrap is installed",
74 None),
75 ("numpyincdir", "numpy header file directory",
76 get_numpy_incdir()),
77 BoolVariable("enable_pyrap",
78 "Use pyrap conversion library from system",
79 False),
80 ("pyraplib", "The name of the pyrap library", "pyrap"),
81 ("pyraplibdir", "The directory where libpyrap is installed",
82 None),
83 ("pyrapincdir", "The pyrap include location",
84 None),
85 EnumVariable("mode", "The type of build.", "release",
86 ["release","debug"], ignorecase=1),
87 EnumVariable("makedoc",
88 "Build the userguide in specified format",
89 "none",
90 ["none", "pdf", "html"], ignorecase=1),
91 BoolVariable("apps", "Build cpp apps", True),
92 BoolVariable("alma", "Enable alma specific functionality",
93 False),
94 )
95
96env = Environment( toolpath = ['./scons'],
97 tools = ["default", "utils", "casa"],
98 ENV = { 'PATH' : os.environ[ 'PATH' ],
99 'HOME' : os.environ[ 'HOME' ] },
100 options = opts)
101
102env.Help(opts.GenerateHelpText(env))
103env.SConsignFile()
104if not ( env.GetOption('clean') or env.GetOption('help') ):
105
106 conf = Configure(env)
107 if conf.env.get("extraroot", None):
108 conf.env.AddCustomPackage('extra')
109 conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])
110 if not conf.CheckHeader("Python.h", language='c'):
111 Exit(1)
112 pylib = 'python'+distutils.sysconfig.get_python_version()
113 if env['PLATFORM'] == "darwin":
114 conf.env.Append(FRAMEWORKS=["Python"])
115 else:
116 if not conf.CheckLib(library=pylib, language='c'): Exit(1)
117
118 conf.env.AddCustomPackage('boost')
119 libname = conf.env["boostlib"]
120 if libname.find(".") > -1 and os.path.exists(libname):
121 conf.env.AppendUnique(LIBS=[env.File(libname)])
122 else:
123 if not conf.CheckLibWithHeader(libname,
124 'boost/python.hpp', language='c++'):
125 Exit(1)
126
127 if env["enable_pyrap"]:
128 conf.env.AddCustomPackage('pyrap')
129 if conf.CheckLib(conf.env["pyraplib"], language='c++', autoadd=0):
130 conf.env.PrependUnique(LIBS=env['pyraplib'])
131 else:
132 Exit(1)
133 else:
134 conf.env.AppendUnique(CPPPATH=[conf.env["numpyincdir"]])
135 if conf.CheckHeader("numpy/numpyconfig.h"):
136 conf.env.Append(CPPDEFINES=["-DAIPS_USENUMPY"])
137 else:
138 conf.env.Exit(1)
139 # compile in pyrap from here...
140 conf.env["pyrapint"] = "#/external/libpyrap/pyrap-0.3.2"
141 conf.env.Append(CPPFLAGS=['-DHAVE_LIBPYRAP'])
142
143 if not conf.CheckLib("m"):
144 Exit(1)
145 # test for cfitsio
146 conf.env.AddCustomPackage('cfitsio')
147 libname = conf.env["cfitsiolib"]
148 if not conf.CheckHeader("fitsio.h"):
149 #SuSE is being special
150 conf.env.AppendUnique(CPPPATH=['/usr/include/libcfitsio0'])
151 if not conf.CheckHeader("fitsio.h"):
152 Exit(1)
153 if libname.find(".") > -1 and os.path.exists(libname):
154 conf.env.AppendUnique(LIBS=[env.File(libname)])
155 else:
156 if not conf.CheckLib(libname, language='c'):
157 Exit(1)
158 conf.env.AddCustomPackage('wcs')
159 libname = conf.env["wcslib"]
160 if libname.find(".") > -1 and os.path.exists(libname):
161 conf.env.AppendUnique(LIBS=[env.File(libname)])
162 else:
163 if not conf.CheckLibWithHeader(libname,
164 'wcslib/wcs.h', language='c'):
165 Exit(1)
166
167 conf.env.AddCustomPackage('rpfits')
168 if not conf.CheckLibWithHeader(conf.env["rpfitslib"], "RPFITS.h",
169 language="c"):
170 Exit(1)
171
172 libpath = ""
173 for p in [conf.env["casacoreroot"], conf.env.get("extraroot", "")]:
174 pth = os.path.join(p, "include", "casacore")
175 if os.path.exists(pth):
176 libpth = os.path.join(p, LIBDIR)
177 conf.env.AppendUnique(CPPPATH=[pth])
178 break
179 cclibs = ["casa_images", "casa_ms", "casa_components",
180 "casa_coordinates", "casa_lattices",
181 "casa_fits", "casa_measures", "casa_scimath",
182 "casa_scimath_f", "casa_tables", "casa_casa"]
183 if conf.env["casacorestatic"]:
184 libs = [ env.File(os.path.join(libpth, "lib"+lib+".a")) \
185 for lib in cclibs ]
186 else:
187 conf.env.AppendUnique(LIBPATH=libpth)
188 if not conf.CheckLibWithHeader("casa_casa", "casa/aips.h",
189 language='c++', autoadd=0):
190 Exit(1)
191 libs = cclibs
192 conf.env.PrependUnique(LIBS=libs)
193
194 # test for blas/lapack
195 conf.env.AddCustomPackage("lapack")
196 libname = conf.env.get("lapacklib", "lapack")
197 if libname.find(".") > -1 and os.path.exists(libname):
198 conf.env.AppendUnique(LIBS=[env.File(libname)])
199 else:
200 if not conf.CheckLib(libname): Exit(1)
201 libname = conf.env.get("blaslib", "blas")
202 if libname.find(".") > -1 and os.path.exists(libname):
203 conf.env.AppendUnique(LIBS=[env.File(libname)])
204 else:
205 if not conf.CheckLib(libname): Exit(1)
206
207 libname = conf.env.get("f2clib", "gfortran")
208 if libname.find(".") > -1 and os.path.exists(libname):
209 conf.env.AppendUnique(LIBS=[env.File(libname)])
210 else:
211 conf.env.CheckFortran(conf)
212 if not conf.CheckLib('stdc++', language='c++'): Exit(1)
213 if conf.env["alma"]:
214 conf.env.Append(CPPFLAGS=['-DUSE_CASAPY'])
215 if conf.env.get("extraflags"):
216 flags = conf.env.ParseFlags(conf.env["extraflags"])
217 conf.env.MergeFlags(flags)
218 env = conf.Finish()
219
220opts.Save('options.cache', env)
221
222env["version"] = "4.1.x"
223
224if env['mode'] == 'release':
225 if env["PLATFORM"] != "darwin":
226 env.Append(LINKFLAGS=['-Wl,-O1', '-s'])
227 env.Append(CCFLAGS=["-O2"])
228else:
229 env.Append(CCFLAGS=["-g", "-W", "-Wall"])
230
231# Export for SConscript files
232Export("env")
233
234# build externals
235ext = env.SConscript("external-alma/SConscript")
236
237# build library
238so = env.SConscript("src/SConscript", variant_dir="build", duplicate=0)
239
240apps = env.SConscript("apps/SConscript")
241
242# test module import, to see if there are unresolved symbols
243def test_module(target,source,env):
244 pth = str(target[0])
245 mod = os.path.splitext(pth)[0]
246 sys.path.insert(2, os.path.split(mod)[0])
247 __import__(os.path.split(mod)[1])
248 print "ok"
249 return 0
250
251def test_str(target, source, env):
252 return "Testing module..."
253
254taction = Action(test_module, test_str)
255env.AddPostAction(so, taction)
256
257if env.GetOption("clean"):
258 Execute(Delete(".sconf_temp"))
259 Execute(Delete("options.cache"))
260
261if env["makedoc"].lower() != "none":
262 env.SConscript("doc/SConscript")
Note: See TracBrowser for help on using the repository browser.