aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/common/213 source set dictionary
diff options
context:
space:
mode:
Diffstat (limited to 'meson/test cases/common/213 source set dictionary')
-rw-r--r--meson/test cases/common/213 source set dictionary/a.c8
-rw-r--r--meson/test cases/common/213 source set dictionary/all.h9
-rw-r--r--meson/test cases/common/213 source set dictionary/f.c7
-rw-r--r--meson/test cases/common/213 source set dictionary/g.c6
-rw-r--r--meson/test cases/common/213 source set dictionary/meson.build56
-rw-r--r--meson/test cases/common/213 source set dictionary/nope.c3
-rw-r--r--meson/test cases/common/213 source set dictionary/subdir/b.c13
-rw-r--r--meson/test cases/common/213 source set dictionary/subdir/meson.build1
8 files changed, 103 insertions, 0 deletions
diff --git a/meson/test cases/common/213 source set dictionary/a.c b/meson/test cases/common/213 source set dictionary/a.c
new file mode 100644
index 000000000..0570dffc4
--- /dev/null
+++ b/meson/test cases/common/213 source set dictionary/a.c
@@ -0,0 +1,8 @@
+#include <stdlib.h>
+#include "all.h"
+
+int main(void)
+{
+ if (p) abort();
+ f();
+}
diff --git a/meson/test cases/common/213 source set dictionary/all.h b/meson/test cases/common/213 source set dictionary/all.h
new file mode 100644
index 000000000..e3547dfdc
--- /dev/null
+++ b/meson/test cases/common/213 source set dictionary/all.h
@@ -0,0 +1,9 @@
+extern void f(void);
+extern void g(void);
+extern void h(void);
+extern void undefined(void);
+
+/* Defined in nope.c and f.c,
+ * value depends on the source set and configuration used.
+ */
+extern void (*p)(void);
diff --git a/meson/test cases/common/213 source set dictionary/f.c b/meson/test cases/common/213 source set dictionary/f.c
new file mode 100644
index 000000000..9c5bb1cb9
--- /dev/null
+++ b/meson/test cases/common/213 source set dictionary/f.c
@@ -0,0 +1,7 @@
+#include "all.h"
+
+void (*p)(void) = (void *)0x1234ABCD;
+
+void f(void)
+{
+}
diff --git a/meson/test cases/common/213 source set dictionary/g.c b/meson/test cases/common/213 source set dictionary/g.c
new file mode 100644
index 000000000..4a6f253b0
--- /dev/null
+++ b/meson/test cases/common/213 source set dictionary/g.c
@@ -0,0 +1,6 @@
+#include "all.h"
+
+void g(void)
+{
+ h();
+}
diff --git a/meson/test cases/common/213 source set dictionary/meson.build b/meson/test cases/common/213 source set dictionary/meson.build
new file mode 100644
index 000000000..9a3450707
--- /dev/null
+++ b/meson/test cases/common/213 source set dictionary/meson.build
@@ -0,0 +1,56 @@
+project('a', 'c')
+
+good = declare_dependency(link_with: static_library('good', 'g.c'))
+bad = declare_dependency(link_args: 'nonexistent.a')
+not_found = dependency('invalid', required: false)
+
+source_set = import('sourceset')
+
+sources = source_set.source_set()
+sources.add(when: 'YES', if_false: ['nope.c'])
+sources.add(when: 'YES1', if_true: files('a.c'))
+subdir('subdir')
+sources.add(when: 'NO', if_true: 'nope.c', if_false: ['f.c'])
+sources.add(when: 'NO', if_true: bad, if_false: ['f.c'])
+
+sources.add(when: 'YES2', if_true: good)
+
+# dependencies as conditions
+sources.add(when: not_found, if_true: 'nope.c')
+
+# test add_all
+sources2 = source_set.source_set()
+sources2.add(when: 'YES1', if_true: 'nope.c')
+sources.add_all(when: 'NO', if_true: sources2)
+
+# test duplicate items
+sources.add(when: 'YES1', if_true: files('a.c'))
+
+conf1 = {
+ 'YES': true,
+ 'YES1': true,
+ 'YES2': false,
+ 'NO': false,
+}
+result1 = sources.apply(conf1)
+
+conf2 = {
+ 'YES': true,
+ 'YES1': false,
+ 'YES2': true,
+ 'NO': false,
+}
+result2 = sources.apply(conf2)
+
+# Each target will recompile the objects
+executable('first', sources: result1.sources(), dependencies: result1.dependencies())
+executable('second', sources: result2.sources(), dependencies: result2.dependencies())
+
+# All target will use the same object files
+if meson.is_unity()
+ message('Skipping extraction test because this is a Unity build.')
+else
+ all_objs = static_library('all_objs', sources.all_sources())
+ executable('first_via_lib', objects: all_objs.extract_objects(result1.sources()), dependencies: result1.dependencies())
+ executable('second_via_lib', objects: all_objs.extract_objects(result2.sources()), dependencies: result2.dependencies())
+endif
diff --git a/meson/test cases/common/213 source set dictionary/nope.c b/meson/test cases/common/213 source set dictionary/nope.c
new file mode 100644
index 000000000..0ce1d3b1e
--- /dev/null
+++ b/meson/test cases/common/213 source set dictionary/nope.c
@@ -0,0 +1,3 @@
+#include "all.h"
+
+void (*p)(void) = undefined;
diff --git a/meson/test cases/common/213 source set dictionary/subdir/b.c b/meson/test cases/common/213 source set dictionary/subdir/b.c
new file mode 100644
index 000000000..31c378934
--- /dev/null
+++ b/meson/test cases/common/213 source set dictionary/subdir/b.c
@@ -0,0 +1,13 @@
+#include <stdlib.h>
+#include "all.h"
+
+void h(void)
+{
+}
+
+int main(void)
+{
+ if (p) abort();
+ f();
+ g();
+}
diff --git a/meson/test cases/common/213 source set dictionary/subdir/meson.build b/meson/test cases/common/213 source set dictionary/subdir/meson.build
new file mode 100644
index 000000000..b497de574
--- /dev/null
+++ b/meson/test cases/common/213 source set dictionary/subdir/meson.build
@@ -0,0 +1 @@
+sources.add(when: ['YES2', good], if_true: [ files('b.c') ])