| 1 |
""" |
|---|
| 2 |
SConstruct for iplt |
|---|
| 3 |
|
|---|
| 4 |
This file is part of the image processing library & toolbox |
|---|
| 5 |
for electron microscopy, licensed under the GPL. Please see |
|---|
| 6 |
the accompanying LICENSE file for more information. The iplt |
|---|
| 7 |
homepage is http://www.iplt.org |
|---|
| 8 |
|
|---|
| 9 |
Author: Ansgar Philippsen |
|---|
| 10 |
|
|---|
| 11 |
""" |
|---|
| 12 |
|
|---|
| 13 |
EnsureSConsVersion(0,95) |
|---|
| 14 |
|
|---|
| 15 |
import SCons, re |
|---|
| 16 |
import sys, os, os.path, string, copy, shutil |
|---|
| 17 |
from types import * |
|---|
| 18 |
|
|---|
| 19 |
sys.path.append("utils") |
|---|
| 20 |
|
|---|
| 21 |
# defines routines to discriminate the platform |
|---|
| 22 |
from Platform import * |
|---|
| 23 |
platform = GetPlatform() |
|---|
| 24 |
|
|---|
| 25 |
if platform.GetName()=="win32": |
|---|
| 26 |
sys.argv=sys.argv[1:] # remove first '-c' under win32 |
|---|
| 27 |
|
|---|
| 28 |
skip_config=0 |
|---|
| 29 |
|
|---|
| 30 |
if 'doc' in COMMAND_LINE_TARGETS and len(COMMAND_LINE_TARGETS)==1: |
|---|
| 31 |
skip_config=1 |
|---|
| 32 |
|
|---|
| 33 |
if "-c" in sys.argv: |
|---|
| 34 |
skip_config=1 |
|---|
| 35 |
|
|---|
| 36 |
# define an extended scons environment |
|---|
| 37 |
from Environ import * |
|---|
| 38 |
from DoConfig import * |
|---|
| 39 |
|
|---|
| 40 |
# get custom options |
|---|
| 41 |
version_string=SCons.__version__ |
|---|
| 42 |
version = string.split(string.split(version_string, ' ')[0], '.') |
|---|
| 43 |
v_major = int(version[0]) |
|---|
| 44 |
v_minor = int(re.match('\d+', version[1]).group()) |
|---|
| 45 |
if len(version) >= 3: |
|---|
| 46 |
v_revision = int(re.match('\d+', version[2]).group()) |
|---|
| 47 |
else: |
|---|
| 48 |
v_revision = 0 |
|---|
| 49 |
if v_major == 0 and v_minor < 98: |
|---|
| 50 |
opts = Options("settings.py") |
|---|
| 51 |
else: |
|---|
| 52 |
opts = Variables("settings.py") |
|---|
| 53 |
opts.Add("EXTRA_INCLUDE_PATH","extra include paths","") |
|---|
| 54 |
opts.Add("EXTRA_LIBRARY_PATH","extra library search paths","") |
|---|
| 55 |
opts.Add("EXTRA_FRAMEWORK_PATH","extra framework search paths. Affects MacOS X only","") |
|---|
| 56 |
opts.Add("EXTRA_CC_FLAGS","extra flags for c++ compiler","") |
|---|
| 57 |
opts.Add("EXTRA_LINK_FLAGS","extra flags for linker","") |
|---|
| 58 |
opts.Add("EXTRA_LIBS","extra libraries to include at link time","") |
|---|
| 59 |
opts.Add("BOOST_LIBS_SUFFIX","postfix for boost libraries","") |
|---|
| 60 |
opts.Add("PYTHON_VERSION","python version (maj.min), override automatic python detection","") |
|---|
| 61 |
opts.Add("INSTALL_PATH","location for installation","") |
|---|
| 62 |
opts.Add("CC","explicit C compiler") |
|---|
| 63 |
opts.Add("CXX","explicit C++ compiler") |
|---|
| 64 |
opts.Add("LINK","explicit linker to use") |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
# setup basic environment |
|---|
| 68 |
env = Environment(options=opts, ENV = os.environ) |
|---|
| 69 |
env.platform_name=platform.GetName() |
|---|
| 70 |
# the following hack is necessary to avoid weird unicode issues with python 2.6 on some platforms |
|---|
| 71 |
#env.Append(CCFLAGS='$TRANSLATION_UNITS') |
|---|
| 72 |
env['CCFLAGS'].append('$TRANSLATION_UNITS') |
|---|
| 73 |
env['TRANSLATION_UNITS']=translation_units(env) |
|---|
| 74 |
|
|---|
| 75 |
platform.SetLibDir(env) |
|---|
| 76 |
#add pyc builder |
|---|
| 77 |
def pyc_action(target,source,env): |
|---|
| 78 |
import compiler |
|---|
| 79 |
for s in source: |
|---|
| 80 |
ret=compiler.compileFile(str(s)) |
|---|
| 81 |
if ret: |
|---|
| 82 |
return -1 |
|---|
| 83 |
|
|---|
| 84 |
return 0 |
|---|
| 85 |
def pyc_string(target,source,env): |
|---|
| 86 |
for s in source: |
|---|
| 87 |
return "byte compiling %s"%(str(s)) |
|---|
| 88 |
|
|---|
| 89 |
pyc_builder = Builder(action=Action(pyc_action,pyc_string), |
|---|
| 90 |
suffix='.pyc',src_suffix='.py', |
|---|
| 91 |
single_source=True) |
|---|
| 92 |
env.Append(BUILDERS = {'PyC':pyc_builder}) |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
if os.getenv('IPLT_STAGE'): |
|---|
| 96 |
env.SetStageDir(os.getenv('IPLT_STAGE')) |
|---|
| 97 |
else: |
|---|
| 98 |
env.SetStageDir("#/stage") |
|---|
| 99 |
|
|---|
| 100 |
if "-c" in sys.argv: |
|---|
| 101 |
print "removing stage dir '"+str(Dir(env.GetStageDir()))+"' ..." |
|---|
| 102 |
shutil.rmtree(str(Dir(env.GetStageDir())),True) |
|---|
| 103 |
print "done" |
|---|
| 104 |
|
|---|
| 105 |
platform.SetCompilerFlags(env) |
|---|
| 106 |
platform_name = platform.GetName() |
|---|
| 107 |
|
|---|
| 108 |
boost_suffix = env["BOOST_LIBS_SUFFIX"] |
|---|
| 109 |
|
|---|
| 110 |
env.Append(CPPPATH = [env._stagedir + "/include","#extra/include"] + string.split(env["EXTRA_INCLUDE_PATH"]) ) |
|---|
| 111 |
|
|---|
| 112 |
env.Append(LIBPATH = string.split(env["EXTRA_LIBRARY_PATH"]) ) |
|---|
| 113 |
env.Append(CCFLAGS = string.split(env["EXTRA_CC_FLAGS"])) |
|---|
| 114 |
env.Append(LINKFLAGS = string.split(env["EXTRA_LINK_FLAGS"])) |
|---|
| 115 |
env.Append(FRAMEWORKPATH=string.split(env["EXTRA_FRAMEWORK_PATH"])) |
|---|
| 116 |
abs_lib_dir = os.getcwd() + "/" + str(env.Dir(env._stagedir)) + "/"+env.GetLibDir() |
|---|
| 117 |
|
|---|
| 118 |
extra_libs = string.split(env["EXTRA_LIBS"]) |
|---|
| 119 |
|
|---|
| 120 |
env.Append(LIBS = extra_libs) |
|---|
| 121 |
|
|---|
| 122 |
do_config=0 #TODO override with command line option |
|---|
| 123 |
|
|---|
| 124 |
centries=[] |
|---|
| 125 |
|
|---|
| 126 |
if skip_config: |
|---|
| 127 |
print "Skipping Configuration" |
|---|
| 128 |
else: |
|---|
| 129 |
if not do_config: |
|---|
| 130 |
if os.path.isfile("config.save"): |
|---|
| 131 |
print "Using configuration settings in config.save" |
|---|
| 132 |
cfile=file("config.save","r") |
|---|
| 133 |
centries=cfile.readlines() |
|---|
| 134 |
cfile.close() |
|---|
| 135 |
else: |
|---|
| 136 |
print "No pre-configured state found, running configuration" |
|---|
| 137 |
do_config=1 |
|---|
| 138 |
else: |
|---|
| 139 |
print "Running configuration" |
|---|
| 140 |
|
|---|
| 141 |
env=Configure_Main(env,boost_suffix,do_config,centries) |
|---|
| 142 |
tmpenv=Configure_tmp(env.Clone(),boost_suffix,do_config,centries) |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
# the Pymod environment adds the necessary flags and builder |
|---|
| 146 |
# it is derived from the basic environment |
|---|
| 147 |
pymod_env = env.Clone() |
|---|
| 148 |
platform.AddPythonInclude(pymod_env, env["PYTHON_VERSION"]) |
|---|
| 149 |
#platform.AddPythonLib(pymod_env, env["PYTHON_VERSION"]) # not required !! |
|---|
| 150 |
platform.SetPymodBuilder(pymod_env) |
|---|
| 151 |
pymod_env.Prepend(LIBPATH = env._stagedir+"/"+pymod_env.GetLibDir()) |
|---|
| 152 |
pymod_env.Append(LIBS = ["iplt","iplt_geom"]) |
|---|
| 153 |
if not skip_config: |
|---|
| 154 |
pymod_env = Configure_Pymod(pymod_env,boost_suffix,do_config,centries) |
|---|
| 155 |
|
|---|
| 156 |
# algorithm environment, based on basic env |
|---|
| 157 |
alg_env = env.Clone() |
|---|
| 158 |
alg_env.Prepend(LIBPATH = env._stagedir+"/"+pymod_env.GetLibDir()) |
|---|
| 159 |
alg_env.Append(LIBS = ["iplt","iplt_geom","iplt_info"]+extra_libs) # iplt_geom added for OSX |
|---|
| 160 |
|
|---|
| 161 |
# plugin environment, based on basic env |
|---|
| 162 |
plugin_env = env.Clone() |
|---|
| 163 |
platform.SetPluginInfo(plugin_env) |
|---|
| 164 |
plugin_env.Prepend(LIBPATH = env._stagedir+"/"+pymod_env.GetLibDir()) |
|---|
| 165 |
plugin_env.Append(LIBS = extra_libs) |
|---|
| 166 |
|
|---|
| 167 |
# the wxwindows environment, based on basic env |
|---|
| 168 |
wxwin_env = env.Clone() |
|---|
| 169 |
# static library hack |
|---|
| 170 |
wxwin_env._dict["STATICLIBS"]= [] |
|---|
| 171 |
platform.SetWXInfo(wxwin_env) |
|---|
| 172 |
wxwin_env.Prepend(LIBPATH = env._stagedir+"/"+pymod_env.GetLibDir()) |
|---|
| 173 |
wxwin_env.Append(LIBS = extra_libs) |
|---|
| 174 |
platform.AddPythonInclude(wxwin_env, env["PYTHON_VERSION"]) |
|---|
| 175 |
platform.AddPythonLib(wxwin_env, env["PYTHON_VERSION"]) # required! |
|---|
| 176 |
|
|---|
| 177 |
pyapp_env = env.Clone() |
|---|
| 178 |
platform.AddPythonInclude(pyapp_env, env["PYTHON_VERSION"]) |
|---|
| 179 |
platform.AddPythonLib(pyapp_env, env["PYTHON_VERSION"]) |
|---|
| 180 |
|
|---|
| 181 |
if not 'nogui' in COMMAND_LINE_TARGETS and not skip_config: |
|---|
| 182 |
wxwin_env = Configure_wx(wxwin_env,do_config,centries) |
|---|
| 183 |
|
|---|
| 184 |
if do_config and not skip_config: |
|---|
| 185 |
print "Writing configuration to config.save" |
|---|
| 186 |
cfile=file("config.save","w") |
|---|
| 187 |
cfile.writelines(centries) |
|---|
| 188 |
cfile.close() |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
# app env |
|---|
| 192 |
app_env = env.Clone() |
|---|
| 193 |
app_env.Append(LIBS = ["iplt"]) |
|---|
| 194 |
app_env.Prepend(LIBPATH = env._stagedir+"/"+pymod_env.GetLibDir()) |
|---|
| 195 |
app_env.Append(LIBS = extra_libs) |
|---|
| 196 |
|
|---|
| 197 |
# unit tests env |
|---|
| 198 |
test_env = env.Clone() |
|---|
| 199 |
#test_env.Append(LIBS = 'boost_unit_test_framework' + env["BOOST_LIBS_SUFFIX"]) |
|---|
| 200 |
test_env.Append(LIBS = 'iplt') |
|---|
| 201 |
test_env.Prepend(LIBPATH = env._stagedir+"/"+pymod_env.GetLibDir()) |
|---|
| 202 |
test_env.Append(LIBS = extra_libs) |
|---|
| 203 |
# The following line was added to make iplt compatible with boost 1.34. We must now link |
|---|
| 204 |
# statically to boost.test and dynamically to everything else. Not sure if this |
|---|
| 205 |
# is portable to non-gcc compilers, probably not. |
|---|
| 206 |
if platform_name=="win32": |
|---|
| 207 |
test_env.Append(LINKCOM=" E:/sft/lib/boost_unit_test_framework-vc80-mt.lib") |
|---|
| 208 |
else: |
|---|
| 209 |
test_env.Append(LINKCOM = ' -Wl,-Bstatic -lboost_unit_test_framework' + env["BOOST_LIBS_SUFFIX"] + ' -Wl,-Bdynamic') |
|---|
| 210 |
# doc environment |
|---|
| 211 |
from doxy import DoxyEnvironment |
|---|
| 212 |
doc_env=DoxyEnvironment() |
|---|
| 213 |
|
|---|
| 214 |
Export(["env","pymod_env","alg_env","plugin_env","wxwin_env","app_env","test_env","doc_env","pyapp_env","platform_name"]) |
|---|
| 215 |
|
|---|
| 216 |
# build targets |
|---|
| 217 |
Alias("libs") |
|---|
| 218 |
Alias("gui") |
|---|
| 219 |
Alias("python_modules") |
|---|
| 220 |
Alias("unit_tests") |
|---|
| 221 |
Alias("default",["libs","gui","python_modules"]) |
|---|
| 222 |
Alias("all",["default","unit_tests"]) |
|---|
| 223 |
|
|---|
| 224 |
#nogui = ['src/base','src/misc','src/io','src/alg','src/info'] |
|---|
| 225 |
#default = nogui + ['src/gui'] |
|---|
| 226 |
|
|---|
| 227 |
Default("default") |
|---|
| 228 |
|
|---|
| 229 |
SConscript(dirs="src") |
|---|
| 230 |
|
|---|
| 231 |
def install_all(target=None, source=None, env=None): |
|---|
| 232 |
p = env["INSTALL_PATH"]; |
|---|
| 233 |
if(p == ""): |
|---|
| 234 |
print "no INSTALL_PATH specified in settings file, install aborted" |
|---|
| 235 |
return -1 |
|---|
| 236 |
env.InstallDir(Dir("#stage"),Dir(p),"bin") |
|---|
| 237 |
env.InstallDir(Dir("#stage"),Dir(p),pymod_env.GetLibDir()) |
|---|
| 238 |
env.InstallDir(Dir("#stage"),Dir(p),"include") |
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
env.Command("install","",Action(install_all)) |
|---|
| 242 |
env.Depends("install","default") |
|---|
| 243 |
env.AlwaysBuild("install") |
|---|
| 244 |
|
|---|
| 245 |
#env.Alias("all", default + ['install']) |
|---|
| 246 |
#env.Alias("nogui", nogui) |
|---|
| 247 |
|
|---|
| 248 |
env.Alias("configure") |
|---|
| 249 |
|
|---|
| 250 |
if 'doc' in COMMAND_LINE_TARGETS: |
|---|
| 251 |
doc_env.BuildAll(env._stagedir +'/share/doc/iplt') |
|---|