meson: Add meson build

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Id1694bde6c57cab65ca86b00f64285f4d6224b2d
diff --git a/.gitignore b/.gitignore
index 6500baa..6da54be 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,29 +1,3 @@
-*.o
-*.lo
-*.la
-*.sw*
-Makefile
-Makefile.in
-configure
-.deps
-.libs
-aclocal.m4
-ar-lib
-*-libtool
-autom4te.cache/
-compile
-config.guess
-config.h
-config.h.in
-config.log
-config.status
-config.sub
-depcomp
-install-sh
-ltmain.sh
-missing
-stamp-h1
-phosphor-dbus-monitor
-generated.hpp
-errors.hpp
-test-driver
+build*/
+subprojects/*
+!subprojects/*.wrap
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..7573271
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,35 @@
+project(
+    'phosphor-dbus-monitor', 'cpp',
+    version : '1.0.0',
+    meson_version: '>=0.58.0',
+    default_options: [
+        'warning_level=3',
+        'werror=true',
+        'cpp_std=c++20',
+        'buildtype=debugoptimized',
+    ]
+)
+
+conf_data = configuration_data()
+conf_data.set_quoted('OBJ_EVENT', '/xyz/openbmc_project/events')
+conf_data.set_quoted('BUSNAME_EVENT', 'xyz.openbmc_project.Events')
+conf_data.set_quoted('EVENTS_PERSIST_PATH', '/var/lib/phosphor-dbus-monitor/events')
+
+conf_data.set('CLASS_VERSION', 1)
+conf_data.set('MAX_EVENTS', 20)
+
+sdbusplus_dep = dependency('sdbusplus')
+sdeventplus_dep = dependency('sdeventplus')
+phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
+phosphor_logging_dep = dependency('phosphor-logging')
+phosphor_snmp_dep = dependency('phosphor-snmp')
+
+prog_python = find_program('python3', required: true)
+realpath_prog = find_program('realpath')
+
+configure_file(output: 'config.h',
+    configuration: conf_data
+)
+
+subdir('src')
+subdir('mslverify')
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..c124f67
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,11 @@
+option(
+    'tests', type : 'feature',
+    value: 'enabled',
+    description : 'Build tests'
+)
+
+option(
+    'YAML_PATH', type: 'string',
+    value: 'src/example',
+    description: 'The path to the yaml config files.'
+)
\ No newline at end of file
diff --git a/mslverify/meson.build b/mslverify/meson.build
new file mode 100644
index 0000000..9f7baca
--- /dev/null
+++ b/mslverify/meson.build
@@ -0,0 +1,18 @@
+sources_mslverify = [
+    'verify.cpp',
+]
+
+deps_mslverify = [
+    sdbusplus_dep,
+    phosphor_dbus_interfaces_dep,
+    phosphor_logging_dep,
+]
+
+executable(
+    'phosphor-msl-verify',
+    sources_mslverify,
+    implicit_include_directories: true,
+    dependencies: deps_mslverify,
+    install: true,
+    install_dir: get_option('bindir'),
+)
diff --git a/src/meson.build b/src/meson.build
new file mode 100644
index 0000000..54e39f9
--- /dev/null
+++ b/src/meson.build
@@ -0,0 +1,61 @@
+templates_depends = files(
+    'example/example.yaml',
+    'example/test.yaml',
+    'templates/callbackgroup.mako.cpp',
+    'templates/conditional.mako.cpp',
+    'templates/count.mako.cpp',
+    'templates/median.mako.cpp',
+    'templates/generated.mako.hpp',
+    'templates/journal.mako.cpp',
+    'templates/elog.mako.cpp',
+    'templates/errors.mako.hpp',
+    'templates/method.mako.cpp',
+    'templates/resolve_errors.mako.cpp',
+    'templates/event.mako.cpp',
+)
+
+generated_hpp = custom_target(
+    'generated.hpp',
+    command: [
+        prog_python,
+        meson.project_source_root() + '/src/pdmgen.py',
+        '-t', 'generated.mako.hpp',
+        '-p', meson.project_source_root() + '/src/templates',
+        '-d', meson.project_source_root() + '/' + get_option('YAML_PATH'),
+        '-o', meson.current_build_dir() + '/generated.hpp',
+        'generate-cpp'
+    ],
+    depend_files: templates_depends,
+    output: 'generated.hpp',
+)
+
+sources = [
+    generated_hpp,
+    'elog.cpp',
+    'event_manager.cpp',
+    'event_serialize.cpp',
+    'journal.cpp',
+    'main.cpp',
+    'pathwatch.cpp',
+    'propertywatch.cpp',
+    'resolve_errors.cpp',
+    'snmp_trap.cpp',
+]
+
+deps = [
+    sdbusplus_dep,
+    sdeventplus_dep,
+    phosphor_dbus_interfaces_dep,
+    phosphor_logging_dep,
+    phosphor_snmp_dep,
+]
+
+executable(
+    'phosphor-dbus-monitor',
+    sources,
+    include_directories: ['..'],
+    implicit_include_directories: true,
+    dependencies: deps,
+    install: true,
+    install_dir: get_option('bindir'),
+)