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