meson: add support for debug

Automatically enable the debugging code when doing debug build types,
and enable that by default, so the code is built by default.

Change-Id: I17b1dbb79ba7ca85d9be65d1c6f0004abdcd88d6
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/meson.build b/meson.build
index 0ebde38..0510bad 100644
--- a/meson.build
+++ b/meson.build
@@ -2,6 +2,7 @@
     'phosphor-objmgr',
     'c', 'cpp',
     default_options: [
+        'buildtype=debugoptimized',
         'cpp_std=c++20',
         'warning_level=3',
         'werror=true',
@@ -15,6 +16,11 @@
 phosphor_dbus_interfaces = dependency('phosphor-dbus-interfaces')
 sdbusplus = dependency('sdbusplus')
 
+
+if get_option('buildtype').startswith('debug')
+    add_project_arguments('-DMAPPER_ENABLE_DEBUG', language : 'cpp')
+endif
+
 if get_option('tests').enabled()
     gtest = dependency('gtest', main: true, disabler: true, required: false)
     gmock = dependency('gmock', disabler: true, required: false)
diff --git a/src/main.cpp b/src/main.cpp
index 65de2ad..81bba2b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -71,7 +71,7 @@
     InProgressIntrospect(
         sdbusplus::asio::connection* systemBus, boost::asio::io_context& io,
         const std::string& processName, AssociationMaps& am
-#ifdef DEBUG
+#ifdef MAPPER_ENABLE_DEBUG
         ,
         std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>>
             globalStartTime
@@ -79,7 +79,7 @@
         ) :
         systemBus(systemBus),
         io(io), processName(processName), assocMaps(am)
-#ifdef DEBUG
+#ifdef MAPPER_ENABLE_DEBUG
         ,
         globalStartTime(std::move(globalStartTime)),
         processStartTime(std::chrono::steady_clock::now())
@@ -90,7 +90,7 @@
         try
         {
             sendIntrospectionCompleteSignal(systemBus, processName);
-#ifdef DEBUG
+#ifdef MAPPER_ENABLE_DEBUG
             std::chrono::duration<float> diff =
                 std::chrono::steady_clock::now() - processStartTime;
             std::cout << std::setw(50) << processName << " scan took "
@@ -124,7 +124,7 @@
     boost::asio::io_context& io;
     std::string processName;
     AssociationMaps& assocMaps;
-#ifdef DEBUG
+#ifdef MAPPER_ENABLE_DEBUG
     std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>>
         globalStartTime;
     std::chrono::time_point<std::chrono::steady_clock> processStartTime;
@@ -258,7 +258,7 @@
     sdbusplus::asio::connection* systemBus, boost::asio::io_context& io,
     InterfaceMapType& interfaceMap, const std::string& processName,
     AssociationMaps& assocMaps,
-#ifdef DEBUG
+#ifdef MAPPER_ENABLE_DEBUG
     std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>>
         globalStartTime,
 #endif
@@ -269,7 +269,7 @@
         std::shared_ptr<InProgressIntrospect> transaction =
             std::make_shared<InProgressIntrospect>(systemBus, io, processName,
                                                    assocMaps
-#ifdef DEBUG
+#ifdef MAPPER_ENABLE_DEBUG
                                                    ,
                                                    globalStartTime
 #endif
@@ -318,7 +318,7 @@
             }
             // Try to make startup consistent
             std::sort(processNames.begin(), processNames.end());
-#ifdef DEBUG
+#ifdef MAPPER_ENABLE_DEBUG
             std::shared_ptr<std::chrono::time_point<std::chrono::steady_clock>>
                 globalStartTime = std::make_shared<
                     std::chrono::time_point<std::chrono::steady_clock>>(
@@ -331,7 +331,7 @@
                 {
                     startNewIntrospect(systemBus, io, interfaceMap, processName,
                                        assocMaps,
-#ifdef DEBUG
+#ifdef MAPPER_ENABLE_DEBUG
                                        globalStartTime,
 #endif
                                        objectServer);
@@ -692,7 +692,7 @@
 
             if (!newOwner.empty())
             {
-#ifdef DEBUG
+#ifdef MAPPER_ENABLE_DEBUG
                 auto transaction = std::make_shared<
                     std::chrono::time_point<std::chrono::steady_clock>>(
                     std::chrono::steady_clock::now());
@@ -703,7 +703,7 @@
                     nameOwners[newOwner] = name;
                     startNewIntrospect(systemBus.get(), io, interfaceMap, name,
                                        associationMaps,
-#ifdef DEBUG
+#ifdef MAPPER_ENABLE_DEBUG
                                        transaction,
 #endif
                                        server);