summaryrefslogtreecommitdiffstats
path: root/test cases/linuxlike/13 cmake dependency
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:41:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:41:38 +0000
commit7b6e527f440cd7e6f8be2b07cee320ee6ca18786 (patch)
tree4a2738d69fa2814659fdadddf5826282e73d81f4 /test cases/linuxlike/13 cmake dependency
parentInitial commit. (diff)
downloadmeson-upstream.tar.xz
meson-upstream.zip
Adding upstream version 1.0.1.upstream/1.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test cases/linuxlike/13 cmake dependency')
-rw-r--r--test cases/linuxlike/13 cmake dependency/cmake/FindImportedOldStyle.cmake5
-rw-r--r--test cases/linuxlike/13 cmake dependency/cmake/FindImportedTarget.cmake15
-rw-r--r--test cases/linuxlike/13 cmake dependency/cmake/FindSomethingLikeZLIB.cmake56
-rw-r--r--test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake11
-rw-r--r--test cases/linuxlike/13 cmake dependency/cmake_fake2/cmMesonTestF2Config.cmake9
-rw-r--r--test cases/linuxlike/13 cmake dependency/cmake_fake3/bin/.gitkeep0
-rw-r--r--test cases/linuxlike/13 cmake dependency/cmake_fake3/lib/cmake/cmMesonTestF3/cmMesonTestF3Config.cmake9
-rw-r--r--test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonTestDep/cmMesonTestDepConfig.cmake9
-rw-r--r--test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfig.cmake9
-rw-r--r--test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonVersionedTestDep/cmMesonVersionedTestDepConfigVersion.cmake12
-rw-r--r--test cases/linuxlike/13 cmake dependency/incdir/myinc.h3
-rw-r--r--test cases/linuxlike/13 cmake dependency/meson.build101
-rw-r--r--test cases/linuxlike/13 cmake dependency/prog-checkver.c15
-rw-r--r--test cases/linuxlike/13 cmake dependency/prog.c8
-rw-r--r--test cases/linuxlike/13 cmake dependency/test.json14
-rw-r--r--test cases/linuxlike/13 cmake dependency/testFlagSet.c18
16 files changed, 294 insertions, 0 deletions
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;
+}