1 # Copyright 2005 Vladimir Prus.
2 # Distributed under the Boost Software License, Version 1.0. (See
3 # accompanying file LICENSE_1_0.txt or copy at
4 # http://www.boost.org/LICENSE_1_0.txt)
6 # Defines main target 'cast', used to change type for target. For example, in Qt
7 # library one wants two kinds of CPP files -- those that just compiled and those
8 # that are passed via the MOC tool.
12 # exe main : main.cpp [ cast _ moccable-cpp : widget.cpp ] ;
14 # Boost.Build will assign target type CPP to both main.cpp and widget.cpp. Then,
15 # the cast rule will change target type of widget.cpp to MOCCABLE-CPP, and Qt
16 # support will run the MOC tool as part of the build process.
18 # At the moment, the 'cast' rule only works for non-derived (source) targets.
20 # TODO: The following comment is unclear or incorrect. Clean it up.
21 # > Another solution would be to add a separate main target 'moc-them' that
22 # > would moc all the passed sources, no matter what their type is, but I prefer
23 # > cast, as defining a new target type + generator for that type is somewhat
24 # > simpler than defining a main target rule.
26 import "class" : new ;
33 class cast-target-class : typed-target
37 rule __init__ ( name : project : type : sources * : requirements * :
38 default-build * : usage-requirements * )
40 typed-target.__init__ $(name) : $(project) : $(type) : $(sources) :
41 $(requirements) : $(default-build) : $(usage-requirements) ;
44 rule construct ( name : source-targets * : property-set )
47 for local s in $(source-targets)
49 if ! [ class.is-a $(s) : file-target ]
51 import errors : user-error : errors.user-error ;
52 errors.user-error Source to the 'cast' rule is not a file! ;
56 import errors : user-error : errors.user-error ;
57 errors.user-error Only non-derived target are allowed for
58 'cast'. : when building [ full-name ] ;
60 local r = [ $(s).clone-with-different-type $(self.type) ] ;
61 result += [ virtual-target.register $(r) ] ;
63 return [ property-set.empty ] $(result) ;
68 rule cast ( name type : sources * : requirements * : default-build * :
69 usage-requirements * )
71 local project = [ project.current ] ;
73 local real-type = [ type.type-from-rule-name $(type) ] ;
77 errors.user-error No type corresponds to the main target rule name
78 '$(type)' : "Hint: try a lowercase name" ;
81 targets.main-target-alternative [ new cast-target-class $(name) : $(project)
83 : [ targets.main-target-sources $(sources) : $(name) ]
84 : [ targets.main-target-requirements $(requirements) : $(project) ]
85 : [ targets.main-target-default-build $(default-build) : $(project) ]
86 : [ targets.main-target-usage-requirements $(usage-requirements) :
91 IMPORT $(__name__) : cast : : cast ;