[1125] | 1 | import os |
---|
| 2 | import sys |
---|
[1082] | 3 | import distutils.sysconfig |
---|
| 4 | import platform |
---|
[1184] | 5 | import SCons |
---|
[1082] | 6 | |
---|
[1873] | 7 | # try to autodetect numpy |
---|
| 8 | def 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 | |
---|
[2166] | 24 | EnsureSConsVersion(1,0,0) |
---|
[1464] | 25 | |
---|
[2503] | 26 | opts = Variables("options.cache") |
---|
[1464] | 27 | opts.AddVariables( |
---|
[2505] | 28 | ("extraroot", "Addition tree to look for packages", None), |
---|
[1325] | 29 | ("FORTRAN", "The fortran compiler", None), |
---|
| 30 | ("f2clib", "The fortran to c library", None), |
---|
[1464] | 31 | PathVariable("casacoreroot", "The location of casacore", |
---|
[1740] | 32 | "/usr/local"), |
---|
[1325] | 33 | ("boostroot", "The root dir where boost is installed", None), |
---|
| 34 | ("boostlib", "The name of the boost python library", |
---|
| 35 | "boost_python"), |
---|
| 36 | ("boostlibdir", "The boost library location", None), |
---|
| 37 | ("boostincdir", "The boost header file location", None), |
---|
| 38 | ("lapackroot", |
---|
| 39 | "The root directory where lapack is installed", None), |
---|
| 40 | ("lapacklibdir", "The lapack library location", None), |
---|
| 41 | ("lapacklib", |
---|
| 42 | "The lapack library name (e.g. for specialized AMD libraries", |
---|
[1327] | 43 | "lapack"), |
---|
[1325] | 44 | ("blasroot", |
---|
| 45 | "The root directory where blas is installed", None), |
---|
| 46 | ("blaslibdir", "The blas library location", None), |
---|
| 47 | ("blaslib", |
---|
| 48 | "The blas library name (e.g. for specialized AMD libraries", |
---|
[1327] | 49 | "blas"), |
---|
[1325] | 50 | ("cfitsioroot", |
---|
| 51 | "The root directory where cfistio is installed", None), |
---|
| 52 | ("cfitsiolibdir", "The cfitsio library location", None), |
---|
[1327] | 53 | ("cfitsiolib", "The cfitsio library name", "cfitsio"), |
---|
[1325] | 54 | ("cfitsioincdir", "The cfitsio include location", None), |
---|
[1740] | 55 | ("wcslib", "The wcs library name", "wcs"), |
---|
[1325] | 56 | ("wcsroot", |
---|
| 57 | "The root directory where wcs is installed", None), |
---|
| 58 | ("wcslibdir", "The wcs library location", None), |
---|
[1354] | 59 | ("rpfitslib", "The rpfits library name", "rpfits"), |
---|
[1325] | 60 | ("rpfitsroot", |
---|
| 61 | "The root directory where rpfits is installed", None), |
---|
| 62 | ("rpfitslibdir", "The rpfits library location", None), |
---|
[2503] | 63 | |
---|
[1501] | 64 | ("pyraproot", "The root directory where libpyrap is installed", |
---|
| 65 | None), |
---|
[1873] | 66 | ("numpyincdir", "numpy header file directory", |
---|
| 67 | get_numpy_incdir()), |
---|
[2503] | 68 | BoolVariable("enable_pyrap", |
---|
| 69 | "Use pyrap conversion library from system", |
---|
| 70 | False), |
---|
[1501] | 71 | ("pyraplib", "The name of the pyrap library", "pyrap"), |
---|
| 72 | ("pyraplibdir", "The directory where libpyrap is installed", |
---|
| 73 | None), |
---|
| 74 | ("pyrapincdir", "The pyrap include location", |
---|
| 75 | None), |
---|
[1464] | 76 | EnumVariable("mode", "The type of build.", "release", |
---|
[1135] | 77 | ["release","debug"], ignorecase=1), |
---|
[2503] | 78 | EnumVariable("makedoc", |
---|
| 79 | "Build the userguide in specified format", |
---|
| 80 | "none", |
---|
| 81 | ["none", "pdf", "html"], ignorecase=1), |
---|
[1740] | 82 | BoolVariable("apps", "Build cpp apps", True), |
---|
[1501] | 83 | BoolVariable("alma", "Enable alma specific functionality", |
---|
| 84 | False), |
---|
[1130] | 85 | ) |
---|
[1082] | 86 | |
---|
[1135] | 87 | env = Environment( toolpath = ['./scons'], |
---|
[2505] | 88 | tools = ["default", "utils", "casa"], |
---|
[1135] | 89 | ENV = { 'PATH' : os.environ[ 'PATH' ], |
---|
[1120] | 90 | 'HOME' : os.environ[ 'HOME' ] }, |
---|
[1135] | 91 | options = opts) |
---|
[1082] | 92 | |
---|
[2503] | 93 | env.Help(opts.GenerateHelpText(env)) |
---|
[1120] | 94 | env.SConsignFile() |
---|
[2503] | 95 | if not ( env.GetOption('clean') or env.GetOption('help') ): |
---|
[1325] | 96 | |
---|
[1130] | 97 | conf = Configure(env) |
---|
[2505] | 98 | conf.env.AddCustomPackage('extra') |
---|
[1326] | 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) |
---|
[1443] | 104 | conf.env.PrependUnique(LIBS=["casa_images", "casa_ms", "casa_components", |
---|
[1354] | 105 | "casa_coordinates", "casa_lattices", |
---|
| 106 | "casa_fits", "casa_measures", "casa_scimath", |
---|
| 107 | "casa_scimath_f", "casa_tables", |
---|
| 108 | "casa_mirlib"]) |
---|
[1130] | 109 | conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()]) |
---|
| 110 | if not conf.CheckHeader("Python.h", language='c'): |
---|
| 111 | Exit(1) |
---|
[1325] | 112 | pylib = 'python'+distutils.sysconfig.get_python_version() |
---|
| 113 | if env['PLATFORM'] == "darwin": |
---|
| 114 | conf.env.Append(FRAMEWORKS=["Python"]) |
---|
[1130] | 115 | else: |
---|
[1325] | 116 | if not conf.CheckLib(library=pylib, language='c'): Exit(1) |
---|
| 117 | |
---|
| 118 | conf.env.AddCustomPackage('boost') |
---|
[1501] | 119 | if not conf.CheckLibWithHeader(conf.env["boostlib"], |
---|
[1325] | 120 | 'boost/python.hpp', language='c++'): |
---|
| 121 | Exit(1) |
---|
[1501] | 122 | |
---|
[2503] | 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) |
---|
[1873] | 129 | else: |
---|
| 130 | conf.env.AppendUnique(CPPPATH=[conf.env["numpyincdir"]]) |
---|
| 131 | # numpy 1.0 uses config.h; numpy >= 1.1 uses numpyconfig.h |
---|
[2503] | 132 | if conf.CheckHeader("numpy/numpyconfig.h"): |
---|
[1873] | 133 | conf.env.Append(CPPDEFINES=["-DAIPS_USENUMPY"]) |
---|
| 134 | else: |
---|
| 135 | conf.env.Exit(1) |
---|
[2503] | 136 | # compile in pyrap from here... |
---|
[1873] | 137 | conf.env["pyrapint"] = "#/external/libpyrap/pyrap-0.3.2" |
---|
[2503] | 138 | conf.env.Append(CPPFLAGS=['-DHAVE_LIBPYRAP']) |
---|
| 139 | |
---|
[1325] | 140 | # test for cfitsio |
---|
| 141 | if not conf.CheckLib("m"): Exit(1) |
---|
| 142 | conf.env.AddCustomPackage('cfitsio') |
---|
[1327] | 143 | if not conf.CheckLibWithHeader(conf.env["cfitsiolib"], |
---|
| 144 | 'fitsio.h', language='c'): |
---|
[1325] | 145 | Exit(1) |
---|
| 146 | conf.env.AddCustomPackage('wcs') |
---|
[1740] | 147 | if not conf.CheckLibWithHeader(conf.env["wcslib"], |
---|
| 148 | 'wcslib/wcs.h', language='c'): |
---|
[1325] | 149 | Exit(1) |
---|
| 150 | conf.env.AddCustomPackage('rpfits') |
---|
[1354] | 151 | if not conf.CheckLib(conf.env["rpfitslib"], language="c"): |
---|
| 152 | Exit(1) |
---|
[1325] | 153 | |
---|
| 154 | # test for blas/lapack |
---|
[1740] | 155 | lapackname = conf.env.get("lapacklib", "lapack") |
---|
[1331] | 156 | conf.env.AddCustomPackage("lapack") |
---|
[1740] | 157 | if not conf.CheckLib(lapackname): Exit(1) |
---|
[1325] | 158 | blasname = conf.env.get("blaslib", "blas") |
---|
| 159 | conf.env.AddCustomPackage("blas") |
---|
[1740] | 160 | if not conf.CheckLib(blasname): Exit(1) |
---|
[1325] | 161 | conf.env.CheckFortran(conf) |
---|
[1130] | 162 | if not conf.CheckLib('stdc++', language='c++'): Exit(1) |
---|
[1433] | 163 | if conf.env["alma"]: |
---|
[2485] | 164 | conf.env.Append(CPPFLAGS=['-DUSE_CASAPY']) |
---|
[1082] | 165 | env = conf.Finish() |
---|
[1120] | 166 | |
---|
[2503] | 167 | opts.Save('options.cache', env) |
---|
| 168 | |
---|
[2485] | 169 | env["version"] = "4.1.x" |
---|
[1135] | 170 | |
---|
[1120] | 171 | if env['mode'] == 'release': |
---|
[1335] | 172 | if env["PLATFORM"] != "darwin": |
---|
| 173 | env.Append(LINKFLAGS=['-Wl,-O1', '-s']) |
---|
| 174 | env.Append(CCFLAGS=["-O2"]) |
---|
| 175 | else: |
---|
[2179] | 176 | env.Append(CCFLAGS=["-g", "-W", "-Wall"]) |
---|
[1184] | 177 | |
---|
| 178 | # Export for SConscript files |
---|
[1135] | 179 | Export("env") |
---|
[1082] | 180 | |
---|
[1325] | 181 | # build externals |
---|
[2503] | 182 | ext = env.SConscript("external-alma/SConscript") |
---|
| 183 | |
---|
[1184] | 184 | # build library |
---|
[2179] | 185 | so = env.SConscript("src/SConscript", variant_dir="build", duplicate=0) |
---|
[2503] | 186 | |
---|
| 187 | apps = env.SConscript("apps/SConscript") |
---|
| 188 | |
---|
[1195] | 189 | # test module import, to see if there are unresolved symbols |
---|
| 190 | def 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 |
---|
[2503] | 197 | |
---|
[1195] | 198 | def test_str(target, source, env): |
---|
| 199 | return "Testing module..." |
---|
[1184] | 200 | |
---|
[1195] | 201 | taction = Action(test_module, test_str) |
---|
| 202 | env.AddPostAction(so, taction) |
---|
| 203 | |
---|
| 204 | if env.GetOption("clean"): |
---|
| 205 | Execute(Delete(".sconf_temp")) |
---|
[2503] | 206 | Execute(Delete("options.cache")) |
---|
[2166] | 207 | |
---|
| 208 | if env["makedoc"].lower() != "none": |
---|
| 209 | env.SConscript("doc/SConscript") |
---|