| 1 |
project('complex link cases', 'c') |
| 2 |
|
| 3 |
cc = meson.get_compiler('c') |
| 4 |
|
| 5 |
# In all tests, e1 uses s3 which uses s2 which uses s1. |
| 6 |
|
| 7 |
# Executable links with s3 and s1 but not s2 because it is included in s3. |
| 8 |
s1 = static_library('t1-s1', 's1.c') |
| 9 |
s2 = static_library('t1-s2', 's2.c', link_with: s1) |
| 10 |
s3 = static_library('t1-s3', 's3.c', link_whole: s2) |
| 11 |
e = executable('t1-e1', 'main.c', link_with: s3) |
| 12 |
|
| 13 |
# s3 is installed but not s1 so it has to include s1 too. |
| 14 |
# Executable links only s3 because it contains s1 and s2. |
| 15 |
s1 = static_library('t2-s1', 's1.c') |
| 16 |
s2 = static_library('t2-s2', 's2.c', link_with: s1) |
| 17 |
s3 = static_library('t2-s3', 's3.c', link_whole: s2, install: true) |
| 18 |
e = executable('t2-e1', 'main.c', link_with: s3) |
| 19 |
|
| 20 |
# Executable needs to link with s3 only |
| 21 |
s1 = static_library('t3-s1', 's1.c') |
| 22 |
s2 = static_library('t3-s2', 's2.c', link_with: s1) |
| 23 |
s3 = shared_library('t3-s3', 's3.c', link_with: s2) |
| 24 |
e = executable('t3-e1', 'main.c', link_with: s3) |
| 25 |
|
| 26 |
# Executable needs to link with s3 and s2 |
| 27 |
s1 = static_library('t4-s1', 's1.c') |
| 28 |
s2 = shared_library('t4-s2', 's2.c', link_with: s1) |
| 29 |
s3 = static_library('t4-s3', 's3.c', link_with: s2) |
| 30 |
e = executable('t4-e1', 'main.c', link_with: s3) |
| 31 |
|
| 32 |
# Executable needs to link with s3 and s1 |
| 33 |
s1 = shared_library('t5-s1', 's1.c') |
| 34 |
s2 = static_library('t5-s2', 's2.c', link_with: s1) |
| 35 |
s3 = static_library('t5-s3', 's3.c', link_with: s2, install: true) |
| 36 |
e = executable('t5-e1', 'main.c', link_with: s3) |
| 37 |
|
| 38 |
# Executable needs to link with s3 and s2 |
| 39 |
s1 = static_library('t6-s1', 's1.c') |
| 40 |
s2 = static_library('t6-s2', 's2.c', link_with: s1, install: true) |
| 41 |
s3 = static_library('t6-s3', 's3.c', link_with: s2, install: true) |
| 42 |
e = executable('t6-e1', 'main.c', link_with: s3) |
| 43 |
|
| 44 |
# Regression test: s1 gets promoted to link_whole and that used to make all other |
| 45 |
# libraries in the list (s2) to be ignored. |
| 46 |
# Executable only needs to link with s3. |
| 47 |
# See https://github.com/mesonbuild/meson/issues/11956. |
| 48 |
s1 = static_library('t7-s1', 's1.c') |
| 49 |
s2 = static_library('t7-s2', 's2.c') |
| 50 |
s3 = static_library('t7-s3', 's3.c', link_with: [s1, s2], install: true) |
| 51 |
e = executable('t7-e1', 'main.c', link_with: s3) |
| 52 |
|
| 53 |
# Regression test: s3 should come last in the linker command. This seems to be |
| 54 |
# required for at least backward compatibility reasons: |
| 55 |
# https://github.com/mesonbuild/meson/pull/11957#issuecomment-1629243208 |
| 56 |
s1 = static_library('t8-s1', 's1.c') |
| 57 |
s2 = static_library('t8-s2', 's2.c') |
| 58 |
s3 = static_library('t8-s3', 's3.c') |
| 59 |
e = executable('t8-e1', 'main.c', |
| 60 |
link_with: [s1, s2], |
| 61 |
dependencies: declare_dependency(link_with: s3), |
| 62 |
) |
| 63 |
|
| 64 |
if cc.get_argument_syntax() == 'gcc' |
| 65 |
# s1 is an internal static library, using custom target. |
| 66 |
s1_o = custom_target( |
| 67 |
input: 's1.c', |
| 68 |
output: 's1.c.o', |
| 69 |
command: [cc.cmd_array(), '-c', '-o', '@OUTPUT@', '@INPUT@'] |
| 70 |
) |
| 71 |
s1 = custom_target( |
| 72 |
output: 'libt9-s1.a', |
| 73 |
command: ['ar', 'rcs', '@OUTPUT@', s1_o], |
| 74 |
) |
| 75 |
|
| 76 |
# Executable needs to link with s1, s2 and s3. |
| 77 |
s2 = static_library('t9-s2', 's2.c', link_with: s1) |
| 78 |
s3 = static_library('t9-s3', 's3.c', link_with: s2) |
| 79 |
e = executable('t9-e1', 'main.c', link_with: s3) |
| 80 |
|
| 81 |
# s2 cannot be installed because s1 is not being installed and Meson cannot |
| 82 |
# extract object files from the custom target. |
| 83 |
testcase expect_error('Cannot link_whole a custom or Rust target \'libt9-s1.a\' into a static library \'t10-s2\'. Instead, pass individual object files with the "objects:" keyword argument if possible. Meson had to promote link to link_whole because \'t10-s2\' is installed but not \'libt9-s1.a\', and thus has to include objects from \'libt9-s1.a\' to be usable.') |
| 84 |
s2 = static_library('t10-s2', 's2.c', link_with: s1, install: true) |
| 85 |
endtestcase |
| 86 |
|
| 87 |
# s3 cannot be installed because s1 is not being installed and Meson cannot |
| 88 |
# extract object files from the custom target. |
| 89 |
testcase expect_error('Cannot link_whole a custom or Rust target \'libt9-s1.a\' into a static library \'t11-s3\'. Instead, pass individual object files with the "objects:" keyword argument if possible. Meson had to promote link to link_whole because \'t11-s3\' is installed but not \'libt9-s1.a\', and thus has to include objects from \'libt9-s1.a\' to be usable.') |
| 90 |
s2 = static_library('t11-s2', 's2.c', link_with: s1) |
| 91 |
s3 = static_library('t11-s3', 's3.c', link_with: s2, install: true) |
| 92 |
endtestcase |
| 93 |
|
| 94 |
# s1 is an installed static library, using custom target. |
| 95 |
s1 = custom_target( |
| 96 |
output: 'libt12-s1.a', |
| 97 |
command: ['ar', 'rcs', '@OUTPUT@', s1_o], |
| 98 |
install: true, |
| 99 |
install_dir: get_option('libdir'), |
| 100 |
) |
| 101 |
|
| 102 |
# Executable needs to link with s1, s2 and s3. |
| 103 |
s2 = static_library('t12-s2', 's2.c', link_with: s1, install: true) |
| 104 |
s3 = static_library('t12-s3', 's3.c', link_with: s2) |
| 105 |
e = executable('t12-e1', 'main.c', link_with: s3) |
| 106 |
|
| 107 |
# Executable links with s3 and s1 but not s2 because it is included in s3. |
| 108 |
s2 = static_library('t13-s2', 's2.c', link_with: s1) |
| 109 |
s3 = static_library('t13-s3', 's3.c', link_with: s2, install: true) |
| 110 |
e = executable('t13-e1', 'main.c', link_with: s3) |
| 111 |
endif |