meson: Add meson build

This commit is to add meson build.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: If7b62fa788406148836615237eb8df553aeb3351
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..f8de17d
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,127 @@
+project(
+    'phosphor-inventory-manager', '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('BUSNAME', 'xyz.openbmc_project.Inventory.Manager')
+conf_data.set_quoted('INVENTORY_ROOT', '/xyz/openbmc_project/inventory')
+conf_data.set_quoted('IFACE', 'xyz.openbmc_project.Inventory.Manager')
+conf_data.set_quoted('PIM_PERSIST_PATH', '/var/lib/phosphor-inventory-manager')
+conf_data.set_quoted('ASSOCIATIONS_FILE_PATH', '/usr/share/phosphor-inventory-manager/associations.json')
+conf_data.set('CLASS_VERSION', 2)
+conf_data.set('CREATE_ASSOCIATIONS', get_option('associations').enabled())
+configure_file(output: 'config.h',
+    configuration: conf_data
+)
+
+cpp = meson.get_compiler('cpp')
+# Get Cereal dependency.
+cereal_dep = dependency('cereal', required: false)
+has_cereal = cpp.has_header_symbol(
+    'cereal/cereal.hpp',
+    'cereal::specialize',
+    dependencies: cereal_dep,
+    required: false)
+if not has_cereal
+    cereal_opts = import('cmake').subproject_options()
+    cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'})
+    cereal_proj = import('cmake').subproject(
+        'cereal',
+        options: cereal_opts,
+        required: false)
+    assert(cereal_proj.found(), 'cereal is required')
+    cereal_dep = cereal_proj.dependency('cereal')
+endif
+
+sdbusplus_dep = dependency('sdbusplus')
+phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
+phosphor_logging_dep = dependency('phosphor-logging')
+
+prog_python = find_program('python3', required: true)
+
+sources = []
+deps = []
+if get_option('associations').enabled()
+    cpp = meson.get_compiler('cpp')
+    if cpp.has_header('nlohmann/json.hpp')
+        nlohmann_json_dep = declare_dependency()
+    else
+        subproject('nlohmann', required: false)
+        nlohmann_json_dep = declare_dependency(
+            include_directories: [
+                'subprojects/nlohmann/single_include',
+                'subprojects/nlohmann/single_include/nlohmann',
+            ]
+        )
+    endif
+    sources += [
+        'association_manager.cpp',
+    ]
+    deps += [
+        nlohmann_json_dep,
+    ]
+endif
+
+ifacesdir = get_option('IFACES_PATH')
+if ifacesdir == ''
+    ifacesdir = phosphor_dbus_interfaces_dep.get_variable(pkgconfig: 'yamldir', internal: 'yamldir')
+endif
+
+generated_cpp = custom_target(
+    'generated.cpp',
+    command : [
+        prog_python,
+        meson.project_source_root() + '/pimgen.py',
+        '-i', ifacesdir,
+        '-d', get_option('YAML_PATH'),
+        '-o', meson.current_build_dir(),
+        '-b', '$BUSNAME',
+        'generate-cpp'
+    ],
+    output : 'generated.cpp')
+
+gen_serialization_hpp = custom_target(
+    'gen_serialization.hpp',
+    command : [
+        prog_python,
+        meson.project_source_root() + '/pimgen.py',
+        '-i', ifacesdir,
+        '-d', get_option('YAML_PATH'),
+        '-o', meson.current_build_dir(),
+        '-b', '$BUSNAME',
+        'generate-serialization'
+    ],
+    output : 'gen_serialization.hpp')
+
+sources += [
+    generated_cpp,
+    gen_serialization_hpp,
+    'app.cpp',
+    'errors.cpp',
+    'functor.cpp',
+    'manager.cpp',
+]
+
+deps += [
+    cereal_dep,
+    phosphor_dbus_interfaces_dep,
+    phosphor_logging_dep,
+    sdbusplus_dep,
+]
+
+executable(
+    'phosphor-inventory',
+    sources,
+    implicit_include_directories: true,
+    dependencies: deps,
+    install: true,
+    install_dir: get_option('bindir'),
+)
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..8d5578a
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,16 @@
+option(
+    'associations', type : 'feature',
+    value: 'enabled',
+    description : 'Enable creating D-Bus associations from a JSON definition'
+)
+
+option(
+    'YAML_PATH', type: 'string',
+    value: '/usr/share/phosphor-inventory-manager',
+    description: 'The path to the yaml config files.'
+)
+
+option(
+    'IFACES_PATH', type: 'string',
+    description: 'The path to the interfaces PIM can create.'
+)
\ No newline at end of file