Merge pull request #1545 from centricular/dont-link-recursively
Don't add dependencies recursively while linkingpull/1730/merge
commit
62051626a5
32 changed files with 377 additions and 53 deletions
@ -0,0 +1,8 @@ |
||||
#include "../lib.h" |
||||
|
||||
int get_@DEPENDENCY@dep_value (void); |
||||
|
||||
SYMBOL_EXPORT |
||||
int get_@LIBTYPE@@DEPENDENCY@dep_value (void) { |
||||
return get_@DEPENDENCY@dep_value (); |
||||
} |
@ -0,0 +1,16 @@ |
||||
#include <stdio.h> |
||||
|
||||
#include "../lib.h" |
||||
|
||||
SYMBOL_IMPORT int get_@LIBTYPE@@DEPENDENCY@dep_value (void); |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
int val; |
||||
|
||||
val = get_@LIBTYPE@@DEPENDENCY@dep_value (); |
||||
if (val != @VALUE@) { |
||||
printf("@LIBTYPE@@DEPENDENCY@ was %i instead of @VALUE@\n", val); |
||||
return -1; |
||||
} |
||||
return 0; |
||||
} |
@ -0,0 +1,49 @@ |
||||
dep3_libs = [] |
||||
|
||||
# Permutate all combinations of shared and static libraries up to three levels |
||||
# executable -> shared -> static -> shared (etc) |
||||
foreach dep2 : ['sh', 'st'] |
||||
foreach dep1 : ['sh', 'st'] |
||||
foreach libtype : ['sh', 'st'] |
||||
name = libtype + dep1 + dep2 |
||||
if dep2 == 'sh' |
||||
libret = 1 |
||||
elif dep2 == 'st' |
||||
libret = 2 |
||||
else |
||||
error('Unknown dep2 "@0@"'.format(dep2)) |
||||
endif |
||||
|
||||
if libtype == 'sh' |
||||
target = 'shared_library' |
||||
build_args = [] |
||||
elif libtype == 'st' |
||||
target = 'static_library' |
||||
build_args = ['-DMESON_STATIC_BUILD'] |
||||
else |
||||
error('Unknown libtype "@0@"'.format(libtype)) |
||||
endif |
||||
|
||||
cdata = configuration_data() |
||||
cdata.set('DEPENDENCY', dep1 + dep2) |
||||
cdata.set('LIBTYPE', libtype) |
||||
cdata.set('VALUE', libret) |
||||
|
||||
lib_c = configure_file(input : 'lib.c.in', |
||||
output : name + '-lib.c', |
||||
configuration : cdata) |
||||
dep = get_variable(dep1 + dep2 + 'dep') |
||||
dep3_lib = build_target(name, lib_c, link_with : dep, |
||||
target_type : target, |
||||
c_args : build_args) |
||||
dep3_libs += [dep3_lib] |
||||
|
||||
main_c = configure_file(input : 'main.c.in', |
||||
output : name + '-main.c', |
||||
configuration : cdata) |
||||
dep3_bin = executable(name, main_c, link_with : dep3_lib, |
||||
c_args : build_args) |
||||
test(name + 'test', dep3_bin) |
||||
endforeach |
||||
endforeach |
||||
endforeach |
@ -0,0 +1,6 @@ |
||||
int get_st2_prop (void); |
||||
int get_st3_prop (void); |
||||
|
||||
int get_st1_value (void) { |
||||
return get_st2_prop () + get_st3_prop (); |
||||
} |
@ -0,0 +1,6 @@ |
||||
int get_st1_prop (void); |
||||
int get_st3_prop (void); |
||||
|
||||
int get_st2_value (void) { |
||||
return get_st1_prop () + get_st3_prop (); |
||||
} |
@ -0,0 +1,6 @@ |
||||
int get_st1_prop (void); |
||||
int get_st2_prop (void); |
||||
|
||||
int get_st3_value (void) { |
||||
return get_st1_prop () + get_st2_prop (); |
||||
} |
@ -0,0 +1,28 @@ |
||||
#include <stdio.h> |
||||
|
||||
#include "../lib.h" |
||||
|
||||
int get_st1_value (void); |
||||
int get_st2_value (void); |
||||
int get_st3_value (void); |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
int val; |
||||
|
||||
val = get_st1_value (); |
||||
if (val != 5) { |
||||
printf("st1 value was %i instead of 5\n", val); |
||||
return -1; |
||||
} |
||||
val = get_st2_value (); |
||||
if (val != 4) { |
||||
printf("st2 value was %i instead of 4\n", val); |
||||
return -2; |
||||
} |
||||
val = get_st3_value (); |
||||
if (val != 3) { |
||||
printf("st3 value was %i instead of 3\n", val); |
||||
return -3; |
||||
} |
||||
return 0; |
||||
} |
@ -0,0 +1,5 @@ |
||||
st1 = static_library('st1', 'lib1.c', 'prop1.c') |
||||
st2 = static_library('st2', 'lib2.c', 'prop2.c') |
||||
st3 = static_library('st3', 'lib3.c', 'prop3.c') |
||||
|
||||
test('circular', executable('circular', 'main.c', link_with : [st1, st2, st3])) |
@ -0,0 +1,3 @@ |
||||
int get_st1_prop (void) { |
||||
return 1; |
||||
} |
@ -0,0 +1,3 @@ |
||||
int get_st2_prop (void) { |
||||
return 2; |
||||
} |
@ -0,0 +1,3 @@ |
||||
int get_st3_prop (void) { |
||||
return 3; |
||||
} |
@ -0,0 +1,17 @@ |
||||
#if defined _WIN32 |
||||
#ifdef MESON_STATIC_BUILD |
||||
#define SYMBOL_EXPORT |
||||
#define SYMBOL_IMPORT |
||||
#else |
||||
#define SYMBOL_IMPORT __declspec(dllimport) |
||||
#define SYMBOL_EXPORT __declspec(dllexport) |
||||
#endif |
||||
#else |
||||
#define SYMBOL_IMPORT |
||||
#if defined __GNUC__ |
||||
#define SYMBOL_EXPORT __attribute__ ((visibility("default"))) |
||||
#else |
||||
#pragma message ("Compiler does not support symbol visibility.") |
||||
#define SYMBOL_EXPORT |
||||
#endif |
||||
#endif |
@ -0,0 +1,46 @@ |
||||
#include <stdio.h> |
||||
|
||||
#include "lib.h" |
||||
|
||||
int get_stnodep_value (void); |
||||
int get_stshdep_value (void); |
||||
int get_ststdep_value (void); |
||||
SYMBOL_IMPORT int get_shnodep_value (void); |
||||
SYMBOL_IMPORT int get_shshdep_value (void); |
||||
SYMBOL_IMPORT int get_shstdep_value (void); |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
int val; |
||||
|
||||
val = get_shnodep_value (); |
||||
if (val != 1) { |
||||
printf("shnodep was %i instead of 1\n", val); |
||||
return -1; |
||||
} |
||||
val = get_stnodep_value (); |
||||
if (val != 2) { |
||||
printf("stnodep was %i instead of 2\n", val); |
||||
return -2; |
||||
} |
||||
val = get_shshdep_value (); |
||||
if (val != 1) { |
||||
printf("shshdep was %i instead of 1\n", val); |
||||
return -3; |
||||
} |
||||
val = get_shstdep_value (); |
||||
if (val != 2) { |
||||
printf("shstdep was %i instead of 2\n", val); |
||||
return -4; |
||||
} |
||||
val = get_stshdep_value (); |
||||
if (val != 1) { |
||||
printf("shstdep was %i instead of 1\n", val); |
||||
return -5; |
||||
} |
||||
val = get_ststdep_value (); |
||||
if (val != 2) { |
||||
printf("ststdep was %i instead of 2\n", val); |
||||
return -6; |
||||
} |
||||
return 0; |
||||
} |
@ -0,0 +1,26 @@ |
||||
project('recursive dependencies', 'c') |
||||
|
||||
# Test that you can link a shared executable to: |
||||
# - A shared library with no other deps |
||||
subdir('shnodep') |
||||
# - A static library with no other deps |
||||
subdir('stnodep') |
||||
# - A shared library with a shared library dep |
||||
subdir('shshdep') |
||||
# - A shared library with a static library dep |
||||
subdir('shstdep') |
||||
# - A static library with a shared library dep |
||||
subdir('stshdep') |
||||
# - A static library with a static library dep |
||||
subdir('ststdep') |
||||
|
||||
test('alldeps', |
||||
executable('alldeps', 'main.c', |
||||
link_with : [shshdep, shstdep, ststdep, stshdep])) |
||||
|
||||
# More combinations of static and shared libraries |
||||
subdir('3rdorderdeps') |
||||
|
||||
# Circular dependencies between static libraries |
||||
# This requires the use of --start/end-group with GNU ld |
||||
subdir('circular') |
@ -0,0 +1,6 @@ |
||||
#include "../lib.h" |
||||
|
||||
SYMBOL_EXPORT |
||||
int get_shnodep_value (void) { |
||||
return 1; |
||||
} |
@ -0,0 +1 @@ |
||||
shnodep = shared_library('shnodep', 'lib.c') |
@ -0,0 +1,8 @@ |
||||
#include "../lib.h" |
||||
|
||||
int get_shnodep_value (void); |
||||
|
||||
SYMBOL_EXPORT |
||||
int get_shshdep_value (void) { |
||||
return get_shnodep_value (); |
||||
} |
@ -0,0 +1 @@ |
||||
shshdep = shared_library('shshdep', 'lib.c', link_with : shnodep) |
@ -0,0 +1,8 @@ |
||||
#include "../lib.h" |
||||
|
||||
int get_stnodep_value (void); |
||||
|
||||
SYMBOL_EXPORT |
||||
int get_shstdep_value (void) { |
||||
return get_stnodep_value (); |
||||
} |
@ -0,0 +1 @@ |
||||
shstdep = shared_library('shstdep', 'lib.c', link_with : stnodep) |
@ -0,0 +1,6 @@ |
||||
#include "../lib.h" |
||||
|
||||
SYMBOL_EXPORT |
||||
int get_stnodep_value (void) { |
||||
return 2; |
||||
} |
@ -0,0 +1,2 @@ |
||||
stnodep = static_library('stnodep', 'lib.c', |
||||
c_args : '-DMESON_STATIC_BUILD') |
@ -0,0 +1,8 @@ |
||||
#include "../lib.h" |
||||
|
||||
int get_shnodep_value (void); |
||||
|
||||
SYMBOL_EXPORT |
||||
int get_stshdep_value (void) { |
||||
return get_shnodep_value (); |
||||
} |
@ -0,0 +1,2 @@ |
||||
stshdep = static_library('stshdep', 'lib.c', link_with : shnodep, |
||||
c_args : '-DMESON_STATIC_BUILD') |
@ -0,0 +1,8 @@ |
||||
#include "../lib.h" |
||||
|
||||
int get_stnodep_value (void); |
||||
|
||||
SYMBOL_EXPORT |
||||
int get_ststdep_value (void) { |
||||
return get_stnodep_value (); |
||||
} |
@ -0,0 +1,2 @@ |
||||
ststdep = static_library('ststdep', 'lib.c', link_with : stnodep, |
||||
c_args : '-DMESON_STATIC_BUILD') |
Loading…
Reference in new issue