From af1a266670d040d2f4083ff309d732d648afba2a Mon Sep 17 00:00:00 2001 From: Angelos Mouzakitis Date: Tue, 10 Oct 2023 14:33:42 +0000 Subject: Add submodule dependency files Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec --- .../linuxlike/1 pkg-config/incdir/myinc.h | 3 + .../test cases/linuxlike/1 pkg-config/meson.build | 53 +++++++++ .../linuxlike/1 pkg-config/prog-checkver.c | 15 +++ meson/test cases/linuxlike/1 pkg-config/prog.c | 8 ++ .../linuxlike/10 large file support/meson.build | 16 +++ .../linuxlike/11 runpath rpath ldlibrarypath/lib.c | 3 + .../lib1/meson.build | 2 + .../lib2/meson.build | 3 + .../11 runpath rpath ldlibrarypath/main.c | 11 ++ .../11 runpath rpath ldlibrarypath/meson.build | 16 +++ .../linuxlike/12 subprojects in subprojects/main.c | 9 ++ .../12 subprojects in subprojects/meson.build | 9 ++ .../subprojects/a/a.c | 5 + .../subprojects/a/a.h | 1 + .../subprojects/a/meson.build | 11 ++ .../subprojects/b/b.c | 11 ++ .../subprojects/b/b.h | 1 + .../subprojects/b/meson.build | 17 +++ .../subprojects/c/c.h | 3 + .../subprojects/c/meson.build | 5 + .../linuxlike/13 cmake dependency/cmVers.sh | 6 + .../cmake/FindImportedTarget.cmake | 15 +++ .../cmake/FindSomethingLikeZLIB.cmake | 56 ++++++++++ .../cmake_fake1/cmMesonTestF1Config.cmake | 11 ++ .../cmake_fake2/cmMesonTestF2Config.cmake | 9 ++ .../13 cmake dependency/cmake_fake3/bin/.gitkeep | 0 .../cmake/cmMesonTestF3/cmMesonTestF3Config.cmake | 9 ++ .../cmMesonTestDep/cmMesonTestDepConfig.cmake | 9 ++ .../cmMesonVersionedTestDepConfig.cmake | 9 ++ .../cmMesonVersionedTestDepConfigVersion.cmake | 12 ++ .../linuxlike/13 cmake dependency/incdir/myinc.h | 3 + .../linuxlike/13 cmake dependency/meson.build | 95 ++++++++++++++++ .../linuxlike/13 cmake dependency/prog-checkver.c | 15 +++ .../linuxlike/13 cmake dependency/prog.c | 8 ++ .../linuxlike/13 cmake dependency/test.json | 14 +++ .../linuxlike/13 cmake dependency/testFlagSet.c | 18 +++ .../linuxlike/14 static dynamic linkage/main.c | 7 ++ .../14 static dynamic linkage/meson.build | 36 ++++++ .../14 static dynamic linkage/verify_static.py | 29 +++++ .../test cases/linuxlike/15 ld binary/meson.build | 4 + .../linuxlike/2 external library/meson.build | 43 ++++++++ .../test cases/linuxlike/2 external library/prog.c | 8 ++ meson/test cases/linuxlike/3 linker script/bob.c | 9 ++ meson/test cases/linuxlike/3 linker script/bob.h | 6 + meson/test cases/linuxlike/3 linker script/bob.map | 6 + .../linuxlike/3 linker script/bob.map.in | 6 + meson/test cases/linuxlike/3 linker script/copy.py | 5 + .../linuxlike/3 linker script/meson.build | 62 +++++++++++ meson/test cases/linuxlike/3 linker script/prog.c | 5 + .../linuxlike/3 linker script/sub/foo.map | 6 + .../linuxlike/3 linker script/sub/meson.build | 6 + .../test cases/linuxlike/4 extdep static lib/lib.c | 8 ++ .../linuxlike/4 extdep static lib/meson.build | 10 ++ .../linuxlike/4 extdep static lib/prog.c | 5 + .../linuxlike/5 dependency versions/meson.build | 122 +++++++++++++++++++++ .../subprojects/fakezlib/meson.build | 3 + .../subprojects/somelib/lib.c | 0 .../subprojects/somelib/meson.build | 11 ++ .../subprojects/somelibnover/lib.c | 0 .../subprojects/somelibnover/meson.build | 8 ++ .../subprojects/somelibver/lib.c | 0 .../subprojects/somelibver/meson.build | 9 ++ .../linuxlike/6 subdir include order/meson.build | 12 ++ .../linuxlike/6 subdir include order/prog.c | 7 ++ .../linuxlike/6 subdir include order/subdir/glib.h | 1 + .../linuxlike/7 library versions/exe.orig.c | 8 ++ .../test cases/linuxlike/7 library versions/lib.c | 3 + .../linuxlike/7 library versions/meson.build | 55 ++++++++++ .../linuxlike/7 library versions/test.json | 14 +++ .../8 subproject library install/meson.build | 10 ++ .../subprojects/sublib/include/subdefs.h | 21 ++++ .../subprojects/sublib/meson.build | 10 ++ .../subprojects/sublib/sublib.c | 5 + .../8 subproject library install/test.json | 7 ++ .../meson.build | 36 ++++++ 75 files changed, 1094 insertions(+) create mode 100644 meson/test cases/linuxlike/1 pkg-config/incdir/myinc.h create mode 100644 meson/test cases/linuxlike/1 pkg-config/meson.build create mode 100644 meson/test cases/linuxlike/1 pkg-config/prog-checkver.c create mode 100644 meson/test cases/linuxlike/1 pkg-config/prog.c create mode 100644 meson/test cases/linuxlike/10 large file support/meson.build create mode 100644 meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib.c create mode 100644 meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib1/meson.build create mode 100644 meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib2/meson.build create mode 100644 meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/main.c create mode 100644 meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/meson.build create mode 100644 meson/test cases/linuxlike/12 subprojects in subprojects/main.c create mode 100644 meson/test cases/linuxlike/12 subprojects in subprojects/meson.build create mode 100644 meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.c create mode 100644 meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.h create mode 100644 meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/meson.build create mode 100644 meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.c create mode 100644 meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.h create mode 100644 meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/meson.build create mode 100644 meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/c.h create mode 100644 meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/meson.build create mode 100755 meson/test cases/linuxlike/13 cmake dependency/cmVers.sh create mode 100644 meson/test cases/linuxlike/13 cmake dependency/cmake/FindImportedTarget.cmake create mode 100644 meson/test cases/linuxlike/13 cmake dependency/cmake/FindSomethingLikeZLIB.cmake create mode 100644 meson/test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake create mode 100644 meson/test cases/linuxlike/13 cmake dependency/cmake_fake2/cmMesonTestF2Config.cmake create mode 100644 meson/test cases/linuxlike/13 cmake dependency/cmake_fake3/bin/.gitkeep create mode 100644 meson/test cases/linuxlike/13 cmake dependency/cmake_fake3/lib/cmake/cmMesonTestF3/cmMesonTestF3Config.cmake create mode 100644 meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonTestDep/cmMesonTestDepConfig.cmake create mode 100644 meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfig.cmake create mode 100644 meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfigVersion.cmake create mode 100644 meson/test cases/linuxlike/13 cmake dependency/incdir/myinc.h create mode 100644 meson/test cases/linuxlike/13 cmake dependency/meson.build create mode 100644 meson/test cases/linuxlike/13 cmake dependency/prog-checkver.c create mode 100644 meson/test cases/linuxlike/13 cmake dependency/prog.c create mode 100644 meson/test cases/linuxlike/13 cmake dependency/test.json create mode 100644 meson/test cases/linuxlike/13 cmake dependency/testFlagSet.c create mode 100644 meson/test cases/linuxlike/14 static dynamic linkage/main.c create mode 100644 meson/test cases/linuxlike/14 static dynamic linkage/meson.build create mode 100755 meson/test cases/linuxlike/14 static dynamic linkage/verify_static.py create mode 100644 meson/test cases/linuxlike/15 ld binary/meson.build create mode 100644 meson/test cases/linuxlike/2 external library/meson.build create mode 100644 meson/test cases/linuxlike/2 external library/prog.c create mode 100644 meson/test cases/linuxlike/3 linker script/bob.c create mode 100644 meson/test cases/linuxlike/3 linker script/bob.h create mode 100644 meson/test cases/linuxlike/3 linker script/bob.map create mode 100644 meson/test cases/linuxlike/3 linker script/bob.map.in create mode 100644 meson/test cases/linuxlike/3 linker script/copy.py create mode 100644 meson/test cases/linuxlike/3 linker script/meson.build create mode 100644 meson/test cases/linuxlike/3 linker script/prog.c create mode 100644 meson/test cases/linuxlike/3 linker script/sub/foo.map create mode 100644 meson/test cases/linuxlike/3 linker script/sub/meson.build create mode 100644 meson/test cases/linuxlike/4 extdep static lib/lib.c create mode 100644 meson/test cases/linuxlike/4 extdep static lib/meson.build create mode 100644 meson/test cases/linuxlike/4 extdep static lib/prog.c create mode 100644 meson/test cases/linuxlike/5 dependency versions/meson.build create mode 100644 meson/test cases/linuxlike/5 dependency versions/subprojects/fakezlib/meson.build create mode 100644 meson/test cases/linuxlike/5 dependency versions/subprojects/somelib/lib.c create mode 100644 meson/test cases/linuxlike/5 dependency versions/subprojects/somelib/meson.build create mode 100644 meson/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/lib.c create mode 100644 meson/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/meson.build create mode 100644 meson/test cases/linuxlike/5 dependency versions/subprojects/somelibver/lib.c create mode 100644 meson/test cases/linuxlike/5 dependency versions/subprojects/somelibver/meson.build create mode 100644 meson/test cases/linuxlike/6 subdir include order/meson.build create mode 100644 meson/test cases/linuxlike/6 subdir include order/prog.c create mode 100644 meson/test cases/linuxlike/6 subdir include order/subdir/glib.h create mode 100644 meson/test cases/linuxlike/7 library versions/exe.orig.c create mode 100644 meson/test cases/linuxlike/7 library versions/lib.c create mode 100644 meson/test cases/linuxlike/7 library versions/meson.build create mode 100644 meson/test cases/linuxlike/7 library versions/test.json create mode 100644 meson/test cases/linuxlike/8 subproject library install/meson.build create mode 100644 meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/include/subdefs.h create mode 100644 meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/meson.build create mode 100644 meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/sublib.c create mode 100644 meson/test cases/linuxlike/8 subproject library install/test.json create mode 100644 meson/test cases/linuxlike/9 compiler checks with dependencies/meson.build (limited to 'meson/test cases/linuxlike') diff --git a/meson/test cases/linuxlike/1 pkg-config/incdir/myinc.h b/meson/test cases/linuxlike/1 pkg-config/incdir/myinc.h new file mode 100644 index 000000000..4b66a6caa --- /dev/null +++ b/meson/test cases/linuxlike/1 pkg-config/incdir/myinc.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/meson/test cases/linuxlike/1 pkg-config/meson.build b/meson/test cases/linuxlike/1 pkg-config/meson.build new file mode 100644 index 000000000..ca48e9bd0 --- /dev/null +++ b/meson/test cases/linuxlike/1 pkg-config/meson.build @@ -0,0 +1,53 @@ +project('external dependency', 'c') + +# Zlib is probably on all dev machines. + +dep = dependency('zlib', version : '>=1.2', + not_found_message: 'DANGER! DANGER! THIS MUST NEVER BE SEEN!') +exe = executable('zlibprog', 'prog-checkver.c', + dependencies : dep, + c_args : '-DFOUND_ZLIB="' + dep.version() + '"') + +assert(dep.version().version_compare('>=1.2'), 'Pkg-config version numbers exposed incorrectly.') + +# Check that the version exposed by zlib internally is the same as the one we +# retrieve from the pkg-config file. This assumes that the packager didn't mess +# up, but we can be reasonably sure of that. +test('zlibtest', exe) + +zprefix = dep.get_pkgconfig_variable('prefix') # Always set but we can't be sure what the value is. +# pkg-config returns empty string for not defined variables +assert(dep.get_pkgconfig_variable('nonexisting') == '', 'Value of unknown variable is not empty.') +# ... unless default: is used +assert(dep.get_pkgconfig_variable('nonexisting', default: 'foo') == 'foo', 'Value of unknown variable is not defaulted.') +# pkg-config is able to replace variables +assert(dep.get_pkgconfig_variable('prefix', define_variable: ['prefix', '/tmp']) == '/tmp', 'prefix variable has not been replaced.') + +# Test that dependencies of dependencies work. +dep2 = declare_dependency(dependencies : dep) +exe2 = executable('zlibprog2', 'prog.c', dependencies : dep2) +test('zlibtest2', exe2) + +# Try to find a nonexistent library to ensure requires:false works. + +dep = dependency('nvakuhrabnsdfasdf', required : false, + not_found_message : 'This dependency was not found as was expected.') + +# Try to compile a test that takes a dep and an include_directories + +cc = meson.get_compiler('c') +zlibdep = cc.find_library('z') +code = '''#include + +int main(void) { + void * something = deflate; + if(something != 0) + return 0; + return 1; +} +''' + +inc = include_directories('incdir') + +r = cc.run(code, include_directories : inc, dependencies : zlibdep) +assert(r.returncode() == 0, 'Running manual zlib test failed.') diff --git a/meson/test cases/linuxlike/1 pkg-config/prog-checkver.c b/meson/test cases/linuxlike/1 pkg-config/prog-checkver.c new file mode 100644 index 000000000..ea1ed32f4 --- /dev/null +++ b/meson/test cases/linuxlike/1 pkg-config/prog-checkver.c @@ -0,0 +1,15 @@ +#include +#include +#include + +int main(void) { + void * something = deflate; + if(strcmp(ZLIB_VERSION, FOUND_ZLIB) != 0) { + printf("Meson found '%s' but zlib is '%s'\n", FOUND_ZLIB, ZLIB_VERSION); + return 2; + } + if(something != 0) + return 0; + printf("Couldn't find 'deflate'\n"); + return 1; +} diff --git a/meson/test cases/linuxlike/1 pkg-config/prog.c b/meson/test cases/linuxlike/1 pkg-config/prog.c new file mode 100644 index 000000000..eccc4776f --- /dev/null +++ b/meson/test cases/linuxlike/1 pkg-config/prog.c @@ -0,0 +1,8 @@ +#include + +int main(void) { + void * something = deflate; + if(something != 0) + return 0; + return 1; +} diff --git a/meson/test cases/linuxlike/10 large file support/meson.build b/meson/test cases/linuxlike/10 large file support/meson.build new file mode 100644 index 000000000..66833456c --- /dev/null +++ b/meson/test cases/linuxlike/10 large file support/meson.build @@ -0,0 +1,16 @@ +project('trivial test', 'c') + +if host_machine.system() == 'cygwin' + error('MESON_SKIP_TEST _FILE_OFFSET_BITS not yet supported on Cygwin.') +endif + +cc = meson.get_compiler('c') + +size = cc.sizeof('off_t') +assert(size == 8, 'off_t size is @0@ bytes instead of 8'.format(size)) + +code = '''#if !defined(_FILE_OFFSET_BITS) || (_FILE_OFFSET_BITS != 64) +#error "Large-file support was not enabled" +#endif''' + +assert(cc.compiles(code, name : 'checking for LFS'), 'Large file support was not enabled') diff --git a/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib.c b/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib.c new file mode 100644 index 000000000..2784e017b --- /dev/null +++ b/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib.c @@ -0,0 +1,3 @@ +int some_symbol (void) { + return RET_VALUE; +} diff --git a/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib1/meson.build b/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib1/meson.build new file mode 100644 index 000000000..cbc75bdb1 --- /dev/null +++ b/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib1/meson.build @@ -0,0 +1,2 @@ +lib1 = shared_library('testeh', libsrc, + c_args : '-DRET_VALUE=1') diff --git a/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib2/meson.build b/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib2/meson.build new file mode 100644 index 000000000..f2c6dcc4d --- /dev/null +++ b/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib2/meson.build @@ -0,0 +1,3 @@ +lib2 = shared_library('esteh', libsrc, + name_prefix : 'libt', + c_args : '-DRET_VALUE=2') diff --git a/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/main.c b/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/main.c new file mode 100644 index 000000000..500953169 --- /dev/null +++ b/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/main.c @@ -0,0 +1,11 @@ +#include + +int some_symbol (void); + +int main () { + int ret = some_symbol (); + if (ret == 1) + return 0; + fprintf (stderr, "ret was %i instead of 1\n", ret); + return -1; +} diff --git a/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/meson.build b/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/meson.build new file mode 100644 index 000000000..a3103acfa --- /dev/null +++ b/meson/test cases/linuxlike/11 runpath rpath ldlibrarypath/meson.build @@ -0,0 +1,16 @@ +project('runpath rpath ldlibrarypath', 'c') + +error('MESON_SKIP_TEST test disabled due to bug #1635.') + +libsrc = files('lib.c') + +subdir('lib1') +subdir('lib2') + +lib2dir = meson.current_build_dir() + '/lib2' + +e = executable('testexe', 'main.c', + link_with : lib1) + +test('ld-library-path-test', e, + env : ['LD_LIBRARY_PATH=' + lib2dir]) diff --git a/meson/test cases/linuxlike/12 subprojects in subprojects/main.c b/meson/test cases/linuxlike/12 subprojects in subprojects/main.c new file mode 100644 index 000000000..74523173d --- /dev/null +++ b/meson/test cases/linuxlike/12 subprojects in subprojects/main.c @@ -0,0 +1,9 @@ +#include +#include "a.h" +#include "b.h" + +int main(void) { + int life = a_fun() + b_fun(); + printf("%d\n", life); + return 0; +} diff --git a/meson/test cases/linuxlike/12 subprojects in subprojects/meson.build b/meson/test cases/linuxlike/12 subprojects in subprojects/meson.build new file mode 100644 index 000000000..40141494e --- /dev/null +++ b/meson/test cases/linuxlike/12 subprojects in subprojects/meson.build @@ -0,0 +1,9 @@ +project('super', 'c') + +# A will use version 1 of C +a_dep = dependency('a', fallback: ['a', 'a_dep']) + +# B has an optional dependency on C version 2 and will therefore work +b_dep = dependency('b', fallback: ['b', 'b_dep']) + +main = executable('main', files('main.c'), dependencies: [a_dep, b_dep]) diff --git a/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.c b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.c new file mode 100644 index 000000000..f7dd126fe --- /dev/null +++ b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.c @@ -0,0 +1,5 @@ +#include "c.h" + +int a_fun(void) { + return c_fun(); +} diff --git a/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.h b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.h new file mode 100644 index 000000000..9de0deb2c --- /dev/null +++ b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.h @@ -0,0 +1 @@ +int a_fun(void); diff --git a/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/meson.build b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/meson.build new file mode 100644 index 000000000..5f579a372 --- /dev/null +++ b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/meson.build @@ -0,0 +1,11 @@ +project('a', 'c', version:'1.0') + +c_dep = dependency('c', version:'1', fallback: ['c', 'c_dep']) + +alib = library('a', 'a.c', + dependencies: c_dep) + +a_dep = declare_dependency( + link_with: alib, + include_directories: include_directories('.'), +) diff --git a/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.c b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.c new file mode 100644 index 000000000..45c9348f7 --- /dev/null +++ b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.c @@ -0,0 +1,11 @@ +#if defined(WITH_C) +#include "c.h" +#endif + +int b_fun(void){ +#if defined(WITH_C) +return c_fun(); +#else +return 0; +#endif +} diff --git a/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.h b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.h new file mode 100644 index 000000000..47b84d412 --- /dev/null +++ b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.h @@ -0,0 +1 @@ +int b_fun(void); diff --git a/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/meson.build b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/meson.build new file mode 100644 index 000000000..80903f3b1 --- /dev/null +++ b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/meson.build @@ -0,0 +1,17 @@ +project('b', 'c') + +c_dep = dependency('c', version:'2', fallback: ['c', 'c_dep'], required: false) + +assert(c_dep.found() == false, 'C project has the wrong version and should not be found') + +if c_dep.found() + add_global_arguments('-DWITH_C', language: 'c') +endif + +blib = library('b', 'b.c', + dependencies: c_dep) + +b_dep = declare_dependency( + link_with: blib, + include_directories: include_directories('.'), +) diff --git a/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/c.h b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/c.h new file mode 100644 index 000000000..b2e3f9b21 --- /dev/null +++ b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/c.h @@ -0,0 +1,3 @@ +static int c_fun(void){ + return 3; +} diff --git a/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/meson.build b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/meson.build new file mode 100644 index 000000000..7184933b2 --- /dev/null +++ b/meson/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/meson.build @@ -0,0 +1,5 @@ +project('c', 'c', version:'1') + +c_dep = declare_dependency( + include_directories: include_directories('.') +) diff --git a/meson/test cases/linuxlike/13 cmake dependency/cmVers.sh b/meson/test cases/linuxlike/13 cmake dependency/cmVers.sh new file mode 100755 index 000000000..6e096a5f8 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/cmVers.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +VERS=$(cmake --version | grep "cmake version") +VERS=${VERS//cmake version/} + +echo -n $VERS diff --git a/meson/test cases/linuxlike/13 cmake dependency/cmake/FindImportedTarget.cmake b/meson/test cases/linuxlike/13 cmake dependency/cmake/FindImportedTarget.cmake new file mode 100644 index 000000000..753df5bc0 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/cmake/FindImportedTarget.cmake @@ -0,0 +1,15 @@ +find_package(ZLIB) + +if(ZLIB_FOUND OR ZLIB_Found) + set(ImportedTarget_FOUND ON) + add_library(mesonTestLibDefs SHARED IMPORTED) + set_property(TARGET mesonTestLibDefs PROPERTY IMPORTED_LOCATION ${ZLIB_LIBRARY}) + set_property(TARGET mesonTestLibDefs PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIR}) + set_property(TARGET mesonTestLibDefs APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS REQUIRED_MESON_FLAG1) + set_property(TARGET mesonTestLibDefs APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS $<$>:QT_NO_DEBUG>) # Error empty string + set_property(TARGET mesonTestLibDefs APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS REQUIRED_MESON_FLAG2) + set_target_properties(mesonTestLibDefs PROPERTIES IMPORTED_GLOBAL TRUE) + add_library(MesonTest::TestLibDefs ALIAS mesonTestLibDefs) +else() + set(ImportedTarget_FOUND OFF) +endif() diff --git a/meson/test cases/linuxlike/13 cmake dependency/cmake/FindSomethingLikeZLIB.cmake b/meson/test cases/linuxlike/13 cmake dependency/cmake/FindSomethingLikeZLIB.cmake new file mode 100644 index 000000000..483926ce8 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/cmake/FindSomethingLikeZLIB.cmake @@ -0,0 +1,56 @@ +find_package(ZLIB) + +include(CMakeFindDependencyMacro) +include(CheckCXXSourceRuns) +include(CheckCSourceRuns) + +# Do something stupid (see https://github.com/mesonbuild/meson/issues/7501) +set("") + +check_cxx_source_runs( +" +#include + +using namespace std; + +int main(void) { + cout << \"Hello World\" << endl; + return 0; +} +" +CXX_CODE_RAN +) + +check_c_source_runs( +" +#include + +int main(void) { + printf(\"Hello World\"); + return 0; +} +" +C_CODE_RAN +) + +if(NOT CXX_CODE_RAN) + message(FATAL_ERROR "Running CXX source code failed") +endif() + +if(NOT C_CODE_RAN) + message(FATAL_ERROR "Running C source code failed") +endif() + +if(NOT SomethingLikeZLIB_FIND_COMPONENTS STREQUAL "required_comp") + message(FATAL_ERROR "Component 'required_comp' was not specified") +endif() + +find_dependency(Threads) + +if(ZLIB_FOUND OR ZLIB_Found) + set(SomethingLikeZLIB_FOUND ON) + set(SomethingLikeZLIB_LIBRARIES ${ZLIB_LIBRARY}) + set(SomethingLikeZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) +else() + set(SomethingLikeZLIB_FOUND OFF) +endif() diff --git a/meson/test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake b/meson/test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake new file mode 100644 index 000000000..4b3f81479 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake @@ -0,0 +1,11 @@ +find_package(ZLIB) + +if(ZLIB_FOUND OR ZLIB_Found) + set(cmMesonTestF1_FOUND ON) + set(cmMesonTestF1_LIBRARIES general ${ZLIB_LIBRARY}) + set(cmMesonTestF1_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) + + add_library(CMMesonTESTf1::evil_non_standard_trget UNKNOWN IMPORTED) +else() + set(cmMesonTestF1_FOUND OFF) +endif() diff --git a/meson/test cases/linuxlike/13 cmake dependency/cmake_fake2/cmMesonTestF2Config.cmake b/meson/test cases/linuxlike/13 cmake dependency/cmake_fake2/cmMesonTestF2Config.cmake new file mode 100644 index 000000000..a7a55d880 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/cmake_fake2/cmMesonTestF2Config.cmake @@ -0,0 +1,9 @@ +find_package(ZLIB) + +if(ZLIB_FOUND OR ZLIB_Found) + set(cmMesonTestF2_FOUND ON) + set(cmMesonTestF2_LIBRARIES ${ZLIB_LIBRARY}) + set(cmMesonTestF2_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) +else() + set(cmMesonTestF2_FOUND OFF) +endif() diff --git a/meson/test cases/linuxlike/13 cmake dependency/cmake_fake3/bin/.gitkeep b/meson/test cases/linuxlike/13 cmake dependency/cmake_fake3/bin/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/meson/test cases/linuxlike/13 cmake dependency/cmake_fake3/lib/cmake/cmMesonTestF3/cmMesonTestF3Config.cmake b/meson/test cases/linuxlike/13 cmake dependency/cmake_fake3/lib/cmake/cmMesonTestF3/cmMesonTestF3Config.cmake new file mode 100644 index 000000000..2fab39540 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/cmake_fake3/lib/cmake/cmMesonTestF3/cmMesonTestF3Config.cmake @@ -0,0 +1,9 @@ +find_package(ZLIB) + +if(ZLIB_FOUND OR ZLIB_Found) + set(cmMesonTestF3_FOUND ON) + set(cmMesonTestF3_LIBRARIES ${ZLIB_LIBRARY}) + set(cmMesonTestF3_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) +else() + set(cmMesonTestF3_FOUND OFF) +endif() diff --git a/meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonTestDep/cmMesonTestDepConfig.cmake b/meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonTestDep/cmMesonTestDepConfig.cmake new file mode 100644 index 000000000..06a206071 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonTestDep/cmMesonTestDepConfig.cmake @@ -0,0 +1,9 @@ +find_package(ZLIB) + +if(ZLIB_FOUND OR ZLIB_Found) + set(cmMesonTestDep_FOUND ON) + set(cmMesonTestDep_LIBRARIES ${ZLIB_LIBRARY}) + set(cmMesonTestDep_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) +else() + set(cmMesonTestDep_FOUND OFF) +endif() diff --git a/meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfig.cmake b/meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfig.cmake new file mode 100644 index 000000000..d3adcb741 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfig.cmake @@ -0,0 +1,9 @@ +find_package(ZLIB) + +if(ZLIB_FOUND OR ZLIB_Found) + set(cmMesonVersionedTestDep_FOUND ON) + set(cmMesonVersionedTestDep_LIBRARIES ${ZLIB_LIBRARY}) + set(cmMesonVersionedTestDep_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) +else() + set(cmMesonVersionedTestDep_FOUND OFF) +endif() diff --git a/meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfigVersion.cmake b/meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfigVersion.cmake new file mode 100644 index 000000000..5b9905dca --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfigVersion.cmake @@ -0,0 +1,12 @@ +set(PACKAGE_VERSION 3.1.4) + +if (${PACKAGE_FIND_VERSION_MAJOR} EQUAL 3) + if (${PACKAGE_FIND_VERSION} VERSION_LESS 3.1.4) + set(PACKAGE_VERSION_COMPATIBLE 1) + endif() + if (${PACKAGE_FIND_VERSION} VERSION_EQUAL 3.1.4) + set(PACKAGE_VERSION_EXACT 1) + endif() +else() + set(PACKAGE_VERSION_UNSUITABLE 1) +endif() diff --git a/meson/test cases/linuxlike/13 cmake dependency/incdir/myinc.h b/meson/test cases/linuxlike/13 cmake dependency/incdir/myinc.h new file mode 100644 index 000000000..4b66a6caa --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/incdir/myinc.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/meson/test cases/linuxlike/13 cmake dependency/meson.build b/meson/test cases/linuxlike/13 cmake dependency/meson.build new file mode 100644 index 000000000..b82f9b7f5 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/meson.build @@ -0,0 +1,95 @@ +# this test can ONLY be run successfully from run_project_test.py +# due to use of setup_env.json +project('external CMake dependency', ['c', 'cpp']) + +if not find_program('cmake', required: false).found() + error('MESON_SKIP_TEST cmake binary not available.') +endif + +# CMake version +cm_vers = run_command(find_program('./cmVers.sh')).stdout().strip() + +# Zlib is probably on all dev machines. + +dep = dependency('ZLIB', version : '>=1.2', method : 'cmake') +exe = executable('zlibprog', 'prog-checkver.c', + dependencies : dep, + c_args : '-DFOUND_ZLIB="' + dep.version() + '"') + +assert(dep.version().version_compare('>=1.2'), 'CMake version numbers exposed incorrectly.') + +# Check that CMake targets are extracted +dept = dependency('ZLIB', version : '>=1.2', method : 'cmake', modules : 'ZLIB::ZLIB') +exet = executable('zlibprog_target', 'prog-checkver.c', + dependencies : dep, + c_args : '-DFOUND_ZLIB="' + dep.version() + '"') + +# Check that the version exposed by zlib internally is the same as the one we +# retrieve from the pkg-config file. This assumes that the packager didn't mess +# up, but we can be reasonably sure of that. +test('zlibtest', exe) + +# Test that dependencies of dependencies work. +dep2 = declare_dependency(dependencies : dep) +exe2 = executable('zlibprog2', 'prog.c', dependencies : dep2) +test('zlibtest2', exe2) + +# Try to find a nonexistent library to ensure requires:false works. + +depf1 = dependency('nvakuhrabnsdfasdf', required : false, method : 'cmake') +depf2 = dependency('ZLIB', required : false, method : 'cmake', modules : 'dfggh::hgfgag') + +assert(depf2.found() == false, 'Invalid CMake targets should fail') + +# Try to find cmMesonTestDep in a custom prefix +# setup_env.json is used by run_project_tests.py:_run_test to point to ./cmake_pref_env/ +depPrefEnv = dependency('cmMesonTestDep', required : true, method : 'cmake') +depPrefEnv1 = dependency('cmMesonTestF1', required : true, method : 'cmake') +depPrefEnv2 = dependency('cmMesonTestF2', required : true, method : 'cmake') +depPrefEnv3 = dependency('cmMesonTestF3', required : true, method : 'cmake') + +# Try to actually link with depPrefEnv1, since we are doing "fun" stuff there +exe3 = executable('zlibprog3', 'prog.c', dependencies : depPrefEnv1) +test('zlibtest3', exe3) + +# Try to find a dependency with a custom CMake module + +depm1 = dependency('SomethingLikeZLIB', required : true, components : 'required_comp', method : 'cmake', cmake_module_path : 'cmake') +depm2 = dependency('SomethingLikeZLIB', required : true, components : 'required_comp', method : 'cmake', cmake_module_path : ['cmake']) +depm3 = dependency('SomethingLikeZLIB', required : true, components : ['required_comp'], cmake_module_path : 'cmake') + +# Test some edge cases with spaces, etc. (but only for CMake >= 3.15) + +if cm_vers.version_compare('>=3.15') + testDep1 = dependency('ImportedTarget', required : true, method : 'cmake', cmake_module_path : 'cmake', modules: 'mesonTestLibDefs') + testDep2 = dependency('ImportedTarget', required : true, method : 'cmake', cmake_module_path : 'cmake', modules : ['MesonTest::TestLibDefs']) + testFlagSet1 = executable('testFlagSet1', ['testFlagSet.c'], dependencies: [testDep1]) + testFlagSet2 = executable('testFlagSet2', ['testFlagSet.c'], dependencies: [testDep2]) + test('testFlagSetTest1', testFlagSet1) + test('testFlagSetTest2', testFlagSet2) +endif + +# Try to find a dependency with a cmake module which requires a package version +# test.json sets CMAKE_PREFIX_PATH to include ./cmake_pref_env/ +verdep1 = dependency('cmMesonVersionedTestDep', required : true, method : 'cmake', cmake_package_version : '3.0') +verdep2 = dependency('cmMesonVersionedTestDep', required : false, method : 'cmake', cmake_package_version : '200.0') +assert(not verdep2.found(), 'found a version dep we shouldnt have') + +# Try to compile a test that takes a dep and an include_directories + +cc = meson.get_compiler('c') +zlibdep = cc.find_library('z') +code = '''#include + +int main(void) { + void * something = deflate; + if(something != 0) + return 0; + return 1; +} +''' + +inc = include_directories('incdir') + +r = cc.run(code, include_directories : inc, dependencies : zlibdep) +assert(r.returncode() == 0, 'Running manual zlib test failed.') diff --git a/meson/test cases/linuxlike/13 cmake dependency/prog-checkver.c b/meson/test cases/linuxlike/13 cmake dependency/prog-checkver.c new file mode 100644 index 000000000..ea1ed32f4 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/prog-checkver.c @@ -0,0 +1,15 @@ +#include +#include +#include + +int main(void) { + void * something = deflate; + if(strcmp(ZLIB_VERSION, FOUND_ZLIB) != 0) { + printf("Meson found '%s' but zlib is '%s'\n", FOUND_ZLIB, ZLIB_VERSION); + return 2; + } + if(something != 0) + return 0; + printf("Couldn't find 'deflate'\n"); + return 1; +} diff --git a/meson/test cases/linuxlike/13 cmake dependency/prog.c b/meson/test cases/linuxlike/13 cmake dependency/prog.c new file mode 100644 index 000000000..eccc4776f --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/prog.c @@ -0,0 +1,8 @@ +#include + +int main(void) { + void * something = deflate; + if(something != 0) + return 0; + return 1; +} diff --git a/meson/test cases/linuxlike/13 cmake dependency/test.json b/meson/test cases/linuxlike/13 cmake dependency/test.json new file mode 100644 index 000000000..1505986ee --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/test.json @@ -0,0 +1,14 @@ +{ + "env": { + "CMAKE_PREFIX_PATH": "@ROOT@/cmake_fake1;@ROOT@/cmake_fake2:@ROOT@/cmake_pref_env", + "PATH": "@ROOT@/cmake_fake3/bin:@PATH@" + }, + "stdout": [ + { + "line": "WARNING: Could not find and exact match for the CMake dependency cmMesonTestF1." + }, + { + "line": " ['CMMesonTESTf1::evil_non_standard_trget']" + } + ] +} diff --git a/meson/test cases/linuxlike/13 cmake dependency/testFlagSet.c b/meson/test cases/linuxlike/13 cmake dependency/testFlagSet.c new file mode 100644 index 000000000..1f93ea3a8 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/testFlagSet.c @@ -0,0 +1,18 @@ +#include +#include + +#ifndef REQUIRED_MESON_FLAG1 +#error "REQUIRED_MESON_FLAG1 not set" +#endif + +#ifndef REQUIRED_MESON_FLAG2 +#error "REQUIRED_MESON_FLAG2 not set" +#endif + +int main(void) { + printf("Hello World\n"); + void * something = deflate; + if(something != 0) + return 0; + return 1; +} diff --git a/meson/test cases/linuxlike/14 static dynamic linkage/main.c b/meson/test cases/linuxlike/14 static dynamic linkage/main.c new file mode 100644 index 000000000..09d1509bb --- /dev/null +++ b/meson/test cases/linuxlike/14 static dynamic linkage/main.c @@ -0,0 +1,7 @@ +#include "stdio.h" +#include "zlib.h" + +int main(void) { + printf("%s\n", zlibVersion()); + return 0; +} diff --git a/meson/test cases/linuxlike/14 static dynamic linkage/meson.build b/meson/test cases/linuxlike/14 static dynamic linkage/meson.build new file mode 100644 index 000000000..fb0e3537a --- /dev/null +++ b/meson/test cases/linuxlike/14 static dynamic linkage/meson.build @@ -0,0 +1,36 @@ +project('static dynamic', 'c') + +# Solaris does not ship static libraries +if host_machine.system() == 'sunos' + has_static = false +else + has_static = true +endif + +cc = meson.get_compiler('c') + +z_default = cc.find_library('z') +if has_static + z_static = cc.find_library('z', static: true) +endif +z_dynamic = cc.find_library('z', static: false) + +exe_default = executable('main_default', 'main.c', dependencies: [z_default]) +if has_static + exe_static = executable('main_static', 'main.c', dependencies: [z_static]) +endif +exe_dynamic = executable('main_dynamic', 'main.c', dependencies: [z_dynamic]) + +test('test default', exe_default) +if has_static + test('test static', exe_static) +endif +test('test dynamic', exe_dynamic) + +if has_static + test('verify static linking', find_program('verify_static.py'), + args: ['--platform=' + host_machine.system(), exe_static.full_path()]) +endif +test('verify dynamic linking', find_program('verify_static.py'), + args: ['--platform=' + host_machine.system(), exe_dynamic.full_path()], + should_fail: true) diff --git a/meson/test cases/linuxlike/14 static dynamic linkage/verify_static.py b/meson/test cases/linuxlike/14 static dynamic linkage/verify_static.py new file mode 100755 index 000000000..8d16d48c9 --- /dev/null +++ b/meson/test cases/linuxlike/14 static dynamic linkage/verify_static.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +"""Test script that checks if zlib was statically linked to executable""" +import subprocess +import sys + +def handle_common(path): + """Handle the common case.""" + output = subprocess.check_output(['nm', path]).decode('utf-8') + if 'T zlibVersion' in output: + return 0 + return 1 + +def handle_cygwin(path): + """Handle the Cygwin case.""" + output = subprocess.check_output(['nm', path]).decode('utf-8') + if (('I __imp_zlibVersion' in output) or ('D __imp_zlibVersion' in output)): + return 1 + return 0 + +def main(): + """Main function""" + if len(sys.argv) > 2 and sys.argv[1] == '--platform=cygwin': + return handle_cygwin(sys.argv[2]) + else: + return handle_common(sys.argv[2]) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/meson/test cases/linuxlike/15 ld binary/meson.build b/meson/test cases/linuxlike/15 ld binary/meson.build new file mode 100644 index 000000000..987763edd --- /dev/null +++ b/meson/test cases/linuxlike/15 ld binary/meson.build @@ -0,0 +1,4 @@ +project('ld binary') + +ld = find_program('ld') +assert(run_command(ld, '--version').returncode() == 0) diff --git a/meson/test cases/linuxlike/2 external library/meson.build b/meson/test cases/linuxlike/2 external library/meson.build new file mode 100644 index 000000000..3188ebf28 --- /dev/null +++ b/meson/test cases/linuxlike/2 external library/meson.build @@ -0,0 +1,43 @@ +project('external library', 'c') + +cc = meson.get_compiler('c') +zlib = cc.find_library('z') + +# Verify that link testing works. +linkcode = '''#include +int main(void) { + void *ptr = (void*)(deflate); + return ptr == 0; +} +''' + +nolinkcode='''int nonexisting(); +int main(void) { + return nonexisting(); +} +''' + +assert(cc.links(linkcode, args : '-lz', name : 'Test link against zlib'), 'Linking test failed.') +d1 = declare_dependency(compile_args: '-DSOMETHING', link_args: '-lz') +assert(cc.links(linkcode, dependencies : d1, + name : 'Test link against zlib via declare_dependency'), 'Linking test failed.') +d2 = declare_dependency(dependencies: d1) +assert(cc.links(linkcode, dependencies : d2, + name : 'Test link against zlib via indirect declare_dependency'), 'Linking test failed.') +assert(not cc.links(nolinkcode, name : 'Failing link'), 'Linking succeeded when it should have failed.') + +e = executable('zprog', 'prog.c', dependencies : zlib) +test('libtest', e) + +e2 = executable('zprog_alt', 'prog.c', dependencies : zlib) +test('libtest_alt', e2) + +# Test that ext deps work via an internal dep. +intdep = declare_dependency(dependencies : zlib) +exe2 = executable('zprog2', 'prog.c', dependencies : intdep) +test('libtest2', exe2) + +# Test that deps that use find_library deps work. +depdep = declare_dependency(dependencies : intdep) +exe3 = executable('zprog3', 'prog.c', dependencies : depdep) +test('libtest3', exe3) diff --git a/meson/test cases/linuxlike/2 external library/prog.c b/meson/test cases/linuxlike/2 external library/prog.c new file mode 100644 index 000000000..eccc4776f --- /dev/null +++ b/meson/test cases/linuxlike/2 external library/prog.c @@ -0,0 +1,8 @@ +#include + +int main(void) { + void * something = deflate; + if(something != 0) + return 0; + return 1; +} diff --git a/meson/test cases/linuxlike/3 linker script/bob.c b/meson/test cases/linuxlike/3 linker script/bob.c new file mode 100644 index 000000000..50e29c753 --- /dev/null +++ b/meson/test cases/linuxlike/3 linker script/bob.c @@ -0,0 +1,9 @@ +#include"bob.h" + +int hiddenFunction(void) { + return 42; +} + +int bobMcBob(void) { + return hiddenFunction(); +} diff --git a/meson/test cases/linuxlike/3 linker script/bob.h b/meson/test cases/linuxlike/3 linker script/bob.h new file mode 100644 index 000000000..351e2fc60 --- /dev/null +++ b/meson/test cases/linuxlike/3 linker script/bob.h @@ -0,0 +1,6 @@ +#ifndef BOB_H_ +#define BOB_H_ + +int bobMcBob(void); + +#endif diff --git a/meson/test cases/linuxlike/3 linker script/bob.map b/meson/test cases/linuxlike/3 linker script/bob.map new file mode 100644 index 000000000..e07a78062 --- /dev/null +++ b/meson/test cases/linuxlike/3 linker script/bob.map @@ -0,0 +1,6 @@ +V1_0_0 { + global: + "bobMcBob"; + local: + *; +}; diff --git a/meson/test cases/linuxlike/3 linker script/bob.map.in b/meson/test cases/linuxlike/3 linker script/bob.map.in new file mode 100644 index 000000000..f695e4ae8 --- /dev/null +++ b/meson/test cases/linuxlike/3 linker script/bob.map.in @@ -0,0 +1,6 @@ +V1_0_0 { + global: + "@in@"; + local: + *; +}; diff --git a/meson/test cases/linuxlike/3 linker script/copy.py b/meson/test cases/linuxlike/3 linker script/copy.py new file mode 100644 index 000000000..49e7a85a3 --- /dev/null +++ b/meson/test cases/linuxlike/3 linker script/copy.py @@ -0,0 +1,5 @@ +import shutil +import sys + +if __name__ == '__main__': + shutil.copy(sys.argv[1], sys.argv[2]) diff --git a/meson/test cases/linuxlike/3 linker script/meson.build b/meson/test cases/linuxlike/3 linker script/meson.build new file mode 100644 index 000000000..5901bf7cf --- /dev/null +++ b/meson/test cases/linuxlike/3 linker script/meson.build @@ -0,0 +1,62 @@ +project('linker script', 'c') + +# Solaris 11.4 ld supports --version-script only when you also specify +# -z gnu-version-script-compat +if meson.get_compiler('c').get_linker_id() == 'ld.solaris' + add_project_link_arguments('-Wl,-z,gnu-version-script-compat', language: 'C') +endif + +# Static map file +mapfile = 'bob.map' +vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile) + +l = shared_library('bob', 'bob.c', link_args : vflag, link_depends : mapfile) +e = executable('prog', 'prog.c', link_with : l) +test('core', e) + +# configure_file +conf = configuration_data() +conf.set('in', 'bobMcBob') +m = configure_file( + input : 'bob.map.in', + output : 'bob-conf.map', + configuration : conf, +) +vflag = '-Wl,--version-script,@0@'.format(m) + +l = shared_library('bob-conf', 'bob.c', link_args : vflag, link_depends : m) +e = executable('prog-conf', 'prog.c', link_with : l) +test('core', e) + +# custom_target +python = find_program('python3') +m = custom_target( + 'bob-ct.map', + command : [python, '@INPUT0@', '@INPUT1@', 'bob-ct.map'], + input : ['copy.py', 'bob.map'], + output : 'bob-ct.map', + depend_files : 'bob.map', +) +vflag = '-Wl,--version-script,@0@'.format(m.full_path()) + +l = shared_library('bob-ct', ['bob.c', m], link_args : vflag, link_depends : m) +e = executable('prog-ct', 'prog.c', link_with : l) +test('core', e) + +# File +mapfile = files('bob.map') +vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile[0]) + +l = shared_library('bob-files', 'bob.c', link_args : vflag, link_depends : mapfile) +e = executable('prog-files', 'prog.c', link_with : l) +test('core', e) + +subdir('sub') + +# With map file in subdir +mapfile = 'sub/foo.map' +vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile) + +l = shared_library('bar', 'bob.c', link_args : vflag, link_depends : mapfile) +e = executable('prog-bar', 'prog.c', link_with : l) +test('core', e) diff --git a/meson/test cases/linuxlike/3 linker script/prog.c b/meson/test cases/linuxlike/3 linker script/prog.c new file mode 100644 index 000000000..b010b1587 --- /dev/null +++ b/meson/test cases/linuxlike/3 linker script/prog.c @@ -0,0 +1,5 @@ +#include"bob.h" + +int main(void) { + return bobMcBob() != 42; +} diff --git a/meson/test cases/linuxlike/3 linker script/sub/foo.map b/meson/test cases/linuxlike/3 linker script/sub/foo.map new file mode 100644 index 000000000..e07a78062 --- /dev/null +++ b/meson/test cases/linuxlike/3 linker script/sub/foo.map @@ -0,0 +1,6 @@ +V1_0_0 { + global: + "bobMcBob"; + local: + *; +}; diff --git a/meson/test cases/linuxlike/3 linker script/sub/meson.build b/meson/test cases/linuxlike/3 linker script/sub/meson.build new file mode 100644 index 000000000..93199f392 --- /dev/null +++ b/meson/test cases/linuxlike/3 linker script/sub/meson.build @@ -0,0 +1,6 @@ +mapfile = 'foo.map' +vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile) + +l = shared_library('foo', '../bob.c', link_args : vflag, link_depends : mapfile) +e = executable('prog-foo', '../prog.c', link_with : l) +test('core', e) diff --git a/meson/test cases/linuxlike/4 extdep static lib/lib.c b/meson/test cases/linuxlike/4 extdep static lib/lib.c new file mode 100644 index 000000000..bbda9aae7 --- /dev/null +++ b/meson/test cases/linuxlike/4 extdep static lib/lib.c @@ -0,0 +1,8 @@ +#include + +int statlibfunc(void) { + void * something = deflate; + if(something != 0) + return 0; + return 1; +} diff --git a/meson/test cases/linuxlike/4 extdep static lib/meson.build b/meson/test cases/linuxlike/4 extdep static lib/meson.build new file mode 100644 index 000000000..1a73e494e --- /dev/null +++ b/meson/test cases/linuxlike/4 extdep static lib/meson.build @@ -0,0 +1,10 @@ +project('external dependency with static', 'c') + +# Zlib is probably on all dev machines. + +dep = dependency('zlib') +statlib = static_library('statlib', 'lib.c', dependencies : dep) +exe = executable('prog', 'prog.c', link_with : statlib) + + +test('zlibtest', exe) diff --git a/meson/test cases/linuxlike/4 extdep static lib/prog.c b/meson/test cases/linuxlike/4 extdep static lib/prog.c new file mode 100644 index 000000000..0aeb8271b --- /dev/null +++ b/meson/test cases/linuxlike/4 extdep static lib/prog.c @@ -0,0 +1,5 @@ +int statlibfunc(void); + +int main(void) { + return statlibfunc(); +} diff --git a/meson/test cases/linuxlike/5 dependency versions/meson.build b/meson/test cases/linuxlike/5 dependency versions/meson.build new file mode 100644 index 000000000..164e679c4 --- /dev/null +++ b/meson/test cases/linuxlike/5 dependency versions/meson.build @@ -0,0 +1,122 @@ +project('dep versions', 'c', 'cpp') + +# Find external dependency without version +zlib = dependency('zlib') +# Find external dependency with version +zlibver = dependency('zlib', version : '>1.0') +assert(zlib.version() == zlibver.version(), 'zlib versions did not match!') +# Find external dependency with conflicting version +assert(zlib.type_name() == 'pkgconfig', 'zlib should be of type "pkgconfig" not ' + zlib.type_name()) +zlibver = dependency('zlib', version : '<1.0', required : false) +assert(zlibver.found() == false, 'zlib <1.0 should not be found!') + +# Find external dependencies with various version restrictions +dependency('zlib', version : '>=1.0') +dependency('zlib', version : '<=9999') +dependency('zlib', version : '=' + zlib.version()) + +# Find external dependencies with multiple version restrictions +dependency('zlib', version : ['>=1.0', '<=9999']) +if dependency('zlib', version : ['<=1.0', '>=9999', '=' + zlib.version()], required : false).found() + error('zlib <=1.0 >=9999 should not have been found') +endif + +# Test that a versionless zlib is found after not finding an optional zlib dep with version reqs +zlibopt = dependency('zlib', required : false) +assert(zlibopt.found() == true, 'zlib not found') + +# Test https://github.com/mesonbuild/meson/pull/610 +dependency('somebrokenlib', version : '>=2.0', required : false) +dependency('somebrokenlib', version : '>=1.0', required : false) + +# Search for an external dependency that won't be found, but must later be +# found via fallbacks +somelibnotfound = dependency('somelib1', required : false) +assert(somelibnotfound.found() == false, 'somelibnotfound was found?') +# Find internal dependency without version +somelibver = dependency('somelib1', + fallback : ['somelibnover', 'some_dep']) +assert(somelibver.type_name() == 'internal', 'somelibver should be of type "internal", not ' + somelibver.type_name()) +# Find an internal dependency again with the same name and a specific version +somelib = dependency('somelib2', + version : '== 0.1', + fallback : ['somelib', 'some_dep']) +# Find an internal dependency again even if required = false +somelib_reqfalse = dependency('somelib3', + required: false, + fallback : ['somelib', 'some_dep']) +assert(somelib_reqfalse.found(), 'somelib should have been found') +# Find an internal dependency again with the same name and incompatible version +somelibver = dependency('somelib4', + version : '>= 0.3', + fallback : ['somelibver', 'some_dep']) +# Find an internal dependency again with impossible multi-version +somelibver = dependency('somelib5', + version : ['>= 0.3', '<0.3'], + required : false, + fallback : ['somelibver', 'some_dep']) +assert(not somelibver.found(), 'Dependency should not be found') +# Find somelib again, but with a fallback that will fail because subproject does not exist +somelibfail = dependency('somelib6', + version : '>= 0.2', + required : false, + fallback : ['somelibfail', 'some_dep']) +assert(somelibfail.found() == false, 'somelibfail found via wrong fallback') +# Find somelib again, but with a fallback that will fail because dependency does not exist +somefail_dep = dependency('somelib7', + version : '>= 0.2', + required : false, + fallback : ['somelib', 'somefail_dep']) +assert(somefail_dep.found() == false, 'somefail_dep found via wrong fallback') + +# Fallback should only be used if the primary was not found +fallbackzlib_dep = dependency('zlib', + fallback : ['fakezlib', 'fakezlib_dep']) +assert(fallbackzlib_dep.type_name() == 'pkgconfig', 'fallbackzlib_dep should be of type "pkgconfig", not ' + fallbackzlib_dep.type_name()) +# Check that the above dependency was pkgconfig because the fallback wasn't +# checked, not because the fallback didn't work +fakezlib_dep = dependency('fakezlib', + fallback : ['fakezlib', 'fakezlib_dep']) +assert(fakezlib_dep.type_name() == 'internal', 'fakezlib_dep should be of type "internal", not ' + fakezlib_dep.type_name()) + +# Verify that once we got a system dependency, we won't fallback if a newer +# version is requested. +d = dependency('zlib', version: '>= 999', + fallback : ['donotexist', 'fakezlib_dep'], + required: false) +assert(not d.found(), 'version should not match and it should not fallback') + +# Check that you can find a dependency by not specifying a version after not +# finding it by specifying a version. We add `static: true` here so that the +# previously cached zlib dependencies don't get checked. +dependency('zlib', static : true, version : '>=8000', required : false) +dependency('zlib', static : true) + +# Check that you can find a dependency by specifying a correct version after +# not finding it by specifying a wrong one. We add `method: pkg-config` here so that +# the previously cached zlib dependencies don't get checked. +bzip2 = dependency('zlib', method : 'pkg-config', version : '>=9000', required : false) +bzip2 = dependency('zlib', method : 'pkg-config', version : '>=1.0') + +if meson.is_cross_build() + # Test caching of native and cross dependencies + # https://github.com/mesonbuild/meson/issues/1736 + cross_prefix = dependency('zlib').get_pkgconfig_variable('prefix') + native_prefix = dependency('zlib', native : true).get_pkgconfig_variable('prefix') + assert(cross_prefix != '', 'cross zlib prefix is not defined') + assert(native_prefix != '', 'native zlib prefix is not defined') + assert(native_prefix != cross_prefix, 'native prefix == cross_prefix == ' + native_prefix) +endif + +objc_found = add_languages('objc', required : false) + +foreach d : ['sdl2', 'gnustep', 'wxwidgets', 'gl', 'python3', 'boost', 'gtest', 'gmock', 'valgrind'] + if d == 'gnustep' and not objc_found + message('Skipping gnustep because no ObjC compiler found') + else + dep = dependency(d, required : false) + if dep.found() + dep.version() + endif + endif +endforeach diff --git a/meson/test cases/linuxlike/5 dependency versions/subprojects/fakezlib/meson.build b/meson/test cases/linuxlike/5 dependency versions/subprojects/fakezlib/meson.build new file mode 100644 index 000000000..5a077638e --- /dev/null +++ b/meson/test cases/linuxlike/5 dependency versions/subprojects/fakezlib/meson.build @@ -0,0 +1,3 @@ +project('some', 'c', version : '0.1') + +fakezlib_dep = declare_dependency() diff --git a/meson/test cases/linuxlike/5 dependency versions/subprojects/somelib/lib.c b/meson/test cases/linuxlike/5 dependency versions/subprojects/somelib/lib.c new file mode 100644 index 000000000..e69de29bb diff --git a/meson/test cases/linuxlike/5 dependency versions/subprojects/somelib/meson.build b/meson/test cases/linuxlike/5 dependency versions/subprojects/somelib/meson.build new file mode 100644 index 000000000..670b10f39 --- /dev/null +++ b/meson/test cases/linuxlike/5 dependency versions/subprojects/somelib/meson.build @@ -0,0 +1,11 @@ +# Define version only in project, should get inherited by declare_dependency +project('some', 'c', version : '0.1') + +somelib = library('some', 'lib.c') +someinc = include_directories('.') + +some_dep = declare_dependency(link_with : somelib, + include_directories : someinc) + +fakezlib_dep = declare_dependency(link_with : somelib, + include_directories : someinc) diff --git a/meson/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/lib.c b/meson/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/lib.c new file mode 100644 index 000000000..e69de29bb diff --git a/meson/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/meson.build b/meson/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/meson.build new file mode 100644 index 000000000..aa7e554a5 --- /dev/null +++ b/meson/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/meson.build @@ -0,0 +1,8 @@ +project('some', 'c') + +somelib = library('some', 'lib.c') +someinc = include_directories('.') + +# Define version only in declare_dependency +some_dep = declare_dependency(link_with : somelib, + include_directories : someinc) diff --git a/meson/test cases/linuxlike/5 dependency versions/subprojects/somelibver/lib.c b/meson/test cases/linuxlike/5 dependency versions/subprojects/somelibver/lib.c new file mode 100644 index 000000000..e69de29bb diff --git a/meson/test cases/linuxlike/5 dependency versions/subprojects/somelibver/meson.build b/meson/test cases/linuxlike/5 dependency versions/subprojects/somelibver/meson.build new file mode 100644 index 000000000..c773814a9 --- /dev/null +++ b/meson/test cases/linuxlike/5 dependency versions/subprojects/somelibver/meson.build @@ -0,0 +1,9 @@ +project('some', 'c') + +somelib = library('some', 'lib.c') +someinc = include_directories('.') + +# Define version only in declare_dependency +some_dep = declare_dependency(link_with : somelib, + include_directories : someinc, + version : '0.3') diff --git a/meson/test cases/linuxlike/6 subdir include order/meson.build b/meson/test cases/linuxlike/6 subdir include order/meson.build new file mode 100644 index 000000000..fea3984bb --- /dev/null +++ b/meson/test cases/linuxlike/6 subdir include order/meson.build @@ -0,0 +1,12 @@ +project('subdir include order', 'c') + +# Ensure that headers in subdirs override external dependencies +cc = meson.get_compiler('c') + +glib = dependency('glib-2.0') + +# This will fail to compile if it picks up the system-installed glib instead of +# the glib in the subdir +executable('prog', 'prog.c', + include_directories : include_directories('subdir'), + dependencies : glib) diff --git a/meson/test cases/linuxlike/6 subdir include order/prog.c b/meson/test cases/linuxlike/6 subdir include order/prog.c new file mode 100644 index 000000000..2d47a93ae --- /dev/null +++ b/meson/test cases/linuxlike/6 subdir include order/prog.c @@ -0,0 +1,7 @@ +#include + +#ifndef MESON_OUR_GLIB +#error "Failed" +#endif + +int main(void) { return 0; } diff --git a/meson/test cases/linuxlike/6 subdir include order/subdir/glib.h b/meson/test cases/linuxlike/6 subdir include order/subdir/glib.h new file mode 100644 index 000000000..444b2d0aa --- /dev/null +++ b/meson/test cases/linuxlike/6 subdir include order/subdir/glib.h @@ -0,0 +1 @@ +#define MESON_OUR_GLIB 1 diff --git a/meson/test cases/linuxlike/7 library versions/exe.orig.c b/meson/test cases/linuxlike/7 library versions/exe.orig.c new file mode 100644 index 000000000..1e8e90e76 --- /dev/null +++ b/meson/test cases/linuxlike/7 library versions/exe.orig.c @@ -0,0 +1,8 @@ +int myFunc (void); + +int main(void) +{ + if (myFunc() == 55) + return 0; + return 1; +} diff --git a/meson/test cases/linuxlike/7 library versions/lib.c b/meson/test cases/linuxlike/7 library versions/lib.c new file mode 100644 index 000000000..bd251d777 --- /dev/null +++ b/meson/test cases/linuxlike/7 library versions/lib.c @@ -0,0 +1,3 @@ +int myFunc(void) { + return 55; +} diff --git a/meson/test cases/linuxlike/7 library versions/meson.build b/meson/test cases/linuxlike/7 library versions/meson.build new file mode 100644 index 000000000..516094763 --- /dev/null +++ b/meson/test cases/linuxlike/7 library versions/meson.build @@ -0,0 +1,55 @@ +project('library versions', 'c') + +if host_machine.system() == 'cygwin' + error('MESON_SKIP_TEST linuxlike soversions not supported on Cygwin.') +endif + +some = shared_library('some', 'lib.c', + version : '1.2.3', + soversion : '0', + install : true) + +noversion = shared_library('noversion', 'lib.c', + install : true) + +onlyversion = shared_library('onlyversion', 'lib.c', + version : '1.4.5', + install : true) + +onlysoversion = shared_library('onlysoversion', 'lib.c', + # Also test that int soversion is acceptable + soversion : 5, + install : true) + +# Hack to make the executables below depend on the shared libraries above +# without actually adding them as `link_with` dependencies since we want to try +# linking to them with -lfoo linker arguments. +out = custom_target('library-dependency-hack', + input : 'exe.orig.c', + output : 'exe.c', + depends : [some, noversion, onlyversion, onlysoversion], + command : ['cp', '@INPUT@', '@OUTPUT@']) + +# Need to add this manually because Meson can't add it automatically because +# it doesn't know that we are linking to libraries in the build directory. +rpath_dir = meson.current_build_dir() + +# Manually test if the linker can find the above libraries +# i.e., whether they were generated with the right naming scheme +test('manually linked 1', executable('manuallink1', out, + link_args : ['-L.', '-lsome'], + build_rpath : rpath_dir)) + +test('manually linked 2', executable('manuallink2', out, + link_args : ['-L.', '-lnoversion'], + build_rpath : rpath_dir)) + +test('manually linked 3', executable('manuallink3', out, + link_args : ['-L.', '-lonlyversion'], + build_rpath : rpath_dir)) + +test('manually linked 4', executable('manuallink4', out, + link_args : ['-L.', '-lonlysoversion'], + build_rpath : rpath_dir)) + +shared_module('module', 'lib.c', install : true) diff --git a/meson/test cases/linuxlike/7 library versions/test.json b/meson/test cases/linuxlike/7 library versions/test.json new file mode 100644 index 000000000..0da9277bc --- /dev/null +++ b/meson/test cases/linuxlike/7 library versions/test.json @@ -0,0 +1,14 @@ +{ + "installed": [ + {"type": "file", "file": "usr/lib/libsome.so"}, + {"type": "file", "file": "usr/lib/libsome.so.0"}, + {"type": "file", "file": "usr/lib/libsome.so.1.2.3"}, + {"type": "file", "file": "usr/lib/libnoversion.so"}, + {"type": "file", "file": "usr/lib/libonlyversion.so"}, + {"type": "file", "file": "usr/lib/libonlyversion.so.1"}, + {"type": "file", "file": "usr/lib/libonlyversion.so.1.4.5"}, + {"type": "file", "file": "usr/lib/libonlysoversion.so"}, + {"type": "file", "file": "usr/lib/libonlysoversion.so.5"}, + {"type": "file", "file": "usr/lib/libmodule.so"} + ] +} diff --git a/meson/test cases/linuxlike/8 subproject library install/meson.build b/meson/test cases/linuxlike/8 subproject library install/meson.build new file mode 100644 index 000000000..ff5579947 --- /dev/null +++ b/meson/test cases/linuxlike/8 subproject library install/meson.build @@ -0,0 +1,10 @@ +project('subproj lib install', 'c', + version : '2.3.4', + license : 'mylicense') + +if host_machine.system() == 'cygwin' + error('MESON_SKIP_TEST linuxlike soversions not supported on Cygwin.') +endif + +# Test that the subproject library gets installed +subproject('sublib', version : '1.0.0') diff --git a/meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/include/subdefs.h b/meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/include/subdefs.h new file mode 100644 index 000000000..6ae8462f6 --- /dev/null +++ b/meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/include/subdefs.h @@ -0,0 +1,21 @@ +#ifndef SUBDEFS_H_ +#define SUBDEFS_H_ + +#if defined _WIN32 || defined __CYGWIN__ +#if defined BUILDING_SUB + #define DLL_PUBLIC __declspec(dllexport) +#else + #define DLL_PUBLIC __declspec(dllimport) +#endif +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +int DLL_PUBLIC subfunc(void); + +#endif diff --git a/meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/meson.build b/meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/meson.build new file mode 100644 index 000000000..97658fa5e --- /dev/null +++ b/meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/meson.build @@ -0,0 +1,10 @@ +project('subproject', 'c', + version : '1.0.0', + license : ['sublicense1', 'sublicense2']) + +i = include_directories('include') +shared_library('sublib', 'sublib.c', + version : '2.1.0', + soversion : 5, + include_directories : i, install : true, + c_args : '-DBUILDING_SUB=2') diff --git a/meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/sublib.c b/meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/sublib.c new file mode 100644 index 000000000..f71564f14 --- /dev/null +++ b/meson/test cases/linuxlike/8 subproject library install/subprojects/sublib/sublib.c @@ -0,0 +1,5 @@ +#include + +int DLL_PUBLIC subfunc(void) { + return 42; +} diff --git a/meson/test cases/linuxlike/8 subproject library install/test.json b/meson/test cases/linuxlike/8 subproject library install/test.json new file mode 100644 index 000000000..5a2bf04c5 --- /dev/null +++ b/meson/test cases/linuxlike/8 subproject library install/test.json @@ -0,0 +1,7 @@ +{ + "installed": [ + {"type": "file", "file": "usr/lib/libsublib.so"}, + {"type": "file", "file": "usr/lib/libsublib.so.5"}, + {"type": "file", "file": "usr/lib/libsublib.so.2.1.0"} + ] +} diff --git a/meson/test cases/linuxlike/9 compiler checks with dependencies/meson.build b/meson/test cases/linuxlike/9 compiler checks with dependencies/meson.build new file mode 100644 index 000000000..24a9ac048 --- /dev/null +++ b/meson/test cases/linuxlike/9 compiler checks with dependencies/meson.build @@ -0,0 +1,36 @@ +project('compiler checks with dependencies', 'c') + +cc = meson.get_compiler('c') + +glib = dependency ('glib-2.0') +if glib.found() + assert (cc.has_header('glib.h', dependencies : glib), 'glib.h not found') + assert (cc.has_type('gint32', prefix : '#include ', dependencies : glib), 'gint32 not found') + assert (cc.has_function('g_print', dependencies : glib), 'g_print not found') + assert (cc.has_member('GError', 'message', prefix : '#include ', dependencies : glib), 'GError::message not found') + assert (cc.has_header_symbol('glib.h', 'gint32', dependencies : glib), 'gint32 symbol not found') + linkcode = '''#include +int main (void) { + GError *error = g_error_new_literal (0, 0, NULL); + return error == NULL; +} + ''' + assert (cc.links(linkcode, dependencies : glib, name : 'Test link against glib'), 'Linking test against glib failed') +endif + +zlib = cc.find_library ('z') +if zlib.found() + linkcode = '''#include +int main(void) { + void *ptr = (void*)(deflate); + return ptr == 0; +} +''' + assert (cc.has_function('deflate', prefix : '#include', dependencies : zlib), 'has_function test failed.') + assert (cc.links(linkcode, dependencies : zlib, name : 'Test link against zlib'), 'Linking test failed against zlib.') +endif + +assert(cc.has_function('pthread_create', + dependencies : dependency('threads'), + prefix : '#include '), + 'Could not detect pthread_create with a thread dependency.') -- cgit 1.2.3-korg