aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/common/173 as-needed
diff options
context:
space:
mode:
Diffstat (limited to 'meson/test cases/common/173 as-needed')
-rw-r--r--meson/test cases/common/173 as-needed/config.h14
-rw-r--r--meson/test cases/common/173 as-needed/libA.cpp7
-rw-r--r--meson/test cases/common/173 as-needed/libA.h5
-rw-r--r--meson/test cases/common/173 as-needed/libB.cpp19
-rw-r--r--meson/test cases/common/173 as-needed/main.cpp7
-rw-r--r--meson/test cases/common/173 as-needed/meson.build13
6 files changed, 65 insertions, 0 deletions
diff --git a/meson/test cases/common/173 as-needed/config.h b/meson/test cases/common/173 as-needed/config.h
new file mode 100644
index 000000000..b8fb60fe4
--- /dev/null
+++ b/meson/test cases/common/173 as-needed/config.h
@@ -0,0 +1,14 @@
+#if defined _WIN32 || defined __CYGWIN__
+ #if defined BUILDING_DLL
+ #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
diff --git a/meson/test cases/common/173 as-needed/libA.cpp b/meson/test cases/common/173 as-needed/libA.cpp
new file mode 100644
index 000000000..5f45bc077
--- /dev/null
+++ b/meson/test cases/common/173 as-needed/libA.cpp
@@ -0,0 +1,7 @@
+#define BUILDING_DLL
+
+#include "libA.h"
+
+namespace meson_test_as_needed {
+ DLL_PUBLIC bool linked = false;
+}
diff --git a/meson/test cases/common/173 as-needed/libA.h b/meson/test cases/common/173 as-needed/libA.h
new file mode 100644
index 000000000..8e76d22fa
--- /dev/null
+++ b/meson/test cases/common/173 as-needed/libA.h
@@ -0,0 +1,5 @@
+#include "config.h"
+
+namespace meson_test_as_needed {
+ DLL_PUBLIC extern bool linked;
+}
diff --git a/meson/test cases/common/173 as-needed/libB.cpp b/meson/test cases/common/173 as-needed/libB.cpp
new file mode 100644
index 000000000..a8723941b
--- /dev/null
+++ b/meson/test cases/common/173 as-needed/libB.cpp
@@ -0,0 +1,19 @@
+#include "libA.h"
+
+#undef DLL_PUBLIC
+#define BUILDING_DLL
+#include "config.h"
+
+namespace meson_test_as_needed {
+ namespace {
+ bool set_linked() {
+ linked = true;
+ return true;
+ }
+ bool stub = set_linked();
+ }
+
+ DLL_PUBLIC int libB_unused_func() {
+ return 0;
+ }
+}
diff --git a/meson/test cases/common/173 as-needed/main.cpp b/meson/test cases/common/173 as-needed/main.cpp
new file mode 100644
index 000000000..a893431d4
--- /dev/null
+++ b/meson/test cases/common/173 as-needed/main.cpp
@@ -0,0 +1,7 @@
+#include <cstdlib>
+
+#include "libA.h"
+
+int main(void) {
+ return !meson_test_as_needed::linked ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/meson/test cases/common/173 as-needed/meson.build b/meson/test cases/common/173 as-needed/meson.build
new file mode 100644
index 000000000..3b54aaa02
--- /dev/null
+++ b/meson/test cases/common/173 as-needed/meson.build
@@ -0,0 +1,13 @@
+project('as-needed test', 'cpp')
+
+# Idea behind this test is to have -Wl,--as-needed prune
+# away unneeded linkages, which would otherwise cause global
+# static initialiser side-effects to set a boolean to true.
+
+# Credits for portable ISO C++ idea go to sarum9in
+
+libA = library('A', 'libA.cpp')
+libB = library('B', 'libB.cpp', link_with : libA)
+
+main_exe = executable('C', 'main.cpp', link_with : [libA, libB])
+test('main test', main_exe)