Add support for building with meson

Follow the OpenBMC herd and support a modern, comprehensible build framework.

To build with meson:
   meson build
   ninja -C build

The OpenBMC CI scripts look for meson.build before looking for CMakelists so
approval of this patch would change the build system during CI to meson.

Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
Change-Id: I23d023d8db8048579926231841f497366ab3d516
diff --git a/inc/srvcfg_manager.hpp b/inc/srvcfg_manager.hpp
index cd453b0..adfa89a 100644
--- a/inc/srvcfg_manager.hpp
+++ b/inc/srvcfg_manager.hpp
@@ -70,11 +70,11 @@
     std::shared_ptr<sdbusplus::asio::dbus_interface> iface;

     bool internalSet = false;

     std::string objPath;

-    std::string instanceName;

     std::string baseUnitName;

+    std::string instanceName;

     std::string instantiatedUnitName;

-    std::string socketObjectPath;

     std::string serviceObjectPath;

+    std::string socketObjectPath;

     std::string overrideConfDir;

 

     // Properties

diff --git a/inc/utils.hpp b/inc/utils.hpp
index 9a1ff02..e4a31bb 100644
--- a/inc/utils.hpp
+++ b/inc/utils.hpp
@@ -21,7 +21,7 @@
 

 #include <chrono>

 #include <ctime>

-#include <experimental/filesystem>

+#include <filesystem>

 #include <string>

 

 static constexpr const char* sysdStartUnit = "StartUnit";

diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..696bc87
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,57 @@
+project(
+    'phosphor-srvcfg-manager',
+    'cpp',
+    default_options: [
+        'warning_level=3',
+        'werror=true',
+        'cpp_std=c++17'
+    ],
+    license: 'Apache-2.0',
+    version: '1.0',
+)
+
+# Wno-psabi reduces the number of "Note:" messages when cross-compiling some STL
+# stuff for ARM. See https://stackoverflow.com/questions/48149323/strange-gcc-warning-when-compiling-qt-project
+# Basically, gcc 6 and gcc 7 are not ABI compatible, but since the whole OpenBMC
+# project uses the same compiler, we can safely ignmore these info notes.
+add_project_arguments('-Wno-psabi', language: 'cpp')
+
+boost_args = ['-DBOOST_ALL_NO_LIB',
+              '-DBOOST_ASIO_DISABLE_THREADS',
+              '-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
+              '-DBOOST_ERROR_CODE_HEADER_ONLY',
+              '-DBOOST_NO_RTTI',
+              '-DBOOST_NO_TYPEID',
+              '-DBOOST_SYSTEM_NO_DEPRECATED']
+
+deps = [dependency('boost'),
+        dependency('boost', modules : ['coroutine']),
+        dependency('phosphor-dbus-interfaces'),
+        dependency('phosphor-logging'),
+        dependency('sdbusplus'),
+        dependency('systemd'),
+]
+
+executable('phosphor-srvcfg-manager',
+           'src/main.cpp',
+           'src/srvcfg_manager.cpp',
+           'src/utils.cpp',
+        implicit_include_directories: false,
+        include_directories: ['inc'],
+        dependencies: deps,
+        cpp_args : boost_args,
+        install: true,
+        install_dir: get_option('bindir'))
+
+systemd = dependency('systemd')
+systemd_system_unit_dir = systemd.get_pkgconfig_variable(
+    'systemdsystemunitdir',
+    define_variable: ['prefix', get_option('prefix')])
+
+configure_file(
+    copy: true,
+    input: 'srvcfg-manager.service',
+    install: true,
+    install_dir: systemd_system_unit_dir,
+    output: 'srvcfg-manager.service'
+)
diff --git a/src/main.cpp b/src/main.cpp
index c0564e5..e57c767 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -118,7 +118,7 @@
 static inline void

     handleListUnitsResponse(sdbusplus::asio::object_server& server,

                             std::shared_ptr<sdbusplus::asio::connection>& conn,

-                            boost::system::error_code ec,

+                            boost::system::error_code /*ec*/,

                             const std::vector<ListUnitsType>& listUnits)

 {

     // Loop through all units, and mark all units, which has to be

@@ -316,7 +316,7 @@
         "type='signal',"

         "member='StartupFinished',path='/org/freedesktop/systemd1',"

         "interface='org.freedesktop.systemd1.Manager'",

-        [&server, &conn](sdbusplus::message::message& msg) {

+        [&server, &conn](sdbusplus::message::message& /*msg*/) {

             if (!unitQueryStarted)

             {

                 unitQueryStarted = true;

diff --git a/src/srvcfg_manager.cpp b/src/srvcfg_manager.cpp
index 1818bd7..0a6fcd9 100644
--- a/src/srvcfg_manager.cpp
+++ b/src/srvcfg_manager.cpp
@@ -184,14 +184,12 @@
     {

         std::string socketUnitName(instantiatedUnitName + ".socket");

         /// Check override socket directory exist, if not create it.

-        std::experimental::filesystem::path ovrUnitFileDir(

-            systemdOverrideUnitBasePath);

+        std::filesystem::path ovrUnitFileDir(systemdOverrideUnitBasePath);

         ovrUnitFileDir += socketUnitName;

         ovrUnitFileDir += ".d";

-        if (!std::experimental::filesystem::exists(ovrUnitFileDir))

+        if (!std::filesystem::exists(ovrUnitFileDir))

         {

-            if (!std::experimental::filesystem::create_directories(

-                    ovrUnitFileDir))

+            if (!std::filesystem::create_directories(ovrUnitFileDir))

             {

                 phosphor::logging::log<phosphor::logging::level::ERR>(

                     "Unable to create the directory.",

@@ -210,8 +208,8 @@
     const std::string& objPath_, const std::string& baseUnitName_,

     const std::string& instanceName_, const std::string& serviceObjPath_,

     const std::string& socketObjPath_) :

-    server(srv_),

-    conn(conn_), objPath(objPath_), baseUnitName(baseUnitName_),

+    conn(conn_),

+    server(srv_), objPath(objPath_), baseUnitName(baseUnitName_),

     instanceName(instanceName_), serviceObjectPath(serviceObjPath_),

     socketObjectPath(socketObjPath_)

 {