| 1 |
project('cmakeSubTest_advanced', ['c', 'cpp'], meson_version: '>= 1.12.0') |
| 2 |
|
| 3 |
dep_test = dependency('ZLIB', method: 'cmake', required: false) |
| 4 |
if not dep_test.found() |
| 5 |
error('MESON_SKIP_TEST: zlib is not installed') |
| 6 |
endif |
| 7 |
|
| 8 |
cm = import('cmake') |
| 9 |
|
| 10 |
# Test the "normal" subproject call |
| 11 |
sub_pro = cm.subproject('cmMod') |
| 12 |
sub_dep = sub_pro.dependency('cmModLib') |
| 13 |
sub_sta = sub_pro.dependency('cmModLibStatic') |
| 14 |
|
| 15 |
# Build some files |
| 16 |
exe1 = executable('main1', ['main.cpp'], dependencies: [sub_dep]) |
| 17 |
exe2 = executable('main2', ['main.cpp'], dependencies: [sub_sta]) |
| 18 |
slib = shared_library('slib', ['slib.cpp'], dependencies: [sub_dep]) |
| 19 |
exe3 = executable('main3', ['main3.cpp'], link_with: slib) |
| 20 |
test('test1', exe1) |
| 21 |
test('test2', exe2) |
| 22 |
|
| 23 |
# Test if we can also extract executables |
| 24 |
assert(sub_pro.target_type('testEXE') == 'executable', 'The type must be executable for obvious reasons') |
| 25 |
test('test3', sub_pro.target('testEXE')) |
| 26 |
|
| 27 |
# Test that we can add a new target with the same name as the CMake subproject |
| 28 |
exe4 = executable('testEXE', ['main.cpp'], dependencies: [sub_sta]) |
| 29 |
test('test4', exe4) |
| 30 |
|
| 31 |
# Test if libraries are named correctly |
| 32 |
assert(sub_pro.target_type('cmModLib') == 'shared_library', 'Type should be shared_library') |
| 33 |
expected_soversion_str = '1' |
| 34 |
expected_version_str = '1.0.1' |
| 35 |
lib_file_name = import('fs').name(sub_pro.target('cmModLib').full_path()) |
| 36 |
if host_machine.system() == 'linux' |
| 37 |
# Linux shared libraries end with their version: libcmModLib.so.1.0.1 |
| 38 |
lib_version_ok = lib_file_name.endswith(expected_version_str) |
| 39 |
elif host_machine.system() == 'darwin' |
| 40 |
# MacOS shared libraries are suffixed with their soversion: libcmModLib.1.dylib |
| 41 |
lib_version_ok = lib_file_name.split('.')[1] == expected_soversion_str |
| 42 |
else |
| 43 |
# Don't try to assert anything about the library version, either unknown host |
| 44 |
# system or host system doesn't support versioning of shared libraries |
| 45 |
lib_version_ok = true |
| 46 |
endif |
| 47 |
assert(lib_version_ok, f'Shared library version @lib_file_name@ not picked up correctly') |
| 48 |
|
| 49 |
# Test the "normal" subproject call for the build machine |
| 50 |
sub_pro_b = cm.subproject('cmMod', native : true) |
| 51 |
sub_dep_b = sub_pro_b.dependency('cmModLib') |
| 52 |
sub_sta_b = sub_pro_b.dependency('cmModLibStatic') |
| 53 |
|
| 54 |
# Build some files |
| 55 |
exe1_b = executable('main1_b', ['main.cpp'], dependencies: [sub_dep_b], native : true) |
| 56 |
exe2_b = executable('main2_b', ['main.cpp'], dependencies: [sub_sta_b], native : true) |