diff --git a/src/build-system.jam b/src/build-system.jam index dbba935da..c4e3df8f9 100755 --- a/src/build-system.jam +++ b/src/build-system.jam @@ -41,6 +41,15 @@ rule location ( ) return $(r:P) ; } +# Returns the property set with the +# free features from the currently processed +# build request. +rule command-line-free-features ( ) +{ + return $(.command-line-free-features) ; +} + + # Check if we can load 'test-config.jam'. If we can, load it and # ignore user configs. @@ -399,6 +408,7 @@ local results-of-main-targets ; for local p in $(expanded) { + .command-line-free-features = [ property-set.create [ $(p).free ] ] ; for local t in $(targets) { local g = [ $(t).generate $(p) ] ; diff --git a/src/build/targets.jam b/src/build/targets.jam index 0b1afa080..b42e75bb0 100644 --- a/src/build/targets.jam +++ b/src/build/targets.jam @@ -1057,6 +1057,7 @@ class basic-target : abstract-target import set sequence errors ; import "class" : new ; import property feature ; + import build-system ; rule __init__ ( name : project : sources * : requirements * : @@ -1185,12 +1186,21 @@ class basic-target : abstract-target local fn = [ full-name ] ; ECHO [ targets.indent ] "Building target '$(fn)'" ; targets.increase-indent ; - ECHO [ targets.indent ] "Build request: " [ $(property-set).raw ] ; + ECHO [ targets.indent ] "Build request: " [ $(property-set).raw ] ; + local cf = [ build-system.command-line-free-features ] ; + ECHO [ targets.indent ] "Command line free features: " + [ $(cf).raw ] ; ECHO [ targets.indent ] "Target requirements: " [ $(self.requirements).raw ] ; } if ! $(self.generated.$(property-set)) { + # Apply free features form the command line. If user + # said + # define=FOO + # he most likely want this define to be set for all compiles. + property-set = [ $(property-set).refine + [ build-system.command-line-free-features ] ] ; local rproperties = [ targets.common-properties $(property-set) $(self.requirements) ] ; diff --git a/test/free_features_request.py b/test/free_features_request.py new file mode 100644 index 000000000..d4ae0ca7b --- /dev/null +++ b/test/free_features_request.py @@ -0,0 +1,42 @@ +#!/usr/bin/python + +# Copyright (C) Vladimir Prus 2007. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# Tests that a free feature specified on the command +# line applies to all targets ever built. +from BoostBuild import Tester, List + + +t = Tester() + +t.write("Jamroot", """ +exe hello : hello.cpp foo ; +lib foo : foo.cpp ; +""") +t.write("hello.cpp", """ +extern void foo(); +#ifdef FOO +int main() +{ + foo(); + return 0; +} +#endif +""") + +t.write("foo.cpp", """ +#ifdef FOO +void foo() {} +#endif +""") + +# If FOO is not defined when compiling the 'foo' +# target, we'll get a link error at this point. +t.run_build_system("hello define=FOO") + +t.expect_addition("bin/$toolset/debug/hello") + +t.cleanup() diff --git a/test/test_all.py b/test/test_all.py index 234a17680..9e21bc26a 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -150,6 +150,7 @@ tests = [ "rebuilds", "example_libraries", "example_make", "remove_requirement", + "free_features_request", ] if os.name == 'posix':