sourceset: add a realistic example as a testcase

pull/5028/head
Paolo Bonzini 6 years ago
parent d894c48660
commit 06b1f457d5
  1. 8
      test cases/common/223 source set realistic example/boards/arm/aarch64.cc
  2. 10
      test cases/common/223 source set realistic example/boards/arm/arm.cc
  3. 12
      test cases/common/223 source set realistic example/boards/arm/arm.h
  4. 8
      test cases/common/223 source set realistic example/boards/arm/arm32.cc
  5. 16
      test cases/common/223 source set realistic example/boards/arm/versatilepb.cc
  6. 16
      test cases/common/223 source set realistic example/boards/arm/virt.cc
  7. 16
      test cases/common/223 source set realistic example/boards/arm/xlnx_zcu102.cc
  8. 7
      test cases/common/223 source set realistic example/boards/meson.build
  9. 26
      test cases/common/223 source set realistic example/boards/x86/pc.cc
  10. 41
      test cases/common/223 source set realistic example/common.h
  11. 5
      test cases/common/223 source set realistic example/config/aarch64
  12. 3
      test cases/common/223 source set realistic example/config/arm
  13. 4
      test cases/common/223 source set realistic example/config/x86
  14. 3
      test cases/common/223 source set realistic example/devices/meson.build
  15. 16
      test cases/common/223 source set realistic example/devices/virtio-mmio.cc
  16. 16
      test cases/common/223 source set realistic example/devices/virtio-pci.cc
  17. 6
      test cases/common/223 source set realistic example/devices/virtio.cc
  18. 10
      test cases/common/223 source set realistic example/devices/virtio.h
  19. 32
      test cases/common/223 source set realistic example/main.cc
  20. 44
      test cases/common/223 source set realistic example/meson.build
  21. 8
      test cases/common/223 source set realistic example/not-found.cc
  22. 7
      test cases/common/223 source set realistic example/was-found.cc
  23. 13
      test cases/common/223 source set realistic example/zlib.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;
}

@ -0,0 +1,10 @@
#include "arm.h"
const char *ARMBoard::target()
{
return THE_TARGET;
}
void ARMBoard::some_arm_thing()
{
}

@ -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

@ -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;
}

@ -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;

@ -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;

@ -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;

@ -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'))

@ -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;

@ -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

@ -0,0 +1,5 @@
TARGET_AARCH64=y
CONFIG_VIRT=y
CONFIG_XLNX_ZCU102=y
CONFIG_VIRTIO=y
CONFIG_VIRTIO_MMIO=y

@ -0,0 +1,3 @@
TARGET_ARM=y
CONFIG_VIRT=y
CONFIG_VERSATILEPB=y

@ -0,0 +1,4 @@
TARGET_X86=y
CONFIG_PC=y
CONFIG_VIRTIO=y
CONFIG_VIRTIO_PCI=y

@ -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'))

@ -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;

@ -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;

@ -0,0 +1,6 @@
#include <iostream>
#include "common.h"
#include "virtio.h"
void VirtioDevice::some_virtio_thing() {
}

@ -0,0 +1,10 @@
#ifndef VIRTIO_H
#define VIRTIO_H 1
#include "common.h"
struct VirtioDevice: Device {
void some_virtio_thing();
};
#endif

@ -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()
{
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();
}

@ -0,0 +1,44 @@
# a sort-of realistic example that combines the sourceset and kconfig
# modules, inspired by QEMU's build system
project('sourceset-example', 'cpp')
ss = import('sourceset')
kconfig = import('unstable-kconfig')
zlib = dependency('zlib', version : '>=1.2.8', required: false)
not_found = dependency('not-found', required: false)
common = ss.source_set()
specific = ss.source_set()
common.add(files('main.cc'))
common.add(when: zlib, 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())
targets = [ 'arm', 'aarch64', 'x86' ]
target_dirs = { 'arm' : 'arm', 'aarch64' : 'arm', 'x86': 'x86' }
foreach x : targets
config = kconfig.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

@ -0,0 +1,8 @@
#include <iostream>
#include "common.h"
void some_random_function()
{
std::cout << ANSI_START << "everything's alright"
<< ANSI_END << std::endl;
}

@ -0,0 +1,7 @@
#include <iostream>
void some_random_function()
{
std::cout << ANSI_START << "huh?"
<< ANSI_END << std::endl;
}

@ -0,0 +1,13 @@
#include <iostream>
#include "common.h"
struct ZLibDependency : Dependency {
void initialize();
};
void ZLibDependency::initialize() {
std::cout << ANSI_START << "hello from zlib"
<< ANSI_END << std::endl;
}
ZLibDependency zlib;
Loading…
Cancel
Save