build: Add meson build

Change-Id: I0c42715b0f15c3caabf04da290ab6b99c50bbc13
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..154ef19
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,73 @@
+project(
+  'google-ipmi-sys',
+  'cpp',
+  version: '0.1',
+  meson_version: '>=0.51.0',
+  default_options: [
+    'cpp_std=c++17',
+    'warning_level=3',
+    'werror=true',
+  ])
+
+meson.get_compiler('cpp').has_header_symbol(
+  'ipmid/api.h',
+  'ipmid_get_sd_bus_connection')
+
+json_dep = dependency('nlohmann_json', required: false)
+meson.get_compiler('cpp').has_header_symbol(
+  'nlohmann/json.hpp',
+  'nlohmann::json',
+  dependencies: json_dep)
+
+sys_pre = declare_dependency(
+  include_directories: include_directories('.'),
+  dependencies: [
+    json_dep,
+    dependency('phosphor-dbus-interfaces'),
+    dependency('phosphor-logging'),
+    dependency('sdbusplus'),
+  ])
+
+sys_lib = static_library(
+  'sys',
+  'cable.cpp',
+  'cpld.cpp',
+  'entity_name.cpp',
+  'eth.cpp',
+  'flash_size.cpp',
+  'handler.cpp',
+  'host_power_off.cpp',
+  'ipmi.cpp',
+  'machine_name.cpp',
+  'pcie_i2c.cpp',
+  'psu.cpp',
+  'util.cpp',
+  implicit_include_directories: false,
+  dependencies: sys_pre)
+
+sys_dep = declare_dependency(
+  link_with: sys_lib,
+  dependencies: sys_pre)
+
+if not get_option('tests').disabled()
+  subdir('test')
+endif
+
+shared_module(
+  'googlesys',
+  'main.cpp',
+  implicit_include_directories: false,
+  dependencies: [
+    dependency('libipmid'),
+    sys_dep,
+  ],
+  install: true,
+  install_dir: get_option('libdir') / 'ipmid-providers')
+
+systemd_dep = dependency('systemd')
+if systemd_dep.found()
+  install_data(
+    'gbmc-host-poweroff.target',
+    'gbmc-psu-hardreset.target',
+    install_dir: systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir'))
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..0fc2767
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1 @@
+option('tests', type: 'feature', description: 'Build tests')
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..0dc3b49
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,25 @@
+gtest = dependency('gtest', main: true, disabler: true, required: get_option('tests'))
+gmock = dependency('gmock', disabler: true, required: get_option('tests'))
+
+tests = [
+  'cable',
+  'cpld',
+  'entity',
+  'eth',
+  'flash',
+  'handler',
+  'machine',
+  'pcie',
+  'poweroff',
+  'psu',
+]
+
+foreach t : tests
+  test(
+    t,
+    executable(
+      t.underscorify(),
+      t + '_unittest.cpp',
+      implicit_include_directories: false,
+      dependencies: [sys_dep, gtest, gmock]))
+endforeach