build: meson support for libphosphor-logging

Create just enough meson directives to create the equivalent
of libphosphor-logging, so that this repository can be picked
up as a meson subproject.  Remainder of the conversion to meson
will be in follow-on commits.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ifbcc58b118352d8f0338221c4cb7e472c2be7a43
diff --git a/.gitignore b/.gitignore
index 10293c4..628fd48 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,7 @@
+build*/
+subprojects/*
+!subprojects/*.wrap
+
 Makefile
 Makefile.in
 aclocal.m4
diff --git a/config.h.meson b/config.h.meson
new file mode 100644
index 0000000..0e71553
--- /dev/null
+++ b/config.h.meson
@@ -0,0 +1,11 @@
+#pragma once
+
+// @TODO(stwcx): These values are currently configured in autoconf but never
+//               modified by anyone, nor could I see why they ever would be.
+//               Once autoconf is removed, they should be switched over to
+//               a constant in a header file.
+
+#define BUSNAME_LOGGING "xyz.openbmc_project.Logging"
+#define OBJ_INTERNAL "/xyz/openbmc_project/logging/internal/manager"
+
+// vim: ft=cpp
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..64931d9
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,99 @@
+project('phosphor-logging', 'cpp',
+    meson_version: '>= 0.57.0',
+    default_options: [
+      'buildtype=debugoptimized',
+      'cpp_std=c++20',
+      'warning_level=3',
+      'werror=true',
+    ],
+    version: '1.0.0',
+)
+
+python_prog = find_program('python3')
+
+# Get sdbusplus dependency.
+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
+
+# Get PDI and sdeventplus dependency.
+pdi_dep = dependency(
+    'phosphor-dbus-interfaces',
+    fallback: ['phosphor-dbus-interfaces', 'phosphor_dbus_interfaces_dep'],
+)
+sdeventplus_dep = dependency(
+    'sdeventplus',
+    fallback: ['sdeventplus', 'sdeventplus_dep' ],
+)
+
+# Find the installed YAML directory, either from a configure option or
+# by pulling it from the PDI dependency.
+yamldir = get_option('yamldir')
+if yamldir == ''
+    yamldir = pdi_dep.get_variable(pkgconfig: 'yamldir', internal: 'yamldir')
+endif
+
+# Create config.h with constants that use to come from autoconf.
+conf_data = configuration_data()
+configure_file(
+    input: 'config.h.meson',
+    output: 'config.h',
+    configuration: conf_data,
+)
+
+# Generate callouts-gen.hpp.
+callouts_gen = custom_target('callouts-gen.hpp'.underscorify(),
+    input: [
+        'callouts/callouts.py',
+        'callouts/callouts-gen.mako.hpp',
+        get_option('callout_yaml'),
+    ],
+    output: 'callouts-gen.hpp',
+    command: [ python_prog, '@INPUT0@', '-i', '@INPUT2@', '-o', '@OUTPUT0@' ],
+)
+
+subdir('phosphor-logging')
+
+# Build libphosphor-logging.
+libphosphor_logging = library(
+    'phosphor_logging',
+    files(
+        'elog.cpp',
+        'elog_meta.cpp',
+        'sdjournal.cpp',
+    ),
+    callouts_gen,
+    elog_errors_gen,
+    dependencies: [ sdbusplus_dep, pdi_dep, sdeventplus_dep ],
+    version: meson.project_version(),
+    install: true,
+)
+
+import('pkgconfig').generate(
+    libphosphor_logging,
+    name: meson.project_name(),
+    version: meson.project_version(),
+    requires: [
+        'libsystemd',
+        'phosphor-dbus-interfaces',
+        'sdbusplus',
+    ],
+    description: 'Phosphor logging utilities',
+)
+
+# Create dependency for use as subproject.
+phosphor_logging_dep = declare_dependency(
+    include_directories: include_directories('.'),
+    link_with: libphosphor_logging,
+    sources: [ callouts_gen, elog_errors_gen ],
+    dependencies: [ sdbusplus_dep, pdi_dep, sdeventplus_dep],
+)
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..0a8c744
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,7 @@
+option('yamldir', type: 'string', description: 'Path to YAML')
+option(
+    'callout_yaml',
+    type: 'string',
+    value: 'callouts/callouts-example.yaml',
+    description: 'Path to Callout YAML',
+)
diff --git a/phosphor-logging/meson.build b/phosphor-logging/meson.build
new file mode 100644
index 0000000..13bd34a
--- /dev/null
+++ b/phosphor-logging/meson.build
@@ -0,0 +1,35 @@
+# Generate elog-errors.hpp.
+elog_errors_gen = custom_target('elog-errors.hpp'.underscorify(),
+    input: files(
+        '../tools/elog-gen.py',
+        '../tools/phosphor-logging/templates/elog-gen-template.mako.hpp',
+    ),
+    output: 'elog-errors.hpp',
+    command: [
+        python_prog, '@INPUT0@',
+        '-t', '',
+        '-m', '@INPUT1@',
+        '-y', yamldir,
+        '-u', meson.current_source_dir() / '../tools/',
+        '-o', '@OUTPUT0@',
+    ],
+    install: true,
+    install_dir: get_option('includedir') / 'phosphor-logging',
+)
+
+elog_errors_dep = declare_dependency(
+    include_directories: include_directories('..'),
+    sources: [elog_errors_gen],
+)
+
+# Install headers.
+install_headers(
+    'elog.hpp',
+    'log.hpp',
+    'sdjournal.hpp',
+    subdir: 'phosphor-logging',
+)
+install_headers(
+    'test/sdjournal_mock.hpp',
+    subdir: 'phosphor-logging/test',
+)
diff --git a/subprojects/phosphor-dbus-interfaces.wrap b/subprojects/phosphor-dbus-interfaces.wrap
new file mode 100644
index 0000000..935a8b2
--- /dev/null
+++ b/subprojects/phosphor-dbus-interfaces.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/phosphor-dbus-interfaces.git
+revision = HEAD
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/subprojects/sdeventplus.wrap b/subprojects/sdeventplus.wrap
new file mode 100644
index 0000000..085bb5e
--- /dev/null
+++ b/subprojects/sdeventplus.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/sdeventplus.git
+revision = HEAD