meson: add support for sdbusplus library vendoring

Abuse the meson subproject command to download sdbusplus and build
against that when it is not found in the usual places.

This is abuse because the subproject command will always fail - meson
only supports other meson projects as subprojects but it will download
the project.

Build sdbusplus at configure time and link to that.  Cross compiling
might work but it is not supported and not a good idea - the intent is
to enable building and running of the unit tests without needing to
install sdbusplus.

Change-Id: Ic888dbce3ac189eb4163a125c49cf336d357983b
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/build-sdbusplus.sh b/build-sdbusplus.sh
new file mode 100755
index 0000000..dbf4824
--- /dev/null
+++ b/build-sdbusplus.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+set -e
+if [ ! -d $MESON_BUILD_ROOT/sdbusplus ]; then
+    cp -r $MESON_SOURCE_ROOT/subprojects/sdbusplus $MESON_BUILD_ROOT
+    cd $MESON_BUILD_ROOT/sdbusplus
+    ./bootstrap.sh
+    ./configure --enable-transaction
+    make -j libsdbusplus.la
+fi
diff --git a/meson.build b/meson.build
index 6f68902..74086d5 100644
--- a/meson.build
+++ b/meson.build
@@ -38,7 +38,19 @@
         ]
     )
 endif
-sdbusplus = dependency('sdbusplus')
+sdbusplus = dependency('sdbusplus', required: false)
+if not sdbusplus.found()
+    subproject('sdbusplus', required: false)
+    run_command(find_program('build-sdbusplus.sh'), check: true)
+    sdbusplus = declare_dependency(
+        dependencies: dependency('libsystemd'),
+        include_directories: 'sdbusplus',
+        link_args: [
+            'sdbusplus/.libs/libsdbusplus.so',
+            '-Wl,-rpath,$ORIGIN/../sdbusplus/.libs'
+        ],
+    )
+endif
 systemd = dependency('systemd')
 systemd_system_unit_dir = systemd.get_pkgconfig_variable(
     'systemdsystemunitdir',
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