diff options
Diffstat (limited to 'meson/test cases/linuxlike/13 cmake dependency')
16 files changed, 289 insertions, 0 deletions
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 $<$<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/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 <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/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 --- /dev/null +++ b/meson/test cases/linuxlike/13 cmake dependency/cmake_fake3/bin/.gitkeep 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<zlib.h> 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<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/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 <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/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<zlib.h> + +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<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; +} |