source: trunk/SConstruct@ 2509

Last change on this file since 2509 was 2507, checked in by Malte Marquarding, 13 years ago

fix extraroot env entry

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