]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/usr/bin/python |
2 | ||
3 | # Copyright 2003, 2004, 2005, 2006 Vladimir Prus | |
4 | # Distributed under the Boost Software License, Version 1.0. | |
5 | # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | # Test that a chain of libraries works ok, no matter if we use static or shared | |
8 | # linking. | |
9 | ||
10 | import BoostBuild | |
11 | import os | |
12 | import string | |
13 | ||
14 | t = BoostBuild.Tester(use_test_config=False) | |
15 | ||
16 | # Stage the binary, so that it will be relinked without hardcode-dll-paths. | |
17 | # That will check that we pass correct -rpath-link, even if not passing -rpath. | |
18 | t.write("jamfile.jam", """\ | |
19 | stage dist : main ; | |
20 | exe main : main.cpp b ; | |
21 | """) | |
22 | ||
23 | t.write("main.cpp", """\ | |
24 | void foo(); | |
25 | int main() { foo(); } | |
26 | """) | |
27 | ||
28 | t.write("jamroot.jam", "") | |
29 | ||
30 | t.write("a/a.cpp", """\ | |
31 | void | |
32 | #if defined(_WIN32) | |
33 | __declspec(dllexport) | |
34 | #endif | |
35 | gee() {} | |
36 | void | |
37 | #if defined(_WIN32) | |
38 | __declspec(dllexport) | |
39 | #endif | |
40 | geek() {} | |
41 | """) | |
42 | ||
43 | t.write("a/jamfile.jam", "lib a : a.cpp ;") | |
44 | ||
45 | t.write("b/b.cpp", """\ | |
46 | void geek(); | |
47 | void | |
48 | #if defined(_WIN32) | |
49 | __declspec(dllexport) | |
50 | #endif | |
51 | foo() { geek(); } | |
52 | """) | |
53 | ||
54 | t.write("b/jamfile.jam", "lib b : b.cpp ../a//a ;") | |
55 | ||
56 | t.run_build_system(["-d2"], stderr=None) | |
57 | t.expect_addition("bin/$toolset/debug/main.exe") | |
58 | t.rm(["bin", "a/bin", "b/bin"]) | |
59 | ||
60 | t.run_build_system(["link=static"]) | |
61 | t.expect_addition("bin/$toolset/debug/link-static/main.exe") | |
62 | t.rm(["bin", "a/bin", "b/bin"]) | |
63 | ||
64 | ||
65 | # Check that <library> works for static linking. | |
66 | t.write("b/jamfile.jam", "lib b : b.cpp : <library>../a//a ;") | |
67 | ||
68 | t.run_build_system(["link=static"]) | |
69 | t.expect_addition("bin/$toolset/debug/link-static/main.exe") | |
70 | ||
71 | t.rm(["bin", "a/bin", "b/bin"]) | |
72 | ||
73 | t.write("b/jamfile.jam", "lib b : b.cpp ../a//a/<link>shared : <link>static ;") | |
74 | ||
75 | t.run_build_system() | |
76 | t.expect_addition("bin/$toolset/debug/main.exe") | |
77 | ||
78 | t.rm(["bin", "a/bin", "b/bin"]) | |
79 | ||
80 | ||
81 | # Test that putting a library in sources of a searched library works. | |
82 | t.write("jamfile.jam", """\ | |
83 | exe main : main.cpp png ; | |
84 | lib png : z : <name>png ; | |
85 | lib z : : <name>zzz ; | |
86 | """) | |
87 | ||
88 | t.run_build_system(["-a", "-d+2"], status=None, stderr=None) | |
89 | # Try to find the "zzz" string either in response file (for Windows compilers), | |
90 | # or in the standard output. | |
91 | rsp = t.adjust_names("bin/$toolset/debug/main.exe.rsp")[0] | |
92 | if os.path.exists(rsp) and ( string.find(open(rsp).read(), "zzz") != -1 ): | |
93 | pass | |
94 | elif string.find(t.stdout(), "zzz") != -1: | |
95 | pass | |
96 | else: | |
97 | t.fail_test(1) | |
98 | ||
99 | # Test main -> libb -> liba chain in the case where liba is a file and not a | |
100 | # Boost.Build target. | |
101 | t.rm(".") | |
102 | ||
103 | t.write("jamroot.jam", "") | |
104 | t.write("a/jamfile.jam", """\ | |
105 | lib a : a.cpp ; | |
106 | install dist : a ; | |
107 | """) | |
108 | ||
109 | t.write("a/a.cpp", """\ | |
110 | #if defined(_WIN32) | |
111 | __declspec(dllexport) | |
112 | #endif | |
113 | void a() {} | |
114 | """) | |
115 | ||
116 | t.run_build_system(subdir="a") | |
117 | t.expect_addition("a/dist/a.dll") | |
118 | ||
119 | if ( os.name == 'nt' or os.uname()[0].lower().startswith('cygwin') ) and \ | |
120 | BoostBuild.get_toolset() != 'gcc': | |
121 | # This is a Windows import library -- we know the exact name. | |
122 | file = "a/dist/a.lib" | |
123 | else: | |
124 | file = t.adjust_names("a/dist/a.dll")[0] | |
125 | ||
126 | t.write("b/jamfile.jam", "lib b : b.cpp ../%s ;" % file) | |
127 | ||
128 | t.write("b/b.cpp", """\ | |
129 | #if defined(_WIN32) | |
130 | __declspec(dllimport) | |
131 | #endif | |
132 | void a(); | |
133 | #if defined(_WIN32) | |
134 | __declspec(dllexport) | |
135 | #endif | |
136 | void b() { a(); } | |
137 | """) | |
138 | ||
139 | t.write("jamroot.jam", "exe main : main.cpp b//b ;") | |
140 | ||
141 | t.write("main.cpp", """\ | |
142 | #if defined(_WIN32) | |
143 | __declspec(dllimport) | |
144 | #endif | |
145 | void b(); | |
146 | int main() { b(); } | |
147 | """) | |
148 | ||
149 | t.run_build_system() | |
150 | t.expect_addition("bin/$toolset/debug/main.exe") | |
151 | ||
152 | t.cleanup() |