-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix linking of shared/static libs with static libs
This commit contains the following fixes: 1. When a shared library A does `link_with:` to static library B, the parts of B used by A will be added to A, and so we don't need to return B in A.get_dependencies() for targets that link to A. This already is the behaviour when a shared library A does `link_whole:` on B. 2. In situation (1), when generating a pkg-config file for A, we must also not add B to Libs.private for A. This already is the behaviour when a shared library A does `link_whole:` on B. 3. When a static library A does `link_whole:` to static library B, we must add the objects in B to A. 4. When a static library A does `link_with:` to static library B, and B is not installed (which makes it an internal static library), we must add the objects in B to A, otherwise nothing can use A. 5. In situation (4), when generating a pkg-config file for A, we must also not add B to Libs.private for A. All these situations are tested by the unit test added in this commit. Closes #3934 Closes #3937
- Loading branch information
Showing
13 changed files
with
253 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
test cases/unit/35 both library usability/consumer/meson.build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
project('both libraries consumer', 'c') | ||
|
||
d1 = dependency('whole-installed') | ||
d2 = dependency('whole-internal') | ||
d3 = dependency('with-installed') | ||
d4 = dependency('with-internal') | ||
|
||
test('both-whole-installed', executable('tester1', 'tester.c', dependencies : d1)) | ||
test('both-whole-internal', executable('tester2', 'tester.c', dependencies : d2)) | ||
test('both-with-installed', executable('tester3', 'tester.c', dependencies : d3)) | ||
test('both-with-internal', executable('tester4', 'tester.c', dependencies : d4)) |
17 changes: 17 additions & 0 deletions
17
test cases/unit/35 both library usability/consumer/tester.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <stdio.h> | ||
|
||
#if defined(_MSC_VER) && !defined(PROVIDER_STATIC) | ||
__declspec(dllimport) | ||
#endif | ||
int both_get_dat_value (void); | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
int got = both_get_dat_value (); | ||
|
||
if (got != 111) { | ||
printf ("Got %i instead of 111\n", got); | ||
return 2; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#if defined(_MSC_VER) && !defined(PROVIDER_STATIC) | ||
__declspec(dllimport) | ||
#endif | ||
int get_dat_value (void); | ||
|
||
#ifdef INSTALLED_LIBRARY | ||
#define EXPECTED_VALUE 69 | ||
#else | ||
#define EXPECTED_VALUE 42 | ||
#endif | ||
|
||
#if defined(_MSC_VER) && !defined(PROVIDER_STATIC) | ||
__declspec(dllexport) | ||
#endif | ||
int both_get_dat_value (void) | ||
{ | ||
if (get_dat_value () != EXPECTED_VALUE) | ||
return 666; | ||
return 111; | ||
} |
36 changes: 36 additions & 0 deletions
36
test cases/unit/35 both library usability/provider/meson.build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
project('both library provider', 'c') | ||
|
||
pkg = import('pkgconfig') | ||
|
||
subdir('otherlib') | ||
|
||
# Both libraries with a link_whole dependency on an installed static library | ||
l1 = library('whole-installed', 'both.c', | ||
c_args : ['-DINSTALLED_LIBRARY'], | ||
link_whole : installed_lib, | ||
install: true) | ||
pkg.generate(l1) | ||
|
||
# Both libraries with a link_whole dependency on a not-installed static library | ||
l2 = library('whole-internal', 'both.c', | ||
link_whole : internal_lib, | ||
install: true) | ||
pkg.generate(l2) | ||
|
||
# Both libraries with a link_with dependency on an installed static library | ||
l3 = library('with-installed', 'both.c', | ||
c_args : ['-DINSTALLED_LIBRARY'], | ||
link_with : installed_lib, | ||
install: true) | ||
pkg.generate(l3) | ||
|
||
# Both libraries with a link_with dependency on a not-installed static library | ||
l4 = library('with-internal', 'both.c', | ||
link_with : internal_lib, | ||
install: true) | ||
pkg.generate(l4) | ||
|
||
test('test-both-whole-installed', executable('tester1', 'tester.c', link_with : l1)) | ||
test('test-both-whole-internal', executable('tester2', 'tester.c', link_with : l2)) | ||
test('test-both-with-installed', executable('tester3', 'tester.c', link_with : l3)) | ||
test('test-both-with-internal', executable('tester4', 'tester.c', link_with : l4)) |
7 changes: 7 additions & 0 deletions
7
test cases/unit/35 both library usability/provider/otherlib/installed.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#if defined(_MSC_VER) && !defined(PROVIDER_STATIC) | ||
__declspec(dllexport) | ||
#endif | ||
int get_dat_value (void) | ||
{ | ||
return 69; | ||
} |
7 changes: 7 additions & 0 deletions
7
test cases/unit/35 both library usability/provider/otherlib/internal.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#if defined(_MSC_VER) && !defined(PROVIDER_STATIC) | ||
__declspec(dllexport) | ||
#endif | ||
int get_dat_value (void) | ||
{ | ||
return 42; | ||
} |
3 changes: 3 additions & 0 deletions
3
test cases/unit/35 both library usability/provider/otherlib/meson.build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
internal_lib = static_library('internal-some', 'internal.c') | ||
|
||
installed_lib = static_library('installed-some', 'installed.c', install: true) |
14 changes: 14 additions & 0 deletions
14
test cases/unit/35 both library usability/provider/tester.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdio.h> | ||
|
||
int both_get_dat_value (void); | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
int got = both_get_dat_value (); | ||
|
||
if (got != 111) { | ||
printf ("Got %i instead of 111\n", got); | ||
return 2; | ||
} | ||
return 0; | ||
} |