3 # Copyright 2003 Dave Abrahams
4 # Copyright 2002, 2003, 2004, 2006 Vladimir Prus
5 # Distributed under the Boost Software License, Version 1.0.
6 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
10 t = BoostBuild.Tester(use_test_config=False)
13 # Test that usage requirements on main targets work (and are propagated all the
14 # way up, and not only to direct dependants).
15 t.write("jamroot.jam", "")
17 # Note: 'lib cc ..', not 'lib c'. If using 'lib c: ...' the HP-CXX linker will
18 # confuse it with the system C runtime.
19 t.write("jamfile.jam", """\
20 lib b : b.cpp : <link>shared:<define>SHARED_B : :
21 <define>FOO <link>shared:<define>SHARED_B ;
28 #if defined(_WIN32) && defined(SHARED_B)
36 #if defined(_WIN32) && defined(SHARED_B)
39 create_lib_please() {}
45 # if defined(_WIN32) && defined(SHARED_B)
54 t.run_build_system(["--clean"])
57 # Test that use requirements on main target work, when they are referred using
58 # 'dependency' features.
60 t.write("jamfile.jam", """\
61 lib b : b.cpp : <link>shared:<define>SHARED_B : : <define>FOO
62 <link>shared:<define>SHARED_B ;
63 exe a : a.cpp : <use>b ;
68 #if defined(_WIN32) && defined(SHARED_B)
81 t.run_build_system(["--clean"])
84 # Test that usage requirements on a project work.
85 t.write("jamfile.jam", "exe a : a.cpp lib//b ;")
87 t.write("lib/jamfile.jam", """\
89 : requirements <link>shared:<define>SHARED_B
90 : usage-requirements <define>FOO <link>shared:<define>SHARED_B ;
94 t.write("lib/b.cpp", """\
96 #if defined(_WIN32) && defined(SHARED_B)
105 # Test that use requirements are inherited correctly.
106 t.write("jamfile.jam", "exe a : a.cpp lib/1//b ;")
108 t.write("a.cpp", """\
109 #if defined(FOO) && defined(ZOO)
112 int main() { foo(); }
115 t.write("lib/jamfile.jam", """\
116 project : requirements : usage-requirements <define>FOO ;
119 t.write("lib/1/jamfile.jam", """\
121 : requirements <link>shared:<define>SHARED_B
122 : usage-requirements <define>ZOO <link>shared:<define>SHARED_B ;
126 t.write("lib/1/b.cpp", """\
128 #if defined(_WIN32) && defined(SHARED_B)
129 __declspec(dllexport)
135 t.run_build_system(["--clean"])
138 # Test that we correctly handle dependency features in usage requirements on
140 t.write("jamfile.jam", """\
141 lib b : b.cpp : <link>shared:<define>SHARED_B : : <define>FOO
142 <link>shared:<define>SHARED_B ;
144 # Here's the test: we should correctly handle dependency feature and get usage
145 # requirements from 'b'.
146 lib cc : c.cpp : <link>shared:<define>SHARED_C : : <library>b ;
148 # This will build only if <define>FOO was propagated from 'c'.
152 t.write("a.cpp", """\
155 # if defined(_WIN32) && defined(SHARED_B)
156 __declspec(dllexport)
161 int main() { foo(); }
164 t.write("c.cpp", """\
166 #if defined(_WIN32) && defined(SHARED_C)
167 __declspec(dllexport)
169 must_export_something;
173 t.run_build_system(["--clean"])
176 # Test correct handling of dependency features in project requirements.
177 t.write("jamfile.jam", "exe a : a.cpp lib1//cc ;")
179 t.write("lib1/jamfile.jam", """\
181 : requirements <link>shared:<define>SHARED_C
182 : usage-requirements <library>../lib2//b <link>shared:<define>SHARED_C ;
186 t.write("lib1/c.cpp", """\
188 #if defined(_WIN32) && defined(SHARED_C)
189 __declspec(dllexport)
191 must_export_something;
194 t.write("lib2/jamfile.jam", """\
195 lib b : b.cpp : <link>shared:<define>SHARED_B : : <define>FOO
196 <link>shared:<define>SHARED_B ;
199 t.copy("b.cpp", "lib2/b.cpp")
204 # Test that targets listed in dependency features in usage requirements are
205 # built with the correct properties.
208 t.write("jamroot.jam", "")
209 t.write("jamfile.jam", """\
210 lib main : main.cpp : <use>libs//lib1 : : <library>libs//lib1 ;
211 exe hello : hello.cpp main : ;
214 t.write("main.cpp", """\
216 #if defined(_WIN32) && defined(SHARED_LIB1)
217 __declspec(dllimport)
221 int main() { foo(); }
224 t.write("hello.cpp", "\n")
225 t.write("libs/a.cpp", """\
227 #if defined(_WIN32) && defined(SHARED_LIB1)
228 __declspec(dllexport)
234 # This library should be built with the same properties as 'main'. This is a
235 # regression test for a bug when they were generated with empty properties, and
236 # there were ambiguities between variants.
237 t.write("libs/jamfile.jam", """\
238 lib lib1 : a_d.cpp : <variant>debug <link>shared:<define>SHARED_LIB1 : :
239 <link>shared:<define>SHARED_LIB1 ;
240 lib lib1 : a.cpp : <variant>release <link>shared:<define>SHARED_LIB1 : :
241 <link>shared:<define>SHARED_LIB1 ;
244 t.write("libs/a_d.cpp", """\
246 #if defined(_WIN32) && defined(SHARED_LIB1)
247 __declspec(dllexport)
252 t.run_build_system(["link=static"])
253 t.expect_addition("libs/bin/$toolset/debug/link-static/a_d.obj")
256 # Test that indirect conditionals are respected in usage requirements.
259 t.write("jamroot.jam", """\
260 rule has-foo ( properties * ) { return <define>HAS_FOO ; }
262 lib b : b.cpp : <link>static : : <conditional>@has-foo ;
265 t.write("a.cpp", """\
268 int main() { foo(); }
272 t.write("b.cpp", """\
274 #if defined(_WIN32) && defined(SHARED_B)
275 __declspec(dllexport)
281 t.expect_addition("bin/$toolset/debug/a.exe")