[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 |
|
---|
[2517] | 24 | def get_libdir():
|
---|
| 25 | return os.path.basename(distutils.sysconfig.get_config_var('LIBDIR'))
|
---|
| 26 |
|
---|
[2518] | 27 | LIBDIR = 'lib' #get_libdir()
|
---|
[2517] | 28 |
|
---|
[2166] | 29 | EnsureSConsVersion(1,0,0)
|
---|
[1464] | 30 |
|
---|
[2503] | 31 | opts = Variables("options.cache")
|
---|
[1464] | 32 | opts.AddVariables(
|
---|
[2505] | 33 | ("extraroot", "Addition tree to look for packages", None),
|
---|
[2525] | 34 | ("extraflags", "Additional build flags", None),
|
---|
[1464] | 35 | PathVariable("casacoreroot", "The location of casacore",
|
---|
[1740] | 36 | "/usr/local"),
|
---|
[2506] | 37 | BoolVariable("casacorestatic",
|
---|
| 38 | "Link statically against casacore",
|
---|
| 39 | False),
|
---|
[1325] | 40 | ("boostroot", "The root dir where boost is installed", None),
|
---|
| 41 | ("boostlib", "The name of the boost python library",
|
---|
| 42 | "boost_python"),
|
---|
| 43 | ("boostlibdir", "The boost library location", None),
|
---|
| 44 | ("boostincdir", "The boost header file location", None),
|
---|
| 45 | ("cfitsioroot",
|
---|
| 46 | "The root directory where cfistio is installed", None),
|
---|
| 47 | ("cfitsiolibdir", "The cfitsio library location", None),
|
---|
[1327] | 48 | ("cfitsiolib", "The cfitsio library name", "cfitsio"),
|
---|
[1325] | 49 | ("cfitsioincdir", "The cfitsio include location", None),
|
---|
[1354] | 50 | ("rpfitslib", "The rpfits library name", "rpfits"),
|
---|
[1325] | 51 | ("rpfitsroot",
|
---|
| 52 | "The root directory where rpfits is installed", None),
|
---|
| 53 | ("rpfitslibdir", "The rpfits library location", None),
|
---|
[2503] | 54 |
|
---|
[1501] | 55 | ("pyraproot", "The root directory where libpyrap is installed",
|
---|
| 56 | None),
|
---|
[1873] | 57 | ("numpyincdir", "numpy header file directory",
|
---|
| 58 | get_numpy_incdir()),
|
---|
[2503] | 59 | BoolVariable("enable_pyrap",
|
---|
| 60 | "Use pyrap conversion library from system",
|
---|
| 61 | False),
|
---|
[1501] | 62 | ("pyraplib", "The name of the pyrap library", "pyrap"),
|
---|
| 63 | ("pyraplibdir", "The directory where libpyrap is installed",
|
---|
| 64 | None),
|
---|
| 65 | ("pyrapincdir", "The pyrap include location",
|
---|
| 66 | None),
|
---|
[1464] | 67 | EnumVariable("mode", "The type of build.", "release",
|
---|
[1135] | 68 | ["release","debug"], ignorecase=1),
|
---|
[2503] | 69 | EnumVariable("makedoc",
|
---|
| 70 | "Build the userguide in specified format",
|
---|
| 71 | "none",
|
---|
| 72 | ["none", "pdf", "html"], ignorecase=1),
|
---|
[1740] | 73 | BoolVariable("apps", "Build cpp apps", True),
|
---|
[1501] | 74 | BoolVariable("alma", "Enable alma specific functionality",
|
---|
| 75 | False),
|
---|
[1130] | 76 | )
|
---|
[1082] | 77 |
|
---|
[1135] | 78 | env = Environment( toolpath = ['./scons'],
|
---|
[2505] | 79 | tools = ["default", "utils", "casa"],
|
---|
[1135] | 80 | ENV = { 'PATH' : os.environ[ 'PATH' ],
|
---|
[1120] | 81 | 'HOME' : os.environ[ 'HOME' ] },
|
---|
[1135] | 82 | options = opts)
|
---|
[1082] | 83 |
|
---|
[2503] | 84 | env.Help(opts.GenerateHelpText(env))
|
---|
[1120] | 85 | env.SConsignFile()
|
---|
[2503] | 86 | if not ( env.GetOption('clean') or env.GetOption('help') ):
|
---|
[1325] | 87 |
|
---|
[1130] | 88 | conf = Configure(env)
|
---|
[2507] | 89 | if conf.env.get("extraroot", None):
|
---|
[2506] | 90 | conf.env.AddCustomPackage('extra')
|
---|
[1130] | 91 | conf.env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])
|
---|
| 92 | if not conf.CheckHeader("Python.h", language='c'):
|
---|
| 93 | Exit(1)
|
---|
[1325] | 94 | pylib = 'python'+distutils.sysconfig.get_python_version()
|
---|
| 95 | if env['PLATFORM'] == "darwin":
|
---|
| 96 | conf.env.Append(FRAMEWORKS=["Python"])
|
---|
[1130] | 97 | else:
|
---|
[1325] | 98 | if not conf.CheckLib(library=pylib, language='c'): Exit(1)
|
---|
| 99 |
|
---|
| 100 | conf.env.AddCustomPackage('boost')
|
---|
[2506] | 101 | libname = conf.env["boostlib"]
|
---|
| 102 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
| 103 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
| 104 | else:
|
---|
| 105 | if not conf.CheckLibWithHeader(libname,
|
---|
| 106 | 'boost/python.hpp', language='c++'):
|
---|
| 107 | Exit(1)
|
---|
[1501] | 108 |
|
---|
[2517] | 109 | if not conf.CheckLib("m"):
|
---|
| 110 | Exit(1)
|
---|
[1325] | 111 | # test for cfitsio
|
---|
| 112 | conf.env.AddCustomPackage('cfitsio')
|
---|
[2506] | 113 | libname = conf.env["cfitsiolib"]
|
---|
[2517] | 114 | if not conf.CheckHeader("fitsio.h"):
|
---|
| 115 | #SuSE is being special
|
---|
| 116 | conf.env.AppendUnique(CPPPATH=['/usr/include/libcfitsio0'])
|
---|
| 117 | if not conf.CheckHeader("fitsio.h"):
|
---|
| 118 | Exit(1)
|
---|
[2506] | 119 | if libname.find(".") > -1 and os.path.exists(libname):
|
---|
| 120 | conf.env.AppendUnique(LIBS=[env.File(libname)])
|
---|
| 121 | else:
|
---|
[2517] | 122 | if not conf.CheckLib(libname, language='c'):
|
---|
[2506] | 123 | Exit(1)
|
---|
| 124 |
|
---|
[1325] | 125 | conf.env.AddCustomPackage('rpfits')
|
---|
[2517] | 126 | if not conf.CheckLibWithHeader(conf.env["rpfitslib"], "RPFITS.h",
|
---|
| 127 | language="c"):
|
---|
[1354] | 128 | Exit(1)
|
---|
[2506] | 129 |
|
---|
| 130 | libpath = ""
|
---|
[2510] | 131 | for p in [conf.env["casacoreroot"], conf.env.get("extraroot", "")]:
|
---|
[2506] | 132 | pth = os.path.join(p, "include", "casacore")
|
---|
| 133 | if os.path.exists(pth):
|
---|
[2624] | 134 | libpath = os.path.join(p, LIBDIR)
|
---|
[3030] | 135 | conf.env.AppendUnique(CPPPATH=[pth,pth+'/..'])
|
---|
[2506] | 136 | break
|
---|
[3034] | 137 | cclibs = ["casa_python", "casa_images", "casa_ms",
|
---|
[2506] | 138 | "casa_coordinates", "casa_lattices",
|
---|
| 139 | "casa_fits", "casa_measures", "casa_scimath",
|
---|
[2517] | 140 | "casa_scimath_f", "casa_tables", "casa_casa"]
|
---|
[2506] | 141 | if conf.env["casacorestatic"]:
|
---|
[2624] | 142 | libs = [ env.File(os.path.join(libpath, "lib"+lib+".a")) \
|
---|
[2506] | 143 | for lib in cclibs ]
|
---|
| 144 | else:
|
---|
[2624] | 145 | conf.env.AppendUnique(LIBPATH=libpath)
|
---|
[2506] | 146 | if not conf.CheckLibWithHeader("casa_casa", "casa/aips.h",
|
---|
| 147 | language='c++', autoadd=0):
|
---|
| 148 | Exit(1)
|
---|
| 149 | libs = cclibs
|
---|
| 150 | conf.env.PrependUnique(LIBS=libs)
|
---|
[1325] | 151 |
|
---|
[1130] | 152 | if not conf.CheckLib('stdc++', language='c++'): Exit(1)
|
---|
[1433] | 153 | if conf.env["alma"]:
|
---|
[2485] | 154 | conf.env.Append(CPPFLAGS=['-DUSE_CASAPY'])
|
---|
[2525] | 155 | if conf.env.get("extraflags"):
|
---|
| 156 | flags = conf.env.ParseFlags(conf.env["extraflags"])
|
---|
| 157 | conf.env.MergeFlags(flags)
|
---|
[1082] | 158 | env = conf.Finish()
|
---|
[1120] | 159 |
|
---|
[2503] | 160 | opts.Save('options.cache', env)
|
---|
| 161 |
|
---|
[2942] | 162 | env["version"] = "4.3.x"
|
---|
[1135] | 163 |
|
---|
[1120] | 164 | if env['mode'] == 'release':
|
---|
[1335] | 165 | if env["PLATFORM"] != "darwin":
|
---|
| 166 | env.Append(LINKFLAGS=['-Wl,-O1', '-s'])
|
---|
| 167 | env.Append(CCFLAGS=["-O2"])
|
---|
[3128] | 168 | env.Append(CCFLAGS=["-std=c++11"])
|
---|
[1335] | 169 | else:
|
---|
[2179] | 170 | env.Append(CCFLAGS=["-g", "-W", "-Wall"])
|
---|
[1184] | 171 |
|
---|
| 172 | # Export for SConscript files
|
---|
[1135] | 173 | Export("env")
|
---|
[1082] | 174 |
|
---|
[1325] | 175 | # build externals
|
---|
[2503] | 176 | ext = env.SConscript("external-alma/SConscript")
|
---|
| 177 |
|
---|
[1184] | 178 | # build library
|
---|
[2179] | 179 | so = env.SConscript("src/SConscript", variant_dir="build", duplicate=0)
|
---|
[2503] | 180 |
|
---|
| 181 | apps = env.SConscript("apps/SConscript")
|
---|
| 182 |
|
---|
[1195] | 183 | # test module import, to see if there are unresolved symbols
|
---|
| 184 | def test_module(target,source,env):
|
---|
| 185 | pth = str(target[0])
|
---|
| 186 | mod = os.path.splitext(pth)[0]
|
---|
| 187 | sys.path.insert(2, os.path.split(mod)[0])
|
---|
| 188 | __import__(os.path.split(mod)[1])
|
---|
| 189 | print "ok"
|
---|
| 190 | return 0
|
---|
[2503] | 191 |
|
---|
[1195] | 192 | def test_str(target, source, env):
|
---|
| 193 | return "Testing module..."
|
---|
[1184] | 194 |
|
---|
[3031] | 195 | taction = Action(test_module, test_str)
|
---|
| 196 | env.AddPostAction(so, taction)
|
---|
[1195] | 197 |
|
---|
| 198 | if env.GetOption("clean"):
|
---|
| 199 | Execute(Delete(".sconf_temp"))
|
---|
[2503] | 200 | Execute(Delete("options.cache"))
|
---|
[2627] | 201 | Execute(Delete(".sconsign.dblite"))
|
---|
[2166] | 202 | if env["makedoc"].lower() != "none":
|
---|
| 203 | env.SConscript("doc/SConscript")
|
---|