aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/common/215 source set realistic example
diff options
context:
space:
mode:
authorAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
committerAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
commitaf1a266670d040d2f4083ff309d732d648afba2a (patch)
tree2fc46203448ddcc6f81546d379abfaeb323575e9 /meson/test cases/common/215 source set realistic example
parente02cda008591317b1625707ff8e115a4841aa889 (diff)
Add submodule dependency filesHEADmaster
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'meson/test cases/common/215 source set realistic example')
-rw-r--r--meson/test cases/common/215 source set realistic example/boards/arm/aarch64.cc8
-rw-r--r--meson/test cases/common/215 source set realistic example/boards/arm/arm.cc10
-rw-r--r--meson/test cases/common/215 source set realistic example/boards/arm/arm.h12
-rw-r--r--meson/test cases/common/215 source set realistic example/boards/arm/arm32.cc8
-rw-r--r--meson/test cases/common/215 source set realistic example/boards/arm/versatilepb.cc16
-rw-r--r--meson/test cases/common/215 source set realistic example/boards/arm/virt.cc16
-rw-r--r--meson/test cases/common/215 source set realistic example/boards/arm/xlnx_zcu102.cc16
-rw-r--r--meson/test cases/common/215 source set realistic example/boards/meson.build7
-rw-r--r--meson/test cases/common/215 source set realistic example/boards/x86/pc.cc26
-rw-r--r--meson/test cases/common/215 source set realistic example/common.h41
-rw-r--r--meson/test cases/common/215 source set realistic example/config/aarch645
-rw-r--r--meson/test cases/common/215 source set realistic example/config/arm3
-rw-r--r--meson/test cases/common/215 source set realistic example/config/x864
-rw-r--r--meson/test cases/common/215 source set realistic example/devices/meson.build3
-rw-r--r--meson/test cases/common/215 source set realistic example/devices/virtio-mmio.cc16
-rw-r--r--meson/test cases/common/215 source set realistic example/devices/virtio-pci.cc16
-rw-r--r--meson/test cases/common/215 source set realistic example/devices/virtio.cc6
-rw-r--r--meson/test cases/common/215 source set realistic example/devices/virtio.h10
-rw-r--r--meson/test cases/common/215 source set realistic example/main.cc32
-rw-r--r--meson/test cases/common/215 source set realistic example/meson.build52
-rw-r--r--meson/test cases/common/215 source set realistic example/not-found.cc8
-rw-r--r--meson/test cases/common/215 source set realistic example/was-found.cc7
-rw-r--r--meson/test cases/common/215 source set realistic example/zlib.cc15
23 files changed, 337 insertions, 0 deletions
diff --git a/meson/test cases/common/215 source set realistic example/boards/arm/aarch64.cc b/meson/test cases/common/215 source set realistic example/boards/arm/aarch64.cc
new file mode 100644
index 000000000..386c771d8
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/boards/arm/aarch64.cc
@@ -0,0 +1,8 @@
+#include "common.h"
+#include <iostream>
+
+void initialize_target()
+{
+ std::cout << ANSI_START << "some " << THE_TARGET
+ << " initialization" << ANSI_END << std::endl;
+}
diff --git a/meson/test cases/common/215 source set realistic example/boards/arm/arm.cc b/meson/test cases/common/215 source set realistic example/boards/arm/arm.cc
new file mode 100644
index 000000000..b463ebe7a
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/boards/arm/arm.cc
@@ -0,0 +1,10 @@
+#include "arm.h"
+
+const char *ARMBoard::target()
+{
+ return THE_TARGET;
+}
+
+void ARMBoard::some_arm_thing()
+{
+}
diff --git a/meson/test cases/common/215 source set realistic example/boards/arm/arm.h b/meson/test cases/common/215 source set realistic example/boards/arm/arm.h
new file mode 100644
index 000000000..4dd6b694f
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/boards/arm/arm.h
@@ -0,0 +1,12 @@
+#ifndef ARM_H
+#define ARM_H 1
+
+#include "common.h"
+
+struct ARMBoard: Board {
+ const char *target();
+ void some_arm_thing();
+};
+
+
+#endif
diff --git a/meson/test cases/common/215 source set realistic example/boards/arm/arm32.cc b/meson/test cases/common/215 source set realistic example/boards/arm/arm32.cc
new file mode 100644
index 000000000..72a24274a
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/boards/arm/arm32.cc
@@ -0,0 +1,8 @@
+#include "common.h"
+#include <iostream>
+
+void initialize_target()
+{
+ std::cout << ANSI_START << "a different " << THE_TARGET
+ << " initialization" << ANSI_END << std::endl;
+}
diff --git a/meson/test cases/common/215 source set realistic example/boards/arm/versatilepb.cc b/meson/test cases/common/215 source set realistic example/boards/arm/versatilepb.cc
new file mode 100644
index 000000000..3d1a9fe7c
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/boards/arm/versatilepb.cc
@@ -0,0 +1,16 @@
+#include <iostream>
+#include "common.h"
+#include "arm.h"
+
+struct VersatilePBBoard: ARMBoard {
+ void say_hello();
+};
+
+void VersatilePBBoard::say_hello()
+{
+ some_arm_thing();
+ std::cout << ANSI_START << "I am the versatilepb board"
+ << ANSI_END << std::endl;
+}
+
+static VersatilePBBoard versatilepb;
diff --git a/meson/test cases/common/215 source set realistic example/boards/arm/virt.cc b/meson/test cases/common/215 source set realistic example/boards/arm/virt.cc
new file mode 100644
index 000000000..6f9a1ca94
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/boards/arm/virt.cc
@@ -0,0 +1,16 @@
+#include <iostream>
+#include "common.h"
+#include "arm.h"
+
+struct VirtBoard: ARMBoard {
+ void say_hello();
+};
+
+void VirtBoard::say_hello()
+{
+ some_arm_thing();
+ std::cout << ANSI_START << "I am the virt board"
+ << ANSI_END << std::endl;
+}
+
+static VirtBoard virt;
diff --git a/meson/test cases/common/215 source set realistic example/boards/arm/xlnx_zcu102.cc b/meson/test cases/common/215 source set realistic example/boards/arm/xlnx_zcu102.cc
new file mode 100644
index 000000000..8921e0074
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/boards/arm/xlnx_zcu102.cc
@@ -0,0 +1,16 @@
+#include <iostream>
+#include "common.h"
+#include "arm.h"
+
+struct XlnxZCU102Board: ARMBoard {
+ void say_hello();
+};
+
+void XlnxZCU102Board::say_hello()
+{
+ some_arm_thing();
+ std::cout << ANSI_START << "I am the xlnx_zcu102 board"
+ << ANSI_END << std::endl;
+}
+
+static XlnxZCU102Board xlnx_zcu102;
diff --git a/meson/test cases/common/215 source set realistic example/boards/meson.build b/meson/test cases/common/215 source set realistic example/boards/meson.build
new file mode 100644
index 000000000..41ead4c3e
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/boards/meson.build
@@ -0,0 +1,7 @@
+specific.add(when: 'TARGET_ARM', if_true: files('arm/arm.cc', 'arm/arm32.cc'))
+specific.add(when: 'TARGET_AARCH64', if_true: files('arm/arm.cc', 'arm/aarch64.cc'))
+specific.add(when: 'CONFIG_VIRT', if_true: files('arm/virt.cc'))
+specific.add(when: 'CONFIG_XLNX_ZCU102', if_true: files('arm/xlnx_zcu102.cc'))
+specific.add(when: 'CONFIG_VERSATILEPB', if_true: files('arm/versatilepb.cc'))
+
+specific.add(when: 'TARGET_X86', if_true: files('x86/pc.cc'))
diff --git a/meson/test cases/common/215 source set realistic example/boards/x86/pc.cc b/meson/test cases/common/215 source set realistic example/boards/x86/pc.cc
new file mode 100644
index 000000000..04ec39262
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/boards/x86/pc.cc
@@ -0,0 +1,26 @@
+#include <iostream>
+#include "common.h"
+
+struct X86Board: Board {
+ const char *target();
+ void say_hello();
+};
+
+const char *X86Board::target()
+{
+ return THE_TARGET;
+}
+
+void X86Board::say_hello()
+{
+ std::cout << ANSI_START << "I am a 1996 PC"
+ << ANSI_END << std::endl;
+}
+
+void initialize_target()
+{
+ std::cout << ANSI_START << "ready, set, go"
+ << ANSI_END << std::endl;
+}
+
+static X86Board pc;
diff --git a/meson/test cases/common/215 source set realistic example/common.h b/meson/test cases/common/215 source set realistic example/common.h
new file mode 100644
index 000000000..6e325c7bc
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/common.h
@@ -0,0 +1,41 @@
+#ifndef COMMON_H
+#define COMMON_H 1
+
+/*
+ * target-specific code will print in yellow, common code will print
+ * in grey.
+ */
+#ifdef THE_TARGET
+#define ANSI_START "\x1b[33;1m"
+#define ANSI_END "\x1b[0m"
+#else
+#define ANSI_START ""
+#define ANSI_END ""
+#endif
+
+void some_random_function();
+void initialize_target();
+
+struct Board {
+ Board *next;
+ Board();
+ virtual ~Board();
+ virtual void say_hello() = 0;
+ virtual const char *target() = 0;
+};
+
+struct Device {
+ Device *next;
+ Device();
+ virtual ~Device();
+ virtual void say_hello() = 0;
+};
+
+struct Dependency {
+ Dependency *next;
+ Dependency();
+ virtual ~Dependency();
+ virtual void initialize() = 0;
+};
+
+#endif
diff --git a/meson/test cases/common/215 source set realistic example/config/aarch64 b/meson/test cases/common/215 source set realistic example/config/aarch64
new file mode 100644
index 000000000..55b90ebee
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/config/aarch64
@@ -0,0 +1,5 @@
+TARGET_AARCH64=y
+CONFIG_VIRT=y
+CONFIG_XLNX_ZCU102=y
+CONFIG_VIRTIO=y
+CONFIG_VIRTIO_MMIO=y
diff --git a/meson/test cases/common/215 source set realistic example/config/arm b/meson/test cases/common/215 source set realistic example/config/arm
new file mode 100644
index 000000000..d3f7ac761
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/config/arm
@@ -0,0 +1,3 @@
+TARGET_ARM=y
+CONFIG_VIRT=y
+CONFIG_VERSATILEPB=y
diff --git a/meson/test cases/common/215 source set realistic example/config/x86 b/meson/test cases/common/215 source set realistic example/config/x86
new file mode 100644
index 000000000..6caa3e244
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/config/x86
@@ -0,0 +1,4 @@
+TARGET_X86=y
+CONFIG_PC=y
+CONFIG_VIRTIO=y
+CONFIG_VIRTIO_PCI=y
diff --git a/meson/test cases/common/215 source set realistic example/devices/meson.build b/meson/test cases/common/215 source set realistic example/devices/meson.build
new file mode 100644
index 000000000..68ee68eec
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/devices/meson.build
@@ -0,0 +1,3 @@
+specific.add(when: 'CONFIG_VIRTIO', if_true: files('virtio.cc'))
+common.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('virtio-pci.cc'))
+common.add(when: 'CONFIG_VIRTIO_MMIO', if_true: files('virtio-mmio.cc'))
diff --git a/meson/test cases/common/215 source set realistic example/devices/virtio-mmio.cc b/meson/test cases/common/215 source set realistic example/devices/virtio-mmio.cc
new file mode 100644
index 000000000..5dab97e5c
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/devices/virtio-mmio.cc
@@ -0,0 +1,16 @@
+#include <iostream>
+#include "common.h"
+#include "virtio.h"
+
+struct VirtioMMIODevice: VirtioDevice {
+ void say_hello();
+};
+
+void VirtioMMIODevice::say_hello()
+{
+ some_virtio_thing();
+ std::cout << ANSI_START << "virtio-mmio is available"
+ << ANSI_END << std::endl;
+}
+
+static VirtioMMIODevice virtio_mmio;
diff --git a/meson/test cases/common/215 source set realistic example/devices/virtio-pci.cc b/meson/test cases/common/215 source set realistic example/devices/virtio-pci.cc
new file mode 100644
index 000000000..7df7a82b7
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/devices/virtio-pci.cc
@@ -0,0 +1,16 @@
+#include <iostream>
+#include "common.h"
+#include "virtio.h"
+
+struct VirtioPCIDevice: VirtioDevice {
+ void say_hello();
+};
+
+void VirtioPCIDevice::say_hello()
+{
+ some_virtio_thing();
+ std::cout << ANSI_START << "virtio-pci is available"
+ << ANSI_END << std::endl;
+}
+
+static VirtioPCIDevice virtio_pci;
diff --git a/meson/test cases/common/215 source set realistic example/devices/virtio.cc b/meson/test cases/common/215 source set realistic example/devices/virtio.cc
new file mode 100644
index 000000000..fc51275bf
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/devices/virtio.cc
@@ -0,0 +1,6 @@
+#include <iostream>
+#include "common.h"
+#include "virtio.h"
+
+void VirtioDevice::some_virtio_thing() {
+}
diff --git a/meson/test cases/common/215 source set realistic example/devices/virtio.h b/meson/test cases/common/215 source set realistic example/devices/virtio.h
new file mode 100644
index 000000000..a157731fe
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/devices/virtio.h
@@ -0,0 +1,10 @@
+#ifndef VIRTIO_H
+#define VIRTIO_H 1
+
+#include "common.h"
+
+struct VirtioDevice: Device {
+ void some_virtio_thing();
+};
+
+#endif
diff --git a/meson/test cases/common/215 source set realistic example/main.cc b/meson/test cases/common/215 source set realistic example/main.cc
new file mode 100644
index 000000000..2b552176b
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/main.cc
@@ -0,0 +1,32 @@
+#include <iostream>
+#include <vector>
+#include "common.h"
+
+Board* boards;
+Device* devices;
+Dependency* deps;
+
+Board::Board() { this->next = boards; boards = this; }
+Board::~Board() {}
+
+Device::Device() { this->next = devices; devices = this; }
+Device::~Device() {}
+
+Dependency::Dependency() { this->next = deps; deps = this; }
+Dependency::~Dependency() {}
+
+int main(void)
+{
+ some_random_function();
+ for (auto d = deps; d; d = d->next)
+ d->initialize();
+
+ initialize_target();
+ for (auto b = boards; b; b = b->next) {
+ std::cout << ANSI_START << b->target() << " - " << ANSI_END;
+ b->say_hello();
+ }
+
+ for (auto d = devices; d; d = d->next)
+ d->say_hello();
+}
diff --git a/meson/test cases/common/215 source set realistic example/meson.build b/meson/test cases/common/215 source set realistic example/meson.build
new file mode 100644
index 000000000..d986b991a
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/meson.build
@@ -0,0 +1,52 @@
+# a sort-of realistic example that combines the sourceset and keyval
+# modules, inspired by QEMU's build system
+
+project('sourceset-example', 'cpp', default_options: ['cpp_std=c++11'])
+
+cppid = meson.get_compiler('cpp').get_id()
+if cppid == 'pgi'
+ error('MESON_SKIP_TEST: Even PGI 19.4 that claims C++17 full support, cannot handle auto x = y syntax used in this test.')
+endif
+
+ss = import('sourceset')
+keyval = import('keyval')
+
+zlib = declare_dependency(compile_args: '-DZLIB=1')
+another = declare_dependency(compile_args: '-DANOTHER=1')
+not_found = dependency('not-found', required: false)
+
+common = ss.source_set()
+specific = ss.source_set()
+
+common.add(files('main.cc'))
+common.add(when: [zlib, another], if_true: files('zlib.cc'))
+common.add(when: not_found,
+ if_true: files('was-found.cc'),
+ if_false: files('not-found.cc'))
+
+subdir('boards')
+subdir('devices')
+
+if meson.is_unity()
+ specific.add_all(common)
+ common = ss.source_set()
+endif
+
+common_lib = static_library('common', common.all_sources(),
+ dependencies: common.all_dependencies())
+
+targets = [ 'arm', 'aarch64', 'x86' ]
+target_dirs = { 'arm' : 'arm', 'aarch64' : 'arm', 'x86': 'x86' }
+
+foreach x : targets
+ config = keyval.load('config' / x)
+ target_specific = specific.apply(config, strict: false)
+ target_common = common.apply(config, strict: false)
+ target_deps = target_specific.dependencies() + target_common.dependencies()
+ executable(x,
+ objects: common_lib.extract_objects(target_common.sources()),
+ sources: target_specific.sources(),
+ dependencies: target_deps,
+ include_directories: 'boards' / target_dirs[x],
+ cpp_args: '-DTHE_TARGET="' + x + '"')
+endforeach
diff --git a/meson/test cases/common/215 source set realistic example/not-found.cc b/meson/test cases/common/215 source set realistic example/not-found.cc
new file mode 100644
index 000000000..955a7a2a6
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/not-found.cc
@@ -0,0 +1,8 @@
+#include <iostream>
+#include "common.h"
+
+void some_random_function()
+{
+ std::cout << ANSI_START << "everything's alright"
+ << ANSI_END << std::endl;
+}
diff --git a/meson/test cases/common/215 source set realistic example/was-found.cc b/meson/test cases/common/215 source set realistic example/was-found.cc
new file mode 100644
index 000000000..f1eaf1ea5
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/was-found.cc
@@ -0,0 +1,7 @@
+#include <iostream>
+
+void some_random_function()
+{
+ std::cout << ANSI_START << "huh?"
+ << ANSI_END << std::endl;
+}
diff --git a/meson/test cases/common/215 source set realistic example/zlib.cc b/meson/test cases/common/215 source set realistic example/zlib.cc
new file mode 100644
index 000000000..434e0b7a6
--- /dev/null
+++ b/meson/test cases/common/215 source set realistic example/zlib.cc
@@ -0,0 +1,15 @@
+#include <iostream>
+#include "common.h"
+
+struct ZLibDependency : Dependency {
+ void initialize();
+};
+
+void ZLibDependency::initialize() {
+ if (ZLIB && ANOTHER) {
+ std::cout << ANSI_START << "hello from zlib"
+ << ANSI_END << std::endl;
+ }
+}
+
+ZLibDependency zlib;