Add meson build

This commit is to add meson build.
And later, we will remove Autotools and replace it with meson build.

In addition, fixed Layout::LedAction construct parameter error in test
file.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I58c9a2c9de928db288e77ca2d6aa807d36e70144
diff --git a/fault-monitor/fru-fault-monitor.cpp b/fault-monitor/fru-fault-monitor.cpp
index 7b03733..35b30ec 100644
--- a/fault-monitor/fru-fault-monitor.cpp
+++ b/fault-monitor/fru-fault-monitor.cpp
@@ -1,11 +1,11 @@
 #include "fru-fault-monitor.hpp"
 
 #include "elog-errors.hpp"
-#include "xyz/openbmc_project/Led/Fru/Monitor/error.hpp"
-#include "xyz/openbmc_project/Led/Mapper/error.hpp"
 
 #include <phosphor-logging/elog.hpp>
 #include <sdbusplus/exception.hpp>
+#include <xyz/openbmc_project/Led/Fru/Monitor/error.hpp>
+#include <xyz/openbmc_project/Led/Mapper/error.hpp>
 
 namespace phosphor
 {
diff --git a/fault-monitor/meson.build b/fault-monitor/meson.build
new file mode 100644
index 0000000..ef7dfd1
--- /dev/null
+++ b/fault-monitor/meson.build
@@ -0,0 +1,14 @@
+fault_monitor_sources = [
+    generated_sources,
+    'fru-fault-monitor.cpp',
+    'monitor-main.cpp',
+]
+
+executable(
+    'phosphor-fru-fault-monitor',
+    fault_monitor_sources,
+    include_directories: ['.', '../', '../gen'],
+    dependencies: deps,
+    install: true,
+    install_dir: get_option('bindir')
+)
diff --git a/gen/meson.build b/gen/meson.build
new file mode 100644
index 0000000..50bb831
--- /dev/null
+++ b/gen/meson.build
@@ -0,0 +1,14 @@
+# Generated file; do not modify.
+sdbuspp_gen_meson_ver = run_command(
+    sdbuspp_gen_meson_prog,
+    '--version',
+).stdout().strip().split('\n')[0]
+
+if sdbuspp_gen_meson_ver != 'sdbus++-gen-meson version 1'
+    warning('Generated meson files from wrong version of sdbus++-gen-meson.')
+    warning(
+        'Expected "sdbus++-gen-meson version 1", got:',
+        sdbuspp_gen_meson_ver
+    )
+endif
+
diff --git a/gen/xyz/meson.build b/gen/xyz/meson.build
new file mode 100644
index 0000000..e4991ad
--- /dev/null
+++ b/gen/xyz/meson.build
@@ -0,0 +1,2 @@
+# Generated file; do not modify.
+subdir('openbmc_project')
diff --git a/gen/xyz/openbmc_project/Led/Fru/Monitor/meson.build b/gen/xyz/openbmc_project/Led/Fru/Monitor/meson.build
new file mode 100644
index 0000000..5339b24
--- /dev/null
+++ b/gen/xyz/openbmc_project/Led/Fru/Monitor/meson.build
@@ -0,0 +1,14 @@
+# Generated file; do not modify.
+generated_sources += custom_target(
+    'xyz/openbmc_project/Led/Fru/Monitor__cpp'.underscorify(),
+    input: [ meson.source_root() / 'xyz/openbmc_project/Led/Fru/Monitor.errors.yaml',  ],
+    output: [ 'error.cpp', 'error.hpp',  ],
+    command: [
+        sdbuspp_gen_meson_prog, '--command', 'cpp',
+        '--output', meson.current_build_dir(),
+        '--tool', sdbusplusplus_prog,
+        '--directory', meson.source_root(),
+        'xyz/openbmc_project/Led/Fru/Monitor',
+    ],
+)
+
diff --git a/gen/xyz/openbmc_project/Led/Fru/meson.build b/gen/xyz/openbmc_project/Led/Fru/meson.build
new file mode 100644
index 0000000..f5310fb
--- /dev/null
+++ b/gen/xyz/openbmc_project/Led/Fru/meson.build
@@ -0,0 +1,16 @@
+# Generated file; do not modify.
+subdir('Monitor')
+generated_others += custom_target(
+    'xyz/openbmc_project/Led/Fru/Monitor__markdown'.underscorify(),
+    input: [ meson.source_root() / 'xyz/openbmc_project/Led/Fru/Monitor.errors.yaml',  ],
+    output: [ 'Monitor.md' ],
+    command: [
+        sdbuspp_gen_meson_prog, '--command', 'markdown',
+        '--output', meson.current_build_dir(),
+        '--tool', sdbusplusplus_prog,
+        '--directory', meson.source_root(),
+        'xyz/openbmc_project/Led/Fru/Monitor',
+    ],
+    build_by_default: true,
+)
+
diff --git a/gen/xyz/openbmc_project/Led/Mapper/meson.build b/gen/xyz/openbmc_project/Led/Mapper/meson.build
new file mode 100644
index 0000000..89f0354
--- /dev/null
+++ b/gen/xyz/openbmc_project/Led/Mapper/meson.build
@@ -0,0 +1,14 @@
+# Generated file; do not modify.
+generated_sources += custom_target(
+    'xyz/openbmc_project/Led/Mapper__cpp'.underscorify(),
+    input: [ meson.source_root() / 'xyz/openbmc_project/Led/Mapper.errors.yaml',  ],
+    output: [ 'error.cpp', 'error.hpp',  ],
+    command: [
+        sdbuspp_gen_meson_prog, '--command', 'cpp',
+        '--output', meson.current_build_dir(),
+        '--tool', sdbusplusplus_prog,
+        '--directory', meson.source_root(),
+        'xyz/openbmc_project/Led/Mapper',
+    ],
+)
+
diff --git a/gen/xyz/openbmc_project/Led/meson.build b/gen/xyz/openbmc_project/Led/meson.build
new file mode 100644
index 0000000..ce0db60
--- /dev/null
+++ b/gen/xyz/openbmc_project/Led/meson.build
@@ -0,0 +1,17 @@
+# Generated file; do not modify.
+subdir('Fru')
+subdir('Mapper')
+generated_others += custom_target(
+    'xyz/openbmc_project/Led/Mapper__markdown'.underscorify(),
+    input: [ meson.source_root() / 'xyz/openbmc_project/Led/Mapper.errors.yaml',  ],
+    output: [ 'Mapper.md' ],
+    command: [
+        sdbuspp_gen_meson_prog, '--command', 'markdown',
+        '--output', meson.current_build_dir(),
+        '--tool', sdbusplusplus_prog,
+        '--directory', meson.source_root(),
+        'xyz/openbmc_project/Led/Mapper',
+    ],
+    build_by_default: true,
+)
+
diff --git a/gen/xyz/openbmc_project/meson.build b/gen/xyz/openbmc_project/meson.build
new file mode 100644
index 0000000..597580b
--- /dev/null
+++ b/gen/xyz/openbmc_project/meson.build
@@ -0,0 +1,2 @@
+# Generated file; do not modify.
+subdir('Led')
diff --git a/json-config.hpp b/json-config.hpp
index 462a84e..d3a59a1 100644
--- a/json-config.hpp
+++ b/json-config.hpp
@@ -141,7 +141,7 @@
      *
      * @return
      */
-    const void getFilePath()
+    void getFilePath()
     {
         // Check override location
         confFile = fs::path{confOverridePath} / confFileName;
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..7f01052
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,160 @@
+project(
+    'phosphor-ledmanager', 'cpp',
+    version : '1.0.0',
+    meson_version: '>=0.54.1',
+    default_options: [
+        'warning_level=3',
+        'werror=true',
+        'cpp_std=c++17',
+        'buildtype=debugoptimized'
+    ]
+)
+
+conf_data = configuration_data()
+conf_data.set_quoted('BUSNAME', 'xyz.openbmc_project.LED.GroupManager')
+conf_data.set_quoted('OBJPATH', '/xyz/openbmc_project/led/groups')
+conf_data.set_quoted('LED_JSON_FILE', '/usr/share/phosphor-led-manager/led-group-config.json')
+conf_data.set_quoted('SAVED_GROUPS_FILE', '/var/lib/phosphor-led-manager/savedGroups')
+conf_data.set_quoted('CALLOUT_FWD_ASSOCIATION', 'callout')
+conf_data.set_quoted('CALLOUT_REV_ASSOCIATION', 'fault')
+conf_data.set_quoted('ELOG_ENTRY', 'entry')
+conf_data.set_quoted('LED_FAULT', 'fault')
+
+conf_data.set('CLASS_VERSION', 1)
+conf_data.set('LED_USE_JSON', get_option('use-json').enabled())
+conf_data.set('USE_LAMP_TEST', get_option('use-lamp-test').enabled())
+
+sdbusplus_dep = dependency('sdbusplus', required: false)
+if sdbusplus_dep.found()
+    sdbusplusplus_prog = find_program('sdbus++')
+    sdbuspp_gen_meson_prog = find_program('sdbus++-gen-meson')
+else
+    sdbusplus_proj = subproject('sdbusplus', required: true)
+    sdbusplus_dep = sdbusplus_proj.get_variable('sdbusplus_dep')
+    sdbusplusplus_prog = sdbusplus_proj.get_variable('sdbusplusplus_prog')
+    sdbuspp_gen_meson_prog = sdbusplus_proj.get_variable(
+        'sdbuspp_gen_meson_prog'
+    )
+endif
+
+sdeventplus = dependency('sdeventplus')
+phosphorlogging = dependency('phosphor-logging')
+phosphordbusinterfaces = dependency('phosphor-dbus-interfaces')
+gtest = dependency('gtest', main: true, disabler: true, required: true)
+gmock = dependency('gmock', disabler: true, required: true)
+prog_python = find_program('python3', required: true)
+realpath_prog = find_program('realpath')
+
+cpp = meson.get_compiler('cpp')
+if cpp.has_header('nlohmann/json.hpp')
+    nlohmann_json = declare_dependency()
+else
+    subproject('nlohmann', required: false)
+    nlohmann_json = declare_dependency(
+        include_directories: [
+            'subprojects/nlohmann/single_include',
+            'subprojects/nlohmann/single_include/nlohmann',
+        ]
+    )
+endif
+
+selected_subdirs = []
+selected_subdirs += 'xyz/openbmc_project'
+
+generated_root = meson.current_build_dir() / 'gen'
+generated_others = []
+generated_sources = []
+
+# Source the generated meson files.
+subdir('gen')
+foreach d : selected_subdirs
+  subdir('gen' / d)
+endforeach
+
+# Parse through the list from sdbus++-gendir and put into sets.
+generated_headers = []
+generated_cpp = []
+generated_others_files = []
+
+foreach g : generated_sources generated_others
+    foreach f : g.to_list()
+        rel_path = run_command(
+            realpath_prog,
+            '--relative-to', generated_root,
+            f.full_path(),
+        ).stdout().strip().split('\n')[-1]
+
+        if rel_path.endswith('.hpp')
+            generated_headers += rel_path
+        elif rel_path.endswith('.cpp')
+            generated_cpp += rel_path
+        else
+            generated_others_files += rel_path
+        endif
+    endforeach
+endforeach
+
+deps = [
+    sdbusplus_dep,
+    sdeventplus,
+    phosphorlogging,
+    phosphordbusinterfaces,
+    nlohmann_json
+]
+
+sources = [
+    'group.cpp',
+    'led-main.cpp',
+    'manager.cpp',
+    'serialize.cpp',
+    'utils.cpp',
+]
+
+if get_option('use-json').disabled()
+    led_gen_hpp = custom_target(
+        'led-gen.hpp',
+        command : [
+            prog_python,
+            meson.source_root() + '/parse_led.py',
+            '-i', meson.source_root(),
+            '-o', meson.current_build_dir(),
+        ],
+        output : 'led-gen.hpp')
+    sources += [led_gen_hpp]
+endif
+
+if get_option('use-lamp-test').enabled()
+    conf_data.set_quoted('LAMP_TEST_OBJECT', '/xyz/openbmc_project/led/groups/lamp_test')
+    conf_data.set_quoted('HOST_LAMP_TEST_OBJECT', '/xyz/openbmc_project/led/groups/host_lamp_test')
+    conf_data.set_quoted('LAMP_TEST_LED_OVERRIDES_JSON', '/usr/share/phosphor-led-manager/lamp-test-led-overrides.json')
+    conf_data.set('LAMP_TEST_TIMEOUT_IN_SECS', 240)
+
+    sources += ['lamptest.cpp']
+endif
+
+configure_file(output: 'config.h',
+    configuration: conf_data
+)
+
+install_data(
+    'scripts/led-set-all-groups-asserted.sh',
+    install_dir: get_option('bindir')
+)
+
+executable(
+    'phosphor-ledmanager',
+    sources,
+    generated_sources,
+    include_directories: include_directories('gen'),
+    dependencies: sdbusplus_dep,
+    implicit_include_directories: true,
+    dependencies: deps,
+    install: true,
+    install_dir: get_option('bindir')
+)
+subdir('fault-monitor')
+
+build_tests = get_option('tests')
+if not build_tests.disabled()
+  subdir('test')
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..0ae13a5
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,3 @@
+option('tests', type : 'feature', description : 'Build tests', value: 'enabled')
+option('use-json', type : 'feature', description : 'LEDs JSON filepath', value: 'disabled')
+option('use-lamp-test', type : 'feature', description : 'LEDs lamp test configuration', value: 'disabled')
\ No newline at end of file
diff --git a/serialize.cpp b/serialize.cpp
index cd48a8c..c8f4e66 100644
--- a/serialize.cpp
+++ b/serialize.cpp
@@ -11,7 +11,7 @@
 #include <fstream>
 
 // Register class version with Cereal
-CEREAL_CLASS_VERSION(phosphor::led::Serialize, CLASS_VERSION);
+CEREAL_CLASS_VERSION(phosphor::led::Serialize, CLASS_VERSION)
 
 namespace phosphor
 {
diff --git a/subprojects/nlohmann.wrap b/subprojects/nlohmann.wrap
new file mode 100644
index 0000000..a77b7c9
--- /dev/null
+++ b/subprojects/nlohmann.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+revision = b3e5cb7f20dcc5c806e418df34324eca60d17d4e
+url = https://github.com/nlohmann/json.git
diff --git a/subprojects/sdbusplus.wrap b/subprojects/sdbusplus.wrap
new file mode 100644
index 0000000..d470130
--- /dev/null
+++ b/subprojects/sdbusplus.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/sdbusplus.git
+revision = HEAD
diff --git a/test/led-test-map.hpp b/test/led-test-map.hpp
index f76d00e..983fad5 100644
--- a/test/led-test-map.hpp
+++ b/test/led-test-map.hpp
@@ -63,13 +63,13 @@
          {
              {"One", phosphor::led::Layout::Blink, 0, 0,
               phosphor::led::Layout::Blink},
-             {"Two", phosphor::led::Layout::On, 0,
+             {"Two", phosphor::led::Layout::On, 0, 0,
               phosphor::led::Layout::Blink},
-             {"Three", phosphor::led::Layout::Blink, 0,
+             {"Three", phosphor::led::Layout::Blink, 0, 0,
               phosphor::led::Layout::On},
-             {"Four", phosphor::led::Layout::On, 0,
+             {"Four", phosphor::led::Layout::On, 0, 0,
               phosphor::led::Layout::Blink},
-             {"Five", phosphor::led::Layout::On, 0,
+             {"Five", phosphor::led::Layout::On, 0, 0,
               phosphor::led::Layout::Blink},
          }},
 };
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..feb6578
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,26 @@
+test_sources = [
+  '../manager.cpp',
+  '../serialize.cpp',
+  '../utils.cpp'
+]
+
+tests = [
+  'utest.cpp',
+  'utest-serialize.cpp',
+]
+
+if get_option('use-json').enabled()
+  tests += ['utest-led-json.cpp']
+endif
+
+foreach t : tests
+  test(t, executable(t.underscorify(), t,
+                     test_sources,
+                     include_directories: ['..'],
+                     dependencies: [
+                         gtest,
+                         gmock,
+                         deps
+                         ]),
+       workdir: meson.current_source_dir())
+endforeach
\ No newline at end of file
diff --git a/test/utest.cpp b/test/utest.cpp
index 787b345..26e13ec 100644
--- a/test/utest.cpp
+++ b/test/utest.cpp
@@ -354,12 +354,13 @@
         std::set<Layout::LedAction> refAssert = {
             {"One", phosphor::led::Layout::Blink, 0, 0,
              phosphor::led::Layout::Blink},
-            {"Two", phosphor::led::Layout::On, 0, phosphor::led::Layout::Blink},
-            {"Three", phosphor::led::Layout::Blink, 0,
-             phosphor::led::Layout::On},
-            {"Four", phosphor::led::Layout::On, 0,
+            {"Two", phosphor::led::Layout::On, 0, 0,
              phosphor::led::Layout::Blink},
-            {"Five", phosphor::led::Layout::On, 0,
+            {"Three", phosphor::led::Layout::Blink, 0, 0,
+             phosphor::led::Layout::On},
+            {"Four", phosphor::led::Layout::On, 0, 0,
+             phosphor::led::Layout::Blink},
+            {"Five", phosphor::led::Layout::On, 0, 0,
              phosphor::led::Layout::Blink},
         };
         EXPECT_EQ(refAssert.size(), ledsAssert.size());