Migrate to Meson build

This commit focuses in enabling the meson build for the
phosphor-snmp repo.

To build and install using meson:
  meson build
  ninja -C build
  ninja -C build install

Tested By:
  meson -Dtests=enabled build
  ninja -C build test

Signed-off-by: Ratan Gupta <ratankgupta31@gmail.com>
Change-Id: I3a79a42d2fed3f39ae218f3e3f81fb165a12ea17
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..7ebdc4d
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,175 @@
+project('phosphor-user-manager',
+        'cpp',
+        version: '0.1', meson_version: '>=0.57.0',
+        default_options: [
+          'warning_level=3',
+          'werror=true',
+          'cpp_std=c++20',
+          'buildtype=debugoptimized',
+        ]
+)
+
+conf_data = configuration_data()
+
+conf_data.set_quoted('USER_MANAGER_BUSNAME', 'xyz.openbmc_project.User.Manager',
+                      description : 'The DBus busname to own.')
+
+conf_data.set_quoted('LDAP_MAPPER_MANAGER_BUSNAME', 'xyz.openbmc_project.LDAP.PrivilegeMapper',
+                      description : 'The Dbus busname LDAP privilege mapper application.')
+
+conf_data.set_quoted('LDAP_MAPPER_PERSIST_PATH', '/var/lib/phosphor-ldap-mapper/groups',
+                      description : 'Path of directory containing LDAP groups privilege mapping.')
+
+conf_data.set_quoted('DEFAULT_CRYPT_ALGO', '1',
+                      description : 'The default crypt algorithm if one not found in shadow.')
+
+conf_data.set('CLASS_VERSION', 1,
+                      description : 'Class version to register with Cereal.')
+
+conf_data.set_quoted('LDAP_CONFIG_FILE', '/etc/nslcd.conf',
+                      description : 'Path of LDAP configuration file.')
+
+conf_data.set_quoted('TLS_CACERT_PATH', '/etc/ssl/certs/authority',
+                      description : 'Path of LDAP server CA certificate.')
+
+conf_data.set_quoted('TLS_CERT_FILE', '/etc/nslcd/certs/cert.pem',
+                      description : 'Path of LDAP client certificate.')
+
+conf_data.set_quoted('LDAP_CONFIG_ROOT', '/xyz/openbmc_project/user/ldap',
+                      description : 'LDAP configuration root.')
+
+conf_data.set_quoted('LDAP_CONFIG_DBUS_OBJ_PATH', '/xyz/openbmc_project/user/ldap/config',
+                      description : 'D-Bus path of LDAP config object.')
+
+conf_data.set_quoted('LDAP_CONFIG_BUSNAME', 'xyz.openbmc_project.Ldap.Config',
+                      description : 'D-Bus busname of LDAP config service.')
+
+conf_data.set_quoted('LDAP_CONF_PERSIST_PATH', '/var/lib/phosphor-ldap-conf',
+                      description : 'path of directory having persisted LDAP configuration enabled property.')
+
+conf_data.set_quoted('SYSTEMD_BUSNAME', 'org.freedesktop.systemd1',
+                      description : 'systemd busname.')
+
+conf_data.set_quoted('SYSTEMD_PATH', '/org/freedesktop/systemd1',
+                      decsription :  'systemd path')
+
+conf_data.set_quoted('SYSTEMD_INTERFACE', 'org.freedesktop.systemd1.Manager',
+                      description : 'systemd interface.')
+
+conf_header = configure_file(output: 'config.h',
+    configuration: conf_data)
+
+phosphor_dbus_interfaces_dep = dependency(
+  'phosphor-dbus-interfaces',
+  fallback: ['phosphor-dbus-interfaces', 'phosphor_dbus_interfaces_dep'],
+)
+
+sdbusplus_dep = dependency(
+  'sdbusplus',
+  fallback: ['sdbusplus', 'sdbusplus_dep'],
+)
+
+phosphor_logging_dep = dependency(
+  'phosphor-logging',
+   fallback: ['phosphor-logging', 'phosphor_logging_dep'],
+)
+
+systemd_dep = dependency('systemd')
+
+cpp = meson.get_compiler('cpp')
+
+user_manager_src = [
+    'mainapp.cpp',
+    'user_mgr.cpp',
+    'users.cpp'
+]
+
+user_manager_deps = [
+     sdbusplus_dep,
+     phosphor_logging_dep,
+     phosphor_dbus_interfaces_dep
+]
+
+user_manager_lib = static_library(
+    'phosphor-user-manager',
+    [
+        'user_mgr.cpp',
+        'users.cpp',
+    ],
+    dependencies: user_manager_deps,
+)
+
+user_manager_dep = declare_dependency(
+    link_with: user_manager_lib,
+    dependencies: user_manager_deps
+)
+
+executable(
+    'phosphor-user-manager',
+    'mainapp.cpp',
+    dependencies: user_manager_dep,
+    link_args: ['-lcrypt', '-lstdc++fs'],
+    cpp_args: ['-DBOOST_ALL_NO_LIB', '-DBOOST_SYSTEM_NO_DEPRECATED', '-DBOOST_ERROR_CODE_HEADER_ONLY'],
+    install: true,
+)
+
+
+systemd_system_unit_dir = systemd_dep.get_variable(
+    pkgconfig: 'systemdsystemunitdir'
+)
+
+busconfig_dir = get_option('datadir') / 'dbus-1' / 'system.d'
+
+cert_manager_dir = get_option('datadir') / 'phosphor-certificate-manager'
+
+certs = []
+
+busconfig = []
+
+systemd_alias = []
+
+certs += 'nslcd'
+
+busconfig += 'phosphor-nslcd-cert-config.conf'
+
+systemd_alias += [[
+        '../phosphor-certificate-manager@.service',
+        'multi-user.target.wants/phosphor-certificate-manager@nslcd.service'
+]]
+
+
+install_data(
+    busconfig,
+    install_dir: busconfig_dir,
+)
+
+install_data(
+    certs,
+    install_dir: cert_manager_dir,
+)
+
+foreach service: systemd_alias
+    # Meson 0.61 will support this:
+    #install_symlink(
+    #      service,
+    #      install_dir: systemd_system_unit_dir,
+    #      pointing_to: link,
+    #  )
+    meson.add_install_script(
+        'sh', '-c',
+        'mkdir -p $(dirname $DESTDIR/@0@/@1@)'.format(systemd_system_unit_dir,
+            service[1]),
+    )
+    meson.add_install_script(
+        'sh', '-c',
+        'ln -s @0@ $DESTDIR/@1@/@2@'.format(service[0], systemd_system_unit_dir,
+            service[1]),
+    )
+endforeach
+
+subdir('phosphor-ldap-mapper')
+subdir('phosphor-ldap-config')
+
+if get_option('tests').enabled()
+  subdir('test')
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..cdf492c
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1 @@
+option('tests', type: 'feature', description: 'Build tests', value: 'enabled')
diff --git a/phosphor-ldap-config/meson.build b/phosphor-ldap-config/meson.build
new file mode 100644
index 0000000..4331483
--- /dev/null
+++ b/phosphor-ldap-config/meson.build
@@ -0,0 +1,32 @@
+phosphor_ldap_conf_deps = [
+    phosphor_dbus_interfaces_dep,
+    phosphor_logging_dep,
+    sdbusplus_dep,
+]
+
+phosphor_ldap_conf_lib = static_library(
+    'phosphor_ldap_conf',
+    [
+        'utils.cpp',
+        'ldap_config.cpp',
+        'ldap_config_mgr.cpp',
+        'ldap_mapper_entry.cpp',
+        'ldap_mapper_serialize.cpp'
+    ],
+    include_directories: '..',
+    dependencies: phosphor_ldap_conf_deps,
+)
+
+phosphor_ldap_conf_dep = declare_dependency(
+    link_with: phosphor_ldap_conf_lib,
+    dependencies: phosphor_ldap_conf_deps,
+)
+
+executable(
+    'phosphor-ldap-conf',
+    'main.cpp',
+    include_directories: '..',
+    dependencies: phosphor_ldap_conf_dep,
+    link_args: ['-lldap'],
+    install: true,
+)
diff --git a/phosphor-ldap-mapper/meson.build b/phosphor-ldap-mapper/meson.build
new file mode 100644
index 0000000..d2f4c50
--- /dev/null
+++ b/phosphor-ldap-mapper/meson.build
@@ -0,0 +1,30 @@
+phosphor_ldap_mapper_deps = [
+    phosphor_dbus_interfaces_dep,
+    phosphor_logging_dep,
+    sdbusplus_dep,
+]
+
+phosphor_ldap_mapper_lib = static_library(
+    'phosphor_ldap_mapper',
+    [
+        'ldap_mapper_mgr.cpp',
+        'ldap_mapper_entry.cpp',
+        'ldap_mapper_serialize.cpp'
+    ],
+    include_directories: '..',
+    dependencies: phosphor_ldap_mapper_deps,
+)
+
+phosphor_ldap_mapper_dep = declare_dependency(
+    link_with: phosphor_ldap_mapper_lib,
+    dependencies: phosphor_ldap_mapper_deps,
+)
+
+executable(
+    'phosphor-ldap-mapper',
+    'main.cpp',
+    include_directories: '..',
+    dependencies: phosphor_ldap_mapper_dep,
+    install: true,
+)
+
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..4dfad2e
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,64 @@
+gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
+gmock_dep = dependency('gmock', disabler: true, required: false)
+if not gtest_dep.found() or not gmock_dep.found()
+    gtest_proj = import('cmake').subproject('googletest', required: false)
+    if gtest_proj.found()
+        gtest_dep = declare_dependency(
+            dependencies: [
+                dependency('threads'),
+                gtest_proj.dependency('gtest'),
+                gtest_proj.dependency('gtest_main'),
+            ]
+        )
+        gmock_dep = gtest_proj.dependency('gmock')
+    else
+        assert(
+            not get_option('tests').enabled(),
+            'Googletest is required if tests are enabled'
+        )
+    endif
+endif
+
+test(
+    'ldap_config_test',
+    executable(
+        'ldap_config_test',
+        ['ldap_config_test.cpp',
+         'utils_test.cpp'],
+        include_directories: '..',
+        dependencies: [
+            gtest_dep,
+            gmock_dep,
+            phosphor_ldap_conf_dep,
+        ],
+        link_args: ['-lldap'],
+    ),
+)
+
+test(
+    'ldap_mapper_test',
+    executable(
+        'ldap_mapper_test',
+        'ldap_mapper_test.cpp',
+        include_directories: '..',
+        dependencies: [
+            gtest_dep,
+            gmock_dep,
+            phosphor_ldap_mapper_dep,
+        ],
+    ),
+)
+
+test(
+    'user_mgr_test',
+    executable(
+        'user_mgr_test',
+        'user_mgr_test.cpp',
+        include_directories: '..',
+        dependencies: [
+            gtest_dep,
+            gmock_dep,
+            user_manager_dep,
+        ],
+    ),
+)