1 | #!/usr/bin/python |
---|
2 | |
---|
3 | # Test usage of searched-libs: one which are found via -l |
---|
4 | # switch to the linker/compiler. |
---|
5 | |
---|
6 | from BoostBuild import Tester, get_toolset |
---|
7 | import string |
---|
8 | import os |
---|
9 | t = Tester() |
---|
10 | |
---|
11 | # To start with, we have to prepate a library to link with |
---|
12 | t.write("lib/project-root.jam", "") |
---|
13 | t.write("lib/Jamfile", "lib test_lib : test_lib.cpp ;") |
---|
14 | t.write("lib/test_lib.cpp", """ |
---|
15 | #ifdef _WIN32 |
---|
16 | __declspec(dllexport) |
---|
17 | #endif |
---|
18 | void foo() {} |
---|
19 | """); |
---|
20 | |
---|
21 | t.run_build_system(subdir="lib") |
---|
22 | t.expect_addition("lib/bin/$toolset/debug/test_lib.dll") |
---|
23 | |
---|
24 | # Auto adjusting of suffixes does not work, since we need to |
---|
25 | # change dll to lib. |
---|
26 | # |
---|
27 | if (os.name == 'nt' or os.uname()[0].lower().startswith('cygwin')) and get_toolset() != 'gcc': |
---|
28 | t.copy("lib/bin/$toolset/debug/test_lib.lib", "lib/test_lib.lib") |
---|
29 | else: |
---|
30 | t.copy("lib/bin/$toolset/debug/test_lib.dll", "lib/test_lib.dll") |
---|
31 | |
---|
32 | |
---|
33 | # Test that the simplest usage of searched library works. |
---|
34 | t.write('project-root.jam', '') |
---|
35 | t.write('Jamfile', """ |
---|
36 | |
---|
37 | import path ; |
---|
38 | import project ; |
---|
39 | |
---|
40 | local here = [ project.attribute $(__name__) location ] ; |
---|
41 | here = [ path.root $(here) [ path.pwd ] ] ; |
---|
42 | |
---|
43 | exe main : main.cpp helper ; |
---|
44 | lib helper : helper.cpp test_lib : <dll-path>$(here)/lib ; |
---|
45 | lib test_lib : : <name>test_lib <search>lib ; |
---|
46 | """) |
---|
47 | t.write("main.cpp", """ |
---|
48 | void helper(); |
---|
49 | int main() { helper(); return 0; } |
---|
50 | """) |
---|
51 | t.write("helper.cpp", """ |
---|
52 | void foo(); |
---|
53 | |
---|
54 | void |
---|
55 | #if defined(_WIN32) |
---|
56 | __declspec(dllexport) |
---|
57 | #endif |
---|
58 | helper() { foo(); } |
---|
59 | """) |
---|
60 | t.run_build_system(stderr=None) # gcc warns about libraries which are not in -rpath. |
---|
61 | t.expect_addition("bin/$toolset/debug/main.exe") |
---|
62 | t.rm("bin/$toolset/debug/main.exe") |
---|
63 | |
---|
64 | # Now try using searched lib from static lib. Request shared version |
---|
65 | # of searched lib, since we don't have static one handy. |
---|
66 | t.write('Jamfile', """ |
---|
67 | exe main : main.cpp helper ; |
---|
68 | lib helper : helper.cpp test_lib/<link>shared : <link>static ; |
---|
69 | lib test_lib : : <name>test_lib <search>lib ; |
---|
70 | """) |
---|
71 | t.run_build_system(stderr=None) |
---|
72 | t.expect_addition("bin/$toolset/debug/main.exe") |
---|
73 | t.expect_addition("bin/$toolset/debug/link-static/helper.lib") |
---|
74 | t.rm("bin/$toolset/debug/main.exe") |
---|
75 | |
---|
76 | # A regression test: <library>property referring to |
---|
77 | # searched-lib was mishandled. As the result, we were |
---|
78 | # putting target name to the command line! |
---|
79 | # Note that |
---|
80 | # g++ ...... <.>z |
---|
81 | # works nicely in some cases, sending output from compiler |
---|
82 | # to file 'z'. |
---|
83 | # This problem shows up when searched libs are in usage |
---|
84 | # requirements. |
---|
85 | |
---|
86 | t.write('Jamfile', 'exe main : main.cpp d/d2//a ;') |
---|
87 | t.write('main.cpp',""" |
---|
88 | void foo(); |
---|
89 | int main() { foo(); return 0; } |
---|
90 | |
---|
91 | """) |
---|
92 | t.write('d/d2/Jamfile', """ |
---|
93 | lib test_lib : : <name>test_lib <search>../../lib ; |
---|
94 | lib a : a.cpp : : : <library>test_lib ; |
---|
95 | """) |
---|
96 | t.write('d/d2/a.cpp', """ |
---|
97 | #ifdef _WIN32 |
---|
98 | __declspec(dllexport) int force_library_creation_for_a; |
---|
99 | #endif |
---|
100 | """) |
---|
101 | |
---|
102 | t.run_build_system() |
---|
103 | |
---|
104 | # A regression test. Searched targets were not associated |
---|
105 | # with any properties. For that reason, if the same searched |
---|
106 | # lib is generated with two different properties, we had an |
---|
107 | # error saying they are actualized to the same Jam target name. |
---|
108 | |
---|
109 | t.write("project-root.jam", "") |
---|
110 | |
---|
111 | t.write("a.cpp", "") |
---|
112 | |
---|
113 | # The 'l' library will be built in two variants: |
---|
114 | # 'debug' (directly requested) and 'release' (requested |
---|
115 | # from 'a'). |
---|
116 | t.write("Jamfile", """ |
---|
117 | exe a : a.cpp l/<variant>release ; |
---|
118 | |
---|
119 | lib l : : <name>l_d <variant>debug ; |
---|
120 | lib l : : <name>l_r <variant>release ; |
---|
121 | """) |
---|
122 | |
---|
123 | t.run_build_system("-n") |
---|
124 | |
---|
125 | # A regression test. Two virtual target with the same properties |
---|
126 | # were created for 'l' target, which caused and error to be reported |
---|
127 | # when actualizing targets. The final error is correct, but we should |
---|
128 | # not create two duplicated targets. Thanks to Andre Hentz |
---|
129 | # for finding this bug. |
---|
130 | t.write("project-root.jam", "") |
---|
131 | |
---|
132 | t.write("a.cpp", "") |
---|
133 | |
---|
134 | t.write("Jamfile", """ |
---|
135 | project a : requirements <runtime-link>static ; |
---|
136 | |
---|
137 | static-lib a : a.cpp l ; |
---|
138 | lib l : : <name>l_f ; |
---|
139 | """) |
---|
140 | |
---|
141 | t.run_build_system("-n") |
---|
142 | |
---|
143 | t.cleanup() |
---|