meson: Add alternative build system

For now both autotools and meson will be maintained side by side.
Eventually we should remove the autotools build system.

Change-Id: I04382b17d5267ee218e2658fc163da17853f637a
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/example/meson.build b/example/meson.build
new file mode 100644
index 0000000..1f18444
--- /dev/null
+++ b/example/meson.build
@@ -0,0 +1,13 @@
+examples = [
+  'delayed_echo',
+  'follow',
+  'heartbeat',
+  'heartbeat_timer',
+]
+
+foreach example : examples
+  executable(example, example + '.cpp',
+             include_directories: includes,
+             implicit_include_directories: false,
+             link_with: sdeventplus)
+endforeach
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..ac9951c
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,21 @@
+project('sdeventplus', 'cpp',
+        version: '0.1', meson_version: '>=0.49.0',
+        default_options: [
+          'warning_level=3',
+          'werror=true',
+          'cpp_std=c++17'
+        ])
+
+includes = include_directories('src')
+
+subdir('src')
+
+build_tests = get_option('tests')
+build_examples = get_option('examples')
+
+if build_examples
+  subdir('example')
+endif
+if not build_tests.disabled()
+  subdir('test')
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..86bc7fc
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,2 @@
+option('tests', type: 'feature', description: 'Build tests')
+option('examples', type: 'boolean', value: true, description: 'Build examples')
diff --git a/src/meson.build b/src/meson.build
new file mode 100644
index 0000000..4e8b5b5
--- /dev/null
+++ b/src/meson.build
@@ -0,0 +1,58 @@
+libsystemd = dependency('libsystemd')
+
+sdeventplus = library(
+  'sdeventplus',
+  [
+    'sdeventplus/clock.cpp',
+    'sdeventplus/event.cpp',
+    'sdeventplus/exception.cpp',
+    'sdeventplus/internal/sdevent.cpp',
+    'sdeventplus/internal/sdref.cpp',
+    'sdeventplus/source/base.cpp',
+    'sdeventplus/source/child.cpp',
+    'sdeventplus/source/event.cpp',
+    'sdeventplus/source/io.cpp',
+    'sdeventplus/source/signal.cpp',
+    'sdeventplus/source/time.cpp',
+    'sdeventplus/utility/timer.cpp'
+  ],
+  include_directories: includes,
+  implicit_include_directories: false,
+  dependencies: libsystemd,
+  install: true)
+
+import('pkgconfig').generate(
+  name: 'sdeventplus',
+  description: 'C++ systemd event wrapper',
+  version: meson.project_version(),
+  libraries: [sdeventplus],
+)
+
+install_headers(
+  'sdeventplus/clock.hpp',
+  'sdeventplus/event.hpp',
+  'sdeventplus/exception.hpp',
+  subdir: 'sdeventplus')
+
+install_headers(
+  'sdeventplus/internal/sdevent.hpp',
+  'sdeventplus/internal/sdref.hpp',
+  'sdeventplus/internal/utils.hpp',
+  subdir: 'sdeventplus/internal')
+
+install_headers(
+  'sdeventplus/source/base.hpp',
+  'sdeventplus/source/child.hpp',
+  'sdeventplus/source/event.hpp',
+  'sdeventplus/source/io.hpp',
+  'sdeventplus/source/signal.hpp',
+  'sdeventplus/source/time.hpp',
+  subdir: 'sdeventplus/source')
+
+install_headers(
+  'sdeventplus/test/sdevent.hpp',
+  subdir: 'sdeventplus/test')
+
+install_headers(
+  'sdeventplus/utility/timer.hpp',
+  subdir: 'sdeventplus/utility')
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..d894a3f
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,25 @@
+gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
+gmock = dependency('gmock', disabler: true, required: build_tests)
+
+tests = [
+  'clock',
+  'event',
+  'exception',
+  'internal/sdref',
+  'internal/utils',
+  'source/base',
+  'source/child',
+  'source/event',
+  'source/io',
+  'source/signal',
+  'source/time',
+  'utility/timer',
+]
+
+foreach t : tests
+  test(t, executable(t.underscorify(), t + '.cpp',
+                     include_directories: includes,
+                     implicit_include_directories: false,
+                     link_with: sdeventplus,
+                     dependencies: [gtest, gmock]))
+endforeach