source: trunk/SConstruct @ 2503

Last change on this file since 2503 was 2503, checked in by Malte Marquarding, 12 years ago

remove install related stuff from scons. We use python distutils for installing

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