|
| 1 | +# |
| 2 | +# Copyright (c) 2016 Stefan Seefeld |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# Distributed under the Boost Software License, Version 1.0. |
| 6 | +# (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | +# http://www.boost.org/LICENSE_1_0.txt) |
| 8 | + |
| 9 | +from SCons.Variables import * |
| 10 | +from SCons.Script import AddOption |
| 11 | +from collections import OrderedDict |
| 12 | +import platform |
| 13 | +from . import ui |
| 14 | +from . import python |
| 15 | +from . import boost |
| 16 | + |
| 17 | +def add_options(vars): |
| 18 | + ui.add_option('-V', '--verbose', dest='verbose', action='store_true', help='verbose mode: print full commands.') |
| 19 | + python.add_options(vars) |
| 20 | + boost.add_options(vars) |
| 21 | + |
| 22 | + vars.Add('CPPPATH', converter=lambda v:v.split()) |
| 23 | + vars.Add('CCFLAGS', converter=lambda v:v.split()) |
| 24 | + vars.Add('LIBPATH', converter=lambda v:v.split()) |
| 25 | + vars.Add('LIBS', converter=lambda v:v.split()) |
| 26 | + vars.Add('PYTHON') |
| 27 | + vars.Add('PYTHONLIBS') |
| 28 | + |
| 29 | + ui.add_variable(vars, ("arch", "target architeture", platform.machine())) |
| 30 | + ui.add_variable(vars, ("toolchain", "toolchain to use", 'gcc')) |
| 31 | + ui.add_variable(vars, ListVariable("variant", "Build configuration", "release", ["release", "debug", "profile"])) |
| 32 | + ui.add_variable(vars, ListVariable("link", "Library linking", "dynamic", ["static", "dynamic"])) |
| 33 | + ui.add_variable(vars, ListVariable("threading", "Multi-threading support", "multi", ["single", "multi"])) |
| 34 | + ui.add_variable(vars, EnumVariable("layout", "Layout of library names and header locations", "versioned", ["versioned", "system"])) |
| 35 | + ui.add_variable(vars, PathVariable("stagedir", "If --stage is passed install only compiled library files in this location", "stage", PathVariable.PathAccept)) |
| 36 | + ui.add_variable(vars, PathVariable("prefix", "Install prefix", "/usr/local", PathVariable.PathAccept)) |
| 37 | + |
| 38 | + |
| 39 | +def get_checks(): |
| 40 | + checks = OrderedDict() |
| 41 | + checks['python'] = python.check |
| 42 | + checks['boost'] = boost.check |
| 43 | + return checks |
| 44 | + |
| 45 | + |
| 46 | +def set_property(env, **kw): |
| 47 | + |
| 48 | + from toolchains.gcc import features as gcc_features |
| 49 | + from toolchains.msvc import features as msvc_features |
| 50 | + |
| 51 | + if 'gcc' in env['TOOLS']: features = gcc_features |
| 52 | + elif 'msvc' in env['TOOLS']: features = msvc_features |
| 53 | + else: raise Error('unknown toolchain') |
| 54 | + features.init_once(env) |
| 55 | + for (prop,value) in kw.items(): |
| 56 | + getattr(features, prop, lambda x, y : None)(env, value) |
| 57 | + env[prop.upper()] = value |
| 58 | + |
| 59 | + |
| 60 | +def boost_suffix(env): |
| 61 | + suffix = str() |
| 62 | + |
| 63 | + if env["layout"] == "versioned": |
| 64 | + if "gcc" in env["TOOLS"]: |
| 65 | + suffix += "-gcc" + "".join(env["CCVERSION"].split(".")[0:2]) |
| 66 | + if env["THREADING"] == "multi": |
| 67 | + suffix += "-mt" |
| 68 | + if env["DEBUG"]: |
| 69 | + suffix += "-d" |
| 70 | + if env["layout"] == "versioned": |
| 71 | + suffix += "-" + "_".join(env["BPL_VERSION"].split(".")) |
| 72 | + |
| 73 | + return suffix |
| 74 | + |
| 75 | + |
| 76 | +def prepare_build_dir(env): |
| 77 | + |
| 78 | + vars = {} |
| 79 | + env["boost_suffix"] = boost_suffix |
| 80 | + build_dir="bin.SCons" |
| 81 | + if "gcc" in env["TOOLS"]: |
| 82 | + build_dir+="/gcc-%s"%env["CCVERSION"] |
| 83 | + vars['CXXFLAGS'] = ['-ftemplate-depth-128', '-Wall'] |
| 84 | + |
| 85 | + elif "msvc" in env["TOOLS"]: |
| 86 | + build_dir+="/msvc-%s"%env["MSVS_VERSION"] |
| 87 | + vars['BOOST_BUILD_DIR'] = build_dir |
| 88 | + vars['BOOST_SUFFIX'] = "${boost_suffix(__env__)}" |
| 89 | + env.Replace(**vars) |
| 90 | + return build_dir |
| 91 | + |
| 92 | + |
| 93 | +def variants(env): |
| 94 | + |
| 95 | + env.Append(CPPPATH = "#/include", CPPDEFINES = ["BOOST_ALL_NO_LIB=1"]) |
| 96 | + set_property(env, architecture = env['TARGET_ARCH']) |
| 97 | + for variant in env["variant"]: |
| 98 | + e = env.Clone() |
| 99 | + e["current_variant"] = variant |
| 100 | + set_property(env, profile = False) |
| 101 | + if variant == "release": |
| 102 | + set_property(e, optimize = "speed", debug = False) |
| 103 | + elif variant == "debug": |
| 104 | + set_property(e, optimize = "no", debug = True) |
| 105 | + elif variant == "profile": |
| 106 | + set_property(e, optimize = "speed", profile = True, debug = True) |
| 107 | + for linking in env["link"]: |
| 108 | + e["linking"] = linking |
| 109 | + if linking == "dynamic": |
| 110 | + e["LINK_DYNAMIC"] = True |
| 111 | + else: |
| 112 | + e["LINK_DYNAMIC"] = False |
| 113 | + for threading in e["threading"]: |
| 114 | + e["current_threading"] = threading |
| 115 | + set_property(e, threading = threading) |
| 116 | + yield e |
0 commit comments