diff options
Diffstat (limited to '')
75 files changed, 1099 insertions, 0 deletions
diff --git a/test cases/linuxlike/1 pkg-config/incdir/myinc.h b/test cases/linuxlike/1 pkg-config/incdir/myinc.h new file mode 100644 index 0000000..4b66a6c --- /dev/null +++ b/test cases/linuxlike/1 pkg-config/incdir/myinc.h @@ -0,0 +1,3 @@ +#pragma once + +#include<zlib.h> diff --git a/test cases/linuxlike/1 pkg-config/meson.build b/test cases/linuxlike/1 pkg-config/meson.build new file mode 100644 index 0000000..ca48e9b --- /dev/null +++ b/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<myinc.h> + +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/test cases/linuxlike/1 pkg-config/prog-checkver.c b/test cases/linuxlike/1 pkg-config/prog-checkver.c new file mode 100644 index 0000000..ea1ed32 --- /dev/null +++ b/test cases/linuxlike/1 pkg-config/prog-checkver.c @@ -0,0 +1,15 @@ +#include <zlib.h> +#include <stdio.h> +#include <string.h> + +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/test cases/linuxlike/1 pkg-config/prog.c b/test cases/linuxlike/1 pkg-config/prog.c new file mode 100644 index 0000000..eccc477 --- /dev/null +++ b/test cases/linuxlike/1 pkg-config/prog.c @@ -0,0 +1,8 @@ +#include<zlib.h> + +int main(void) { + void * something = deflate; + if(something != 0) + return 0; + return 1; +} diff --git a/test cases/linuxlike/10 large file support/meson.build b/test cases/linuxlike/10 large file support/meson.build new file mode 100644 index 0000000..6683345 --- /dev/null +++ b/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/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib.c b/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib.c new file mode 100644 index 0000000..2784e01 --- /dev/null +++ b/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib.c @@ -0,0 +1,3 @@ +int some_symbol (void) { + return RET_VALUE; +} diff --git a/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib1/meson.build b/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib1/meson.build new file mode 100644 index 0000000..cbc75bd --- /dev/null +++ b/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/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib2/meson.build b/test cases/linuxlike/11 runpath rpath ldlibrarypath/lib2/meson.build new file mode 100644 index 0000000..f2c6dcc --- /dev/null +++ b/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/test cases/linuxlike/11 runpath rpath ldlibrarypath/main.c b/test cases/linuxlike/11 runpath rpath ldlibrarypath/main.c new file mode 100644 index 0000000..5009531 --- /dev/null +++ b/test cases/linuxlike/11 runpath rpath ldlibrarypath/main.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +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/test cases/linuxlike/11 runpath rpath ldlibrarypath/meson.build b/test cases/linuxlike/11 runpath rpath ldlibrarypath/meson.build new file mode 100644 index 0000000..a3103ac --- /dev/null +++ b/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/test cases/linuxlike/12 subprojects in subprojects/main.c b/test cases/linuxlike/12 subprojects in subprojects/main.c new file mode 100644 index 0000000..7452317 --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/main.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include "a.h" +#include "b.h" + +int main(void) { + int life = a_fun() + b_fun(); + printf("%d\n", life); + return 0; +} diff --git a/test cases/linuxlike/12 subprojects in subprojects/meson.build b/test cases/linuxlike/12 subprojects in subprojects/meson.build new file mode 100644 index 0000000..4014149 --- /dev/null +++ b/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/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.c b/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.c new file mode 100644 index 0000000..f7dd126 --- /dev/null +++ b/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/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.h b/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.h new file mode 100644 index 0000000..9de0deb --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/a.h @@ -0,0 +1 @@ +int a_fun(void); diff --git a/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/meson.build b/test cases/linuxlike/12 subprojects in subprojects/subprojects/a/meson.build new file mode 100644 index 0000000..5f579a3 --- /dev/null +++ b/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/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.c b/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.c new file mode 100644 index 0000000..45c9348 --- /dev/null +++ b/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/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.h b/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.h new file mode 100644 index 0000000..47b84d4 --- /dev/null +++ b/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/b.h @@ -0,0 +1 @@ +int b_fun(void); diff --git a/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/meson.build b/test cases/linuxlike/12 subprojects in subprojects/subprojects/b/meson.build new file mode 100644 index 0000000..80903f3 --- /dev/null +++ b/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/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/c.h b/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/c.h new file mode 100644 index 0000000..b2e3f9b --- /dev/null +++ b/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/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/meson.build b/test cases/linuxlike/12 subprojects in subprojects/subprojects/c/meson.build new file mode 100644 index 0000000..7184933 --- /dev/null +++ b/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/test cases/linuxlike/13 cmake dependency/cmake/FindImportedOldStyle.cmake b/test cases/linuxlike/13 cmake dependency/cmake/FindImportedOldStyle.cmake new file mode 100644 index 0000000..595b887 --- /dev/null +++ b/test cases/linuxlike/13 cmake dependency/cmake/FindImportedOldStyle.cmake @@ -0,0 +1,5 @@ +find_package(ZLIB) + +set(IMPORTEDOLDSTYLE_LIBRARIES ZLIB::ZLIB) +set(IMPORTEDOLDSTYLE_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}) +set(IMPORTEDOLDSTYLE_FOUND ON) diff --git a/test cases/linuxlike/13 cmake dependency/cmake/FindImportedTarget.cmake b/test cases/linuxlike/13 cmake dependency/cmake/FindImportedTarget.cmake new file mode 100644 index 0000000..1dd1657 --- /dev/null +++ b/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 $<$<NOT:$<CONFIG:Debug>>:;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/test cases/linuxlike/13 cmake dependency/cmake/FindSomethingLikeZLIB.cmake b/test cases/linuxlike/13 cmake dependency/cmake/FindSomethingLikeZLIB.cmake new file mode 100644 index 0000000..483926c --- /dev/null +++ b/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 <iostream> + +using namespace std; + +int main(void) { + cout << \"Hello World\" << endl; + return 0; +} +" +CXX_CODE_RAN +) + +check_c_source_runs( +" +#include <stdio.h> + +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/test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake b/test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake new file mode 100644 index 0000000..4b3f814 --- /dev/null +++ b/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/test cases/linuxlike/13 cmake dependency/cmake_fake2/cmMesonTestF2Config.cmake b/test cases/linuxlike/13 cmake dependency/cmake_fake2/cmMesonTestF2Config.cmake new file mode 100644 index 0000000..a7a55d8 --- /dev/null +++ b/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/test cases/linuxlike/13 cmake dependency/cmake_fake3/bin/.gitkeep b/test cases/linuxlike/13 cmake dependency/cmake_fake3/bin/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/linuxlike/13 cmake dependency/cmake_fake3/bin/.gitkeep diff --git a/test cases/linuxlike/13 cmake dependency/cmake_fake3/lib/cmake/cmMesonTestF3/cmMesonTestF3Config.cmake b/test cases/linuxlike/13 cmake dependency/cmake_fake3/lib/cmake/cmMesonTestF3/cmMesonTestF3Config.cmake new file mode 100644 index 0000000..2fab395 --- /dev/null +++ b/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/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonTestDep/cmMesonTestDepConfig.cmake b/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonTestDep/cmMesonTestDepConfig.cmake new file mode 100644 index 0000000..06a2060 --- /dev/null +++ b/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/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfig.cmake b/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfig.cmake new file mode 100644 index 0000000..d3adcb7 --- /dev/null +++ b/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/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfigVersion.cmake b/test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfigVersion.cmake new file mode 100644 index 0000000..5b9905d --- /dev/null +++ b/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/test cases/linuxlike/13 cmake dependency/incdir/myinc.h b/test cases/linuxlike/13 cmake dependency/incdir/myinc.h new file mode 100644 index 0000000..4b66a6c --- /dev/null +++ b/test cases/linuxlike/13 cmake dependency/incdir/myinc.h @@ -0,0 +1,3 @@ +#pragma once + +#include<zlib.h> diff --git a/test cases/linuxlike/13 cmake dependency/meson.build b/test cases/linuxlike/13 cmake dependency/meson.build new file mode 100644 index 0000000..193ad18 --- /dev/null +++ b/test cases/linuxlike/13 cmake dependency/meson.build @@ -0,0 +1,101 @@ +# 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 + +# 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') + + +# Mix of imported targets and old style variables + +depio1 = dependency('ImportedOldStyle', required : true, cmake_module_path : 'cmake') + +# Try to actually link with depio1, since we are doing even more "fun" stuff there +exe4 = executable('zlibprog4', 'prog.c', dependencies : depio1) +test('zlibtest4', exe4) + +# Test some edge cases with spaces, etc. (but only for CMake >= 3.15) + +if find_program('cmake', required: false, version: '>=3.15').found() + 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 shouldn\'t 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<myinc.h> + +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/test cases/linuxlike/13 cmake dependency/prog-checkver.c b/test cases/linuxlike/13 cmake dependency/prog-checkver.c new file mode 100644 index 0000000..ea1ed32 --- /dev/null +++ b/test cases/linuxlike/13 cmake dependency/prog-checkver.c @@ -0,0 +1,15 @@ +#include <zlib.h> +#include <stdio.h> +#include <string.h> + +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/test cases/linuxlike/13 cmake dependency/prog.c b/test cases/linuxlike/13 cmake dependency/prog.c new file mode 100644 index 0000000..eccc477 --- /dev/null +++ b/test cases/linuxlike/13 cmake dependency/prog.c @@ -0,0 +1,8 @@ +#include<zlib.h> + +int main(void) { + void * something = deflate; + if(something != 0) + return 0; + return 1; +} diff --git a/test cases/linuxlike/13 cmake dependency/test.json b/test cases/linuxlike/13 cmake dependency/test.json new file mode 100644 index 0000000..1505986 --- /dev/null +++ b/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/test cases/linuxlike/13 cmake dependency/testFlagSet.c b/test cases/linuxlike/13 cmake dependency/testFlagSet.c new file mode 100644 index 0000000..1f93ea3 --- /dev/null +++ b/test cases/linuxlike/13 cmake dependency/testFlagSet.c @@ -0,0 +1,18 @@ +#include<stdio.h> +#include<zlib.h> + +#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/test cases/linuxlike/14 static dynamic linkage/main.c b/test cases/linuxlike/14 static dynamic linkage/main.c new file mode 100644 index 0000000..09d1509 --- /dev/null +++ b/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/test cases/linuxlike/14 static dynamic linkage/meson.build b/test cases/linuxlike/14 static dynamic linkage/meson.build new file mode 100644 index 0000000..fb0e353 --- /dev/null +++ b/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/test cases/linuxlike/14 static dynamic linkage/verify_static.py b/test cases/linuxlike/14 static dynamic linkage/verify_static.py new file mode 100755 index 0000000..8d16d48 --- /dev/null +++ b/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/test cases/linuxlike/15 ld binary/meson.build b/test cases/linuxlike/15 ld binary/meson.build new file mode 100644 index 0000000..6452813 --- /dev/null +++ b/test cases/linuxlike/15 ld binary/meson.build @@ -0,0 +1,4 @@ +project('ld binary') + +ld = find_program('ld') +assert(run_command(ld, '--version', check: false).returncode() == 0) diff --git a/test cases/linuxlike/2 external library/meson.build b/test cases/linuxlike/2 external library/meson.build new file mode 100644 index 0000000..3188ebf --- /dev/null +++ b/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<zlib.h> +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/test cases/linuxlike/2 external library/prog.c b/test cases/linuxlike/2 external library/prog.c new file mode 100644 index 0000000..eccc477 --- /dev/null +++ b/test cases/linuxlike/2 external library/prog.c @@ -0,0 +1,8 @@ +#include<zlib.h> + +int main(void) { + void * something = deflate; + if(something != 0) + return 0; + return 1; +} diff --git a/test cases/linuxlike/3 linker script/bob.c b/test cases/linuxlike/3 linker script/bob.c new file mode 100644 index 0000000..50e29c7 --- /dev/null +++ b/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/test cases/linuxlike/3 linker script/bob.h b/test cases/linuxlike/3 linker script/bob.h new file mode 100644 index 0000000..351e2fc --- /dev/null +++ b/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/test cases/linuxlike/3 linker script/bob.map b/test cases/linuxlike/3 linker script/bob.map new file mode 100644 index 0000000..e07a780 --- /dev/null +++ b/test cases/linuxlike/3 linker script/bob.map @@ -0,0 +1,6 @@ +V1_0_0 { + global: + "bobMcBob"; + local: + *; +}; diff --git a/test cases/linuxlike/3 linker script/bob.map.in b/test cases/linuxlike/3 linker script/bob.map.in new file mode 100644 index 0000000..f695e4a --- /dev/null +++ b/test cases/linuxlike/3 linker script/bob.map.in @@ -0,0 +1,6 @@ +V1_0_0 { + global: + "@in@"; + local: + *; +}; diff --git a/test cases/linuxlike/3 linker script/copy.py b/test cases/linuxlike/3 linker script/copy.py new file mode 100644 index 0000000..49e7a85 --- /dev/null +++ b/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/test cases/linuxlike/3 linker script/meson.build b/test cases/linuxlike/3 linker script/meson.build new file mode 100644 index 0000000..5901bf7 --- /dev/null +++ b/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/test cases/linuxlike/3 linker script/prog.c b/test cases/linuxlike/3 linker script/prog.c new file mode 100644 index 0000000..b010b15 --- /dev/null +++ b/test cases/linuxlike/3 linker script/prog.c @@ -0,0 +1,5 @@ +#include"bob.h" + +int main(void) { + return bobMcBob() != 42; +} diff --git a/test cases/linuxlike/3 linker script/sub/foo.map b/test cases/linuxlike/3 linker script/sub/foo.map new file mode 100644 index 0000000..e07a780 --- /dev/null +++ b/test cases/linuxlike/3 linker script/sub/foo.map @@ -0,0 +1,6 @@ +V1_0_0 { + global: + "bobMcBob"; + local: + *; +}; diff --git a/test cases/linuxlike/3 linker script/sub/meson.build b/test cases/linuxlike/3 linker script/sub/meson.build new file mode 100644 index 0000000..93199f3 --- /dev/null +++ b/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/test cases/linuxlike/4 extdep static lib/lib.c b/test cases/linuxlike/4 extdep static lib/lib.c new file mode 100644 index 0000000..bbda9aa --- /dev/null +++ b/test cases/linuxlike/4 extdep static lib/lib.c @@ -0,0 +1,8 @@ +#include<zlib.h> + +int statlibfunc(void) { + void * something = deflate; + if(something != 0) + return 0; + return 1; +} diff --git a/test cases/linuxlike/4 extdep static lib/meson.build b/test cases/linuxlike/4 extdep static lib/meson.build new file mode 100644 index 0000000..1a73e49 --- /dev/null +++ b/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/test cases/linuxlike/4 extdep static lib/prog.c b/test cases/linuxlike/4 extdep static lib/prog.c new file mode 100644 index 0000000..0aeb827 --- /dev/null +++ b/test cases/linuxlike/4 extdep static lib/prog.c @@ -0,0 +1,5 @@ +int statlibfunc(void); + +int main(void) { + return statlibfunc(); +} diff --git a/test cases/linuxlike/5 dependency versions/meson.build b/test cases/linuxlike/5 dependency versions/meson.build new file mode 100644 index 0000000..164e679 --- /dev/null +++ b/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/test cases/linuxlike/5 dependency versions/subprojects/fakezlib/meson.build b/test cases/linuxlike/5 dependency versions/subprojects/fakezlib/meson.build new file mode 100644 index 0000000..5a07763 --- /dev/null +++ b/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/test cases/linuxlike/5 dependency versions/subprojects/somelib/lib.c b/test cases/linuxlike/5 dependency versions/subprojects/somelib/lib.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/linuxlike/5 dependency versions/subprojects/somelib/lib.c diff --git a/test cases/linuxlike/5 dependency versions/subprojects/somelib/meson.build b/test cases/linuxlike/5 dependency versions/subprojects/somelib/meson.build new file mode 100644 index 0000000..670b10f --- /dev/null +++ b/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/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/lib.c b/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/lib.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/lib.c diff --git a/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/meson.build b/test cases/linuxlike/5 dependency versions/subprojects/somelibnover/meson.build new file mode 100644 index 0000000..aa7e554 --- /dev/null +++ b/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/test cases/linuxlike/5 dependency versions/subprojects/somelibver/lib.c b/test cases/linuxlike/5 dependency versions/subprojects/somelibver/lib.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/linuxlike/5 dependency versions/subprojects/somelibver/lib.c diff --git a/test cases/linuxlike/5 dependency versions/subprojects/somelibver/meson.build b/test cases/linuxlike/5 dependency versions/subprojects/somelibver/meson.build new file mode 100644 index 0000000..c773814 --- /dev/null +++ b/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/test cases/linuxlike/6 subdir include order/meson.build b/test cases/linuxlike/6 subdir include order/meson.build new file mode 100644 index 0000000..fea3984 --- /dev/null +++ b/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/test cases/linuxlike/6 subdir include order/prog.c b/test cases/linuxlike/6 subdir include order/prog.c new file mode 100644 index 0000000..2d47a93 --- /dev/null +++ b/test cases/linuxlike/6 subdir include order/prog.c @@ -0,0 +1,7 @@ +#include <glib.h> + +#ifndef MESON_OUR_GLIB +#error "Failed" +#endif + +int main(void) { return 0; } diff --git a/test cases/linuxlike/6 subdir include order/subdir/glib.h b/test cases/linuxlike/6 subdir include order/subdir/glib.h new file mode 100644 index 0000000..444b2d0 --- /dev/null +++ b/test cases/linuxlike/6 subdir include order/subdir/glib.h @@ -0,0 +1 @@ +#define MESON_OUR_GLIB 1 diff --git a/test cases/linuxlike/7 library versions/exe.orig.c b/test cases/linuxlike/7 library versions/exe.orig.c new file mode 100644 index 0000000..1e8e90e --- /dev/null +++ b/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/test cases/linuxlike/7 library versions/lib.c b/test cases/linuxlike/7 library versions/lib.c new file mode 100644 index 0000000..bd251d7 --- /dev/null +++ b/test cases/linuxlike/7 library versions/lib.c @@ -0,0 +1,3 @@ +int myFunc(void) { + return 55; +} diff --git a/test cases/linuxlike/7 library versions/meson.build b/test cases/linuxlike/7 library versions/meson.build new file mode 100644 index 0000000..5160947 --- /dev/null +++ b/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/test cases/linuxlike/7 library versions/test.json b/test cases/linuxlike/7 library versions/test.json new file mode 100644 index 0000000..0da9277 --- /dev/null +++ b/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/test cases/linuxlike/8 subproject library install/meson.build b/test cases/linuxlike/8 subproject library install/meson.build new file mode 100644 index 0000000..ff55799 --- /dev/null +++ b/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/test cases/linuxlike/8 subproject library install/subprojects/sublib/include/subdefs.h b/test cases/linuxlike/8 subproject library install/subprojects/sublib/include/subdefs.h new file mode 100644 index 0000000..6ae8462 --- /dev/null +++ b/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/test cases/linuxlike/8 subproject library install/subprojects/sublib/meson.build b/test cases/linuxlike/8 subproject library install/subprojects/sublib/meson.build new file mode 100644 index 0000000..97658fa --- /dev/null +++ b/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/test cases/linuxlike/8 subproject library install/subprojects/sublib/sublib.c b/test cases/linuxlike/8 subproject library install/subprojects/sublib/sublib.c new file mode 100644 index 0000000..f71564f --- /dev/null +++ b/test cases/linuxlike/8 subproject library install/subprojects/sublib/sublib.c @@ -0,0 +1,5 @@ +#include<subdefs.h> + +int DLL_PUBLIC subfunc(void) { + return 42; +} diff --git a/test cases/linuxlike/8 subproject library install/test.json b/test cases/linuxlike/8 subproject library install/test.json new file mode 100644 index 0000000..5a2bf04 --- /dev/null +++ b/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/test cases/linuxlike/9 compiler checks with dependencies/meson.build b/test cases/linuxlike/9 compiler checks with dependencies/meson.build new file mode 100644 index 0000000..24a9ac0 --- /dev/null +++ b/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 <glib.h>', 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 <glib.h>', dependencies : glib), 'GError::message not found') + assert (cc.has_header_symbol('glib.h', 'gint32', dependencies : glib), 'gint32 symbol not found') + linkcode = '''#include <glib.h> +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<zlib.h> +int main(void) { + void *ptr = (void*)(deflate); + return ptr == 0; +} +''' + assert (cc.has_function('deflate', prefix : '#include<zlib.h>', 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 <pthread.h>'), + 'Could not detect pthread_create with a thread dependency.') |