build: Add meson support

Add support for buildling with meson.

Support for --enable-oe-sdk is dropped because running unit tests on the
build system is now supported directly with meson subprojects:

meson buildir && ninja -C buildir test

I tested this by building a witherspoon image and booting it to
multi-user and verifying the mapper-wait functionality works correctly.

Change-Id: I86e5efc7b7c89183219a4c890ad658e334765fc1
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/.gitignore b/.gitignore
index 6b2bed0..cbe1832 100644
--- a/.gitignore
+++ b/.gitignore
@@ -119,3 +119,6 @@
 src/test/need_to_introspect
 src/test/well_known
 src/test/name_change
+build*/
+subprojects/*
+!subprojects/*.wrap
diff --git a/libmapper/test/meson.build b/libmapper/test/meson.build
new file mode 100644
index 0000000..203f0c3
--- /dev/null
+++ b/libmapper/test/meson.build
@@ -0,0 +1,13 @@
+tests = [
+    [ 'mapper', [ declare_dependency(sources: [ '../mapper.c', 'utils.c' ]) ]],
+]
+
+foreach t : tests
+    name = t[0]
+    extra_deps = t[1]
+    test(name, executable(name.underscorify(), name + '.cpp',
+                     implicit_include_directories: false,
+                     dependencies: [gtest, gmock, sdbusplus, extra_deps],
+                     include_directories: ['../..']),
+         workdir: meson.current_source_dir())
+endforeach
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..3c536af
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,107 @@
+project(
+    'phosphor-objmgr',
+    'c', 'cpp',
+    default_options: [
+        'cpp_std=c++17',
+        'warning_level=3',
+        'werror=true',
+    ],
+    license: 'Apache-2.0',
+    version: '1.0',
+)
+
+phosphor_logging = dependency(
+    'phosphor-logging',
+    fallback: [
+        'phosphor-logging',
+        'phosphor_logging_dep'])
+sdbusplus = dependency(
+    'sdbusplus',
+    fallback: ['sdbusplus', 'sdbusplus_dep'])
+
+if get_option('tests').enabled()
+    gtest = dependency('gtest', main: true, disabler: true, required: false)
+    gmock = dependency('gmock', disabler: true, required: false)
+    if not gtest.found() or not gmock.found()
+        gtest_proj = import('cmake').subproject('googletest', required: false)
+        if gtest_proj.found()
+            gtest = declare_dependency(
+                dependencies: [
+                    dependency('threads'),
+                    gtest_proj.dependency('gtest'),
+                    gtest_proj.dependency('gtest_main'),
+                ]
+            )
+            gmock = gtest_proj.dependency('gmock')
+        else
+            assert(
+                not get_option('tests').enabled(),
+                'Googletest is required if tests are enabled'
+            )
+        endif
+    endif
+    subdir('src/test')
+    subdir('libmapper/test')
+endif
+
+conf = configuration_data()
+conf.set_quoted('MAPPER_BUSNAME', 'xyz.openbmc_project.ObjectMapper')
+conf.set_quoted('MAPPER_INTERFACE', 'xyz.openbmc_project.ObjectMapper')
+conf.set_quoted('MAPPER_PATH', '/xyz/openbmc_project/object_mapper')
+configure_file(output: 'config.h', configuration: conf)
+
+install_headers('libmapper/mapper.h')
+
+libmapper = library(
+    'mapper',
+    'libmapper/mapper.c',
+    dependencies: [ dependency('libsystemd') ],
+    gnu_symbol_visibility: 'hidden',
+    version: meson.project_version(),
+    install: true)
+
+import('pkgconfig').generate(
+    name: 'libmapper',
+    description: 'OpenBMC service discovery utility library',
+    version: meson.project_version(),
+    libraries: libmapper)
+
+executable(
+    'mapper',
+    'libmapper/app.c',
+    link_with: libmapper,
+    dependencies: [ dependency('libsystemd') ],
+    install: true)
+
+executable(
+    'mapperx',
+    [
+        'src/main.cpp',
+        'src/argument.cpp',
+        'src/processing.cpp',
+        'src/associations.cpp',
+    ],
+    dependencies: [
+        dependency('boost'),
+        dependency('libsystemd'),
+        phosphor_logging,
+        sdbusplus,
+        dependency('systemd'),
+        dependency('threads'),
+        dependency('tinyxml2'),
+    ],
+    install: true
+)
+
+executable(
+    'phosphor-unit-failure-monitor',
+    [
+        'fail-monitor/argument.cpp',
+        'fail-monitor/main.cpp',
+        'fail-monitor/monitor.cpp',
+    ],
+    dependencies: [
+        phosphor_logging,
+    ],
+    install: true
+)
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/src/test/meson.build b/src/test/meson.build
new file mode 100644
index 0000000..183ed88
--- /dev/null
+++ b/src/test/meson.build
@@ -0,0 +1,20 @@
+processing_cpp_dep = declare_dependency(sources: '../processing.cpp')
+associations_cpp_dep = declare_dependency(sources: '../associations.cpp')
+
+tests = [
+  [ 'well_known', [ associations_cpp_dep, processing_cpp_dep ]],
+  [ 'need_to_introspect', [ associations_cpp_dep, processing_cpp_dep ]],
+  [ 'associations', [ associations_cpp_dep ]],
+  [ 'name_change', [ associations_cpp_dep, processing_cpp_dep ]],
+  [ 'interfaces_added', [ associations_cpp_dep, processing_cpp_dep ]],
+]
+
+foreach t : tests
+  name = t[0]
+  extra_deps = t[1]
+  test(name, executable(name.underscorify(), name + '.cpp',
+                     implicit_include_directories: false,
+                     dependencies: [gtest, gmock, sdbusplus, extra_deps],
+                     include_directories: ['../..']),
+       workdir: meson.current_source_dir())
+endforeach
diff --git a/subprojects/googletest.wrap b/subprojects/googletest.wrap
new file mode 100644
index 0000000..56da9ef
--- /dev/null
+++ b/subprojects/googletest.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/google/googletest
+revision = HEAD
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/phosphor-logging.wrap b/subprojects/phosphor-logging.wrap
new file mode 100644
index 0000000..a039fcf
--- /dev/null
+++ b/subprojects/phosphor-logging.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/phosphor-logging.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