libpldmresponder: Make libpldmresponder optional

libpldmresponder library is for handling incoming PLDM request messages
on BMC. There are usecases for PLDM daemon on BMC where it is primarily
a requester and BMC aggregates information about firmware devices that
implement MCTP/PLDM and facilitate firmware upgrade of the devices.
This patch is a step in that direction to enable PLDM daemon on BMC
primarily as PLDM requester.

Tested: Ran PLDM daemon successfully without libpldmresponder library.

Signed-off-by: Tom Joseph <rushtotom@gmail.com>
Change-Id: Iceaa10127352aaaba6c338d7ea9ac187be4e5fad
diff --git a/libpldmresponder/meson.build b/libpldmresponder/meson.build
index 8436e14..bb45c3b 100644
--- a/libpldmresponder/meson.build
+++ b/libpldmresponder/meson.build
@@ -23,6 +23,7 @@
   'fru.cpp',
   '../host-bmc/host_pdr_handler.cpp',
   '../host-bmc/dbus_to_event_handler.cpp',
+  '../host-bmc/dbus_to_host_effecters.cpp',
   'event_parser.cpp'
 ]
 
diff --git a/meson.build b/meson.build
index 22b1938..b321d34 100644
--- a/meson.build
+++ b/meson.build
@@ -22,13 +22,14 @@
 endif
 
 conf_data = configuration_data()
+if get_option('libpldmresponder').enabled()
 conf_data.set_quoted('BIOS_JSONS_DIR', '/usr/share/pldm/bios')
 conf_data.set_quoted('BIOS_TABLES_DIR', '/var/lib/pldm/bios')
 conf_data.set_quoted('PDR_JSONS_DIR', '/usr/share/pldm/pdr')
 conf_data.set_quoted('FRU_JSONS_DIR', '/usr/share/pldm/fru')
 conf_data.set_quoted('HOST_JSONS_DIR', '/usr/share/pldm/host')
 conf_data.set_quoted('EVENTS_JSONS_DIR', '/usr/share/pldm/events')
-conf_data.set('PLDM_VERBOSITY',get_option('verbosity'))
+endif
 if get_option('softoff').enabled()
   conf_data.set('SOFTOFF_TIMEOUT_SECONDS', get_option('softoff-timeout-seconds'))
 endif
@@ -44,6 +45,7 @@
   add_project_arguments('-DOEM_IBM', language : 'c')
   add_project_arguments('-DOEM_IBM', language : 'cpp')
 endif
+conf_data.set('PLDM_VERBOSITY',get_option('verbosity'))
 configure_file(output: 'config.h',
   configuration: conf_data
 )
@@ -144,26 +146,29 @@
 libpldmutils = declare_dependency(
   include_directories: include_directories(libpldmutils_headers),
   link_with: libpldmutils)
-subdir('libpldmresponder')
 
 deps = [
   libpldm_dep,
   libpldmutils,
-  libpldmresponder,
-  libpldmutils,
   nlohmann_json,
   sdbusplus,
   sdeventplus,
-  phosphor_dbus_interfaces
+  phosphor_dbus_interfaces,
 ]
 
+if get_option('libpldmresponder').enabled()
+subdir('libpldmresponder')
+deps += [
+  libpldmresponder
+]
+endif
+
 executable(
   'pldmd',
   'pldmd/pldmd.cpp',
   'pldmd/dbus_impl_requester.cpp',
   'pldmd/instance_id.cpp',
   'pldmd/dbus_impl_pdr.cpp',
-  'host-bmc/dbus_to_host_effecters.cpp',
   implicit_include_directories: false,
   dependencies: deps,
   install: true,
diff --git a/meson_options.txt b/meson_options.txt
index e1f6d43..4b1d833 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -4,6 +4,7 @@
 option('oem-ibm', type: 'feature', description: 'Enable IBM OEM PLDM')
 option('requester-api', type: 'feature', description: 'Enable libpldm requester API', value: 'enabled')
 option('utilities', type: 'feature', description: 'Enable debug utilities', value: 'enabled')
+option('libpldmresponder', type: 'feature', description: 'Enable libpldmresponder', value: 'enabled')
 
 option('libpldm-only', type: 'feature', description: 'Only build libpldm', value: 'disabled')
 option('oem-ibm-dma-maxsize', type: 'integer', min:4096, max: 16773120, description: 'OEM-IBM: max DMA size', value: 8384512) #16MB - 4K
diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index ceeff08..bfd3d71 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -4,18 +4,8 @@
 #include "libpldm/platform.h"
 
 #include "common/utils.hpp"
-#include "dbus_impl_pdr.hpp"
 #include "dbus_impl_requester.hpp"
-#include "host-bmc/dbus_to_event_handler.hpp"
-#include "host-bmc/dbus_to_host_effecters.hpp"
-#include "host-bmc/host_pdr_handler.hpp"
 #include "invoker.hpp"
-#include "libpldmresponder/base.hpp"
-#include "libpldmresponder/bios.hpp"
-#include "libpldmresponder/fru.hpp"
-#include "libpldmresponder/oem_handler.hpp"
-#include "libpldmresponder/platform.hpp"
-#include "xyz/openbmc_project/PLDM/Event/server.hpp"
 
 #include <err.h>
 #include <getopt.h>
@@ -41,6 +31,19 @@
 #include <string>
 #include <vector>
 
+#ifdef LIBPLDMRESPONDER
+#include "dbus_impl_pdr.hpp"
+#include "host-bmc/dbus_to_event_handler.hpp"
+#include "host-bmc/dbus_to_host_effecters.hpp"
+#include "host-bmc/host_pdr_handler.hpp"
+#include "libpldmresponder/base.hpp"
+#include "libpldmresponder/bios.hpp"
+#include "libpldmresponder/fru.hpp"
+#include "libpldmresponder/oem_handler.hpp"
+#include "libpldmresponder/platform.hpp"
+#include "xyz/openbmc_project/PLDM/Event/server.hpp"
+#endif
+
 #ifdef OEM_IBM
 #include "libpldmresponder/file_io.hpp"
 #include "libpldmresponder/oem_ibm_handler.hpp"
@@ -48,11 +51,11 @@
 
 constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1;
 
-using namespace pldm::responder;
 using namespace pldm;
 using namespace sdeventplus;
 using namespace sdeventplus::source;
-using namespace pldm::state_sensor;
+using namespace pldm::responder;
+using namespace pldm::utils;
 
 static Response processRxMsg(const std::vector<uint8_t>& requestMsg,
                              Invoker& invoker, dbus_api::Requester& requester)
@@ -152,14 +155,18 @@
     }
 
     auto event = Event::get_default();
+    auto& bus = pldm::utils::DBusHandler::getBus();
+    dbus_api::Requester dbusImplReq(bus, "/xyz/openbmc_project/pldm");
+    Invoker invoker{};
+
+#ifdef LIBPLDMRESPONDER
+    using namespace pldm::state_sensor;
     std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> pdrRepo(
         pldm_pdr_init(), pldm_pdr_destroy);
     std::unique_ptr<pldm_entity_association_tree,
                     decltype(&pldm_entity_association_tree_destroy)>
         entityTree(pldm_entity_association_tree_init(),
                    pldm_entity_association_tree_destroy);
-    auto& bus = pldm::utils::DBusHandler::getBus();
-    dbus_api::Requester dbusImplReq(bus, "/xyz/openbmc_project/pldm");
     std::unique_ptr<HostPDRHandler> hostPDRHandler;
     std::unique_ptr<pldm::host_effecters::HostEffecterParser>
         hostEffecterParser;
@@ -178,8 +185,6 @@
         dbusToPLDMEventHandler =
             std::make_unique<DbusToPLDMEvent>(sockfd, hostEID, dbusImplReq);
     }
-
-    Invoker invoker{};
     std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
 
 #ifdef OEM_IBM
@@ -215,6 +220,10 @@
 
     invoker.registerHandler(PLDM_PLATFORM, std::move(platformHandler));
     invoker.registerHandler(PLDM_FRU, std::move(fruHandler));
+    dbus_api::Pdr dbusImplPdr(bus, "/xyz/openbmc_project/pldm", pdrRepo.get());
+    sdbusplus::xyz::openbmc_project::PLDM::server::Event dbusImplEvent(
+        bus, "/xyz/openbmc_project/pldm");
+#endif
 
     pldm::utils::CustomFD socketFd(sockfd);
 
@@ -242,9 +251,6 @@
         exit(EXIT_FAILURE);
     }
 
-    dbus_api::Pdr dbusImplPdr(bus, "/xyz/openbmc_project/pldm", pdrRepo.get());
-    sdbusplus::xyz::openbmc_project::PLDM::server::Event dbusImplEvent(
-        bus, "/xyz/openbmc_project/pldm");
     auto callback = [verbose, &invoker, &dbusImplReq](IO& io, int fd,
                                                       uint32_t revents) {
         if (!(revents & EPOLLIN))