| 1 |
project('linkcustom', 'c') |
| 2 |
|
| 3 |
# This would require passing the static linker to the build script or having |
| 4 |
# it detect it by itself. I'm too lazy to implement it now and it is not |
| 5 |
# really needed for testing that custom targets work. It is the responsibility |
| 6 |
# of the custom target to produce things in the correct format. |
| 7 |
assert(not meson.is_cross_build(), |
| 8 |
'MESON_SKIP_TEST cross checking not implemented.') |
| 9 |
|
| 10 |
cc = meson.get_compiler('c') |
| 11 |
genprog = find_program('custom_stlib.py') |
| 12 |
|
| 13 |
clib = custom_target('linkcustom', |
| 14 |
output: 'libflob.a', |
| 15 |
command: [genprog, |
| 16 |
'-o', '@OUTPUT@', |
| 17 |
'--private-dir', '@PRIVATE_DIR@'] + cc.cmd_array()) |
| 18 |
|
| 19 |
# custom_target tests |
| 20 |
|
| 21 |
exe = executable('prog', 'prog.c', link_with: clib) |
| 22 |
test('linkcustom', exe) |
| 23 |
|
| 24 |
d = declare_dependency(link_with: clib) |
| 25 |
|
| 26 |
exe2 = executable('prog2', 'prog.c', dependencies: d) |
| 27 |
test('linkcustom2', exe2) |
| 28 |
|
| 29 |
# Link whole tests |
| 30 |
|
| 31 |
if meson.backend() == 'xcode' |
| 32 |
message('Xcode does not support link whole so skipping.') |
| 33 |
else |
| 34 |
exe3 = executable('prog3', 'prog.c', link_whole: clib) |
| 35 |
test('linkwhole', exe) |
| 36 |
|
| 37 |
d2 = declare_dependency(link_whole: clib) |
| 38 |
|
| 39 |
exe4 = executable('prog4', 'prog.c', dependencies: d2) |
| 40 |
test('linkwhole2', exe2) |
| 41 |
endif |
| 42 |
|
| 43 |
# custom_target[i] tests |
| 44 |
|
| 45 |
exe_i = executable('prog_i', 'prog.c', link_with: clib[0]) |
| 46 |
test('linkcustom', exe_i) |
| 47 |
|
| 48 |
d_i = declare_dependency(link_with: clib[0]) |
| 49 |
|
| 50 |
exe2_i = executable('prog2_i', 'prog.c', dependencies: d_i) |
| 51 |
test('linkcustom2_i', exe2_i) |
| 52 |
|
| 53 |
# Link whole tests |
| 54 |
|
| 55 |
if meson.backend() == 'xcode' |
| 56 |
message('Xcode does not support link whole so skipping.') |
| 57 |
else |
| 58 |
shared_library('lib1', 'lib.c', link_whole: clib) |
| 59 |
|
| 60 |
exe3_i = executable('prog3_i', 'prog.c', link_whole: clib[0]) |
| 61 |
test('linkwhole', exe) |
| 62 |
|
| 63 |
d2_i = declare_dependency(link_whole: clib[0]) |
| 64 |
|
| 65 |
exe4_i = executable('prog4_i', 'prog.c', dependencies: d2_i) |
| 66 |
test('linkwhole2_i', exe2_i) |
| 67 |
endif |
| 68 |
|
| 69 |
# Link with custom target |
| 70 |
|
| 71 |
dummy = static_library('dummy', 'dummy.c') |
| 72 |
|
| 73 |
custom_prog = find_program('custom_target.py') |
| 74 |
t = custom_target('custom', input: dummy, output: 'libcustom.a', command: [custom_prog, '@INPUT@', '@OUTPUT@']) |
| 75 |
|
| 76 |
dep1 = declare_dependency(link_with: t) |
| 77 |
dep2 = declare_dependency(link_with: t[0]) |
| 78 |
|
| 79 |
lib1 = static_library('lib1', 'outerlib.c', dependencies: dep1) |
| 80 |
lib2 = static_library('lib2', 'outerlib.c', dependencies: dep2) |
| 81 |
|
| 82 |
exe1 = executable('exe1', 'custom_target.c', link_with: lib1) |
| 83 |
test('custom_target_1', exe1) |
| 84 |
|
| 85 |
exe1_2 = executable('exe1_2', 'custom_target.c', link_with: lib2) |
| 86 |
test('custom_target_2', exe2) |
| 87 |
|
| 88 |
# Link with custom target containing a SONAME |
| 89 |
dummy3 = shared_library('dummy3', 'dummy.c', version: '1.0') |
| 90 |
t = custom_target(input: dummy, output: 'libcustom@PLAINNAME@', command: [custom_prog, '@INPUT@', '@OUTPUT@']) |
| 91 |
lib3 = static_library('lib3', 'outerlib.c', link_with: t) |
| 92 |
exe3 = executable('exe3', 'custom_target.c', link_with: lib3) |
| 93 |
test('custom_target_3', exe3) |