summaryrefslogtreecommitdiffstats
path: root/test cases/common/178 bothlibraries
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/common/178 bothlibraries
parentInitial commit. (diff)
downloadmeson-7b6e527f440cd7e6f8be2b07cee320ee6ca18786.tar.xz
meson-7b6e527f440cd7e6f8be2b07cee320ee6ca18786.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/common/178 bothlibraries')
-rw-r--r--test cases/common/178 bothlibraries/dummy.py8
-rw-r--r--test cases/common/178 bothlibraries/foo.cpp11
-rw-r--r--test cases/common/178 bothlibraries/libfile.c7
-rw-r--r--test cases/common/178 bothlibraries/main.c8
-rw-r--r--test cases/common/178 bothlibraries/main2.c9
-rw-r--r--test cases/common/178 bothlibraries/meson.build62
-rw-r--r--test cases/common/178 bothlibraries/mylib.h13
7 files changed, 118 insertions, 0 deletions
diff --git a/test cases/common/178 bothlibraries/dummy.py b/test cases/common/178 bothlibraries/dummy.py
new file mode 100644
index 0000000..9e838ba
--- /dev/null
+++ b/test cases/common/178 bothlibraries/dummy.py
@@ -0,0 +1,8 @@
+#!/usr/bin/env python3
+
+from pathlib import Path
+import sys
+
+if __name__ == '__main__':
+ Path(sys.argv[1]).write_text('Hello World\n')
+ raise SystemExit(0)
diff --git a/test cases/common/178 bothlibraries/foo.cpp b/test cases/common/178 bothlibraries/foo.cpp
new file mode 100644
index 0000000..a705cbc
--- /dev/null
+++ b/test cases/common/178 bothlibraries/foo.cpp
@@ -0,0 +1,11 @@
+#include <memory>
+#include "mylib.h"
+
+extern "C" {
+ DO_EXPORT int foo(void);
+}
+
+int foo(void) {
+ auto bptr = std::make_shared<int>(0);
+ return *bptr;
+}
diff --git a/test cases/common/178 bothlibraries/libfile.c b/test cases/common/178 bothlibraries/libfile.c
new file mode 100644
index 0000000..f5e228e
--- /dev/null
+++ b/test cases/common/178 bothlibraries/libfile.c
@@ -0,0 +1,7 @@
+#include "mylib.h"
+
+DO_EXPORT int retval = 42;
+
+DO_EXPORT int func(void) {
+ return retval;
+}
diff --git a/test cases/common/178 bothlibraries/main.c b/test cases/common/178 bothlibraries/main.c
new file mode 100644
index 0000000..8237bae
--- /dev/null
+++ b/test cases/common/178 bothlibraries/main.c
@@ -0,0 +1,8 @@
+#include "mylib.h"
+
+DO_IMPORT int func(void);
+DO_IMPORT int retval;
+
+int main(void) {
+ return func() == retval ? 0 : 1;
+}
diff --git a/test cases/common/178 bothlibraries/main2.c b/test cases/common/178 bothlibraries/main2.c
new file mode 100644
index 0000000..e1f4bf8
--- /dev/null
+++ b/test cases/common/178 bothlibraries/main2.c
@@ -0,0 +1,9 @@
+#include "mylib.h"
+
+DO_IMPORT int func(void);
+DO_IMPORT int foo(void);
+DO_IMPORT int retval;
+
+int main(void) {
+ return func() + foo() == retval ? 0 : 1;
+}
diff --git a/test cases/common/178 bothlibraries/meson.build b/test cases/common/178 bothlibraries/meson.build
new file mode 100644
index 0000000..bb3a2bc
--- /dev/null
+++ b/test cases/common/178 bothlibraries/meson.build
@@ -0,0 +1,62 @@
+project('both libraries linking test', 'c', 'cpp')
+
+both_libs = both_libraries('mylib', 'libfile.c')
+dep = declare_dependency(link_with: both_libs)
+exe_shared = executable('prog-shared', 'main.c', link_with : both_libs.get_shared_lib())
+exe_static = executable('prog-static', 'main.c',
+ c_args : ['-DSTATIC_COMPILATION'],
+ link_with : both_libs.get_static_lib())
+exe_both = executable('prog-both', 'main.c', link_with : both_libs)
+exe_dep = executable('prog-dep', 'main.c', dependencies : [dep])
+
+# Try using it in a custom_target
+custom_target('tgt_a',
+ command: [
+ find_program('./dummy.py'),
+ '@OUTPUT@',
+ both_libs,
+ ],
+ output: ['hello1.txt'],
+ input: [both_libs],
+)
+
+test('runtest-shared', exe_shared)
+test('runtest-static', exe_static)
+test('runtest-both', exe_both)
+test('runtest-dep', exe_dep)
+
+# Same as above, but using build_target()
+both_libs2 = build_target('mylib2', 'libfile.c', target_type: 'both_libraries')
+exe_shared2 = executable('prog-shared2', 'main.c',
+ link_with : both_libs2.get_shared_lib())
+exe_static2 = executable('prog-static2', 'main.c',
+ c_args : ['-DSTATIC_COMPILATION'],
+ link_with : both_libs2.get_static_lib())
+exe_both2 = executable('prog-both2', 'main.c', link_with : both_libs2)
+
+# Test {set,get}_variable
+set_variable('both_libs2', both_libs)
+both_libs3 = get_variable('both_libs')
+
+# Ensure that calling the build target methods also works
+assert(both_libs.name() == 'mylib')
+assert(both_libs2.name() == 'mylib')
+assert(both_libs3.name() == 'mylib')
+assert(both_libs2.get_shared_lib().name() == 'mylib')
+assert(both_libs3.get_static_lib().name() == 'mylib')
+
+test('runtest-shared-2', exe_shared2)
+test('runtest-static-2', exe_static2)
+test('runtest-both-2', exe_both2)
+
+# Regression test: libccpp has both C and C++ sources. The executable only has
+# C sources. It should still link using the C++ compiler. When using
+# both_libraries the static has no sources and thus no compilers, resulting in
+# the executable linking using the C compiler.
+# https://github.com/Netflix/vmaf/issues/1107
+libccpp = both_libraries('ccpp', 'foo.cpp', 'libfile.c')
+exe = executable('prog-ccpp', 'main2.c',
+ link_with: libccpp.get_static_lib(),
+ c_args : ['-DSTATIC_COMPILATION'],
+)
+test('runtest-ccpp', exe)
diff --git a/test cases/common/178 bothlibraries/mylib.h b/test cases/common/178 bothlibraries/mylib.h
new file mode 100644
index 0000000..1038a01
--- /dev/null
+++ b/test cases/common/178 bothlibraries/mylib.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#ifdef _WIN32
+ #ifdef STATIC_COMPILATION
+ #define DO_IMPORT extern
+ #else
+ #define DO_IMPORT __declspec(dllimport)
+ #endif
+ #define DO_EXPORT __declspec(dllexport)
+#else
+ #define DO_IMPORT extern
+ #define DO_EXPORT
+#endif