meson: create structure for use as submodule

Some other openbmc projects have set up sdbusplus to use as a
meson-subproject.  When porting one of them (entity-manager) to use
the meson build, I realized we are not structuring our meson.build
file according to best-practices for consumption as a submodule.
Specifically, we are missing the 'sdbusplus_dep' variable as described
in the meson reference: https://mesonbuild.com/Subprojects.html

Now that 'sdbusplus_dep' is defined, use it throughout the rest of
the meson.build files as well for simplification.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I79ad586aa185f769c7ecc83ef06e1f3897e8db2d
diff --git a/example/meson.build b/example/meson.build
index bd0e7c6..9b1cef4 100644
--- a/example/meson.build
+++ b/example/meson.build
@@ -1,9 +1,7 @@
 executable(
     'list-users',
     'list-users.cpp',
-    include_directories: root_inc,
-    link_with: libsdbusplus,
-    dependencies: libsystemd_pkg,
+    dependencies: sdbusplus_dep,
 )
 
 if boost_dep.found()
@@ -16,9 +14,7 @@
             '-DBOOST_ERROR_CODE_HEADER_ONLY',
             '-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
         ],
-        include_directories: root_inc,
-        link_with: libsdbusplus,
-        dependencies: [ boost_dep, pthread_dep, libsystemd_pkg ],
+        dependencies: [ boost_dep, pthread_dep, sdbusplus_dep ],
     )
 endif
 
@@ -37,7 +33,5 @@
     'calculator-server',
     'calculator-server.cpp',
     calc_files,
-    include_directories: root_inc,
-    link_with: libsdbusplus,
-    dependencies: libsystemd_pkg,
+    dependencies: sdbusplus_dep,
 )
diff --git a/meson.build b/meson.build
index 41d9984..8ea6b9b 100644
--- a/meson.build
+++ b/meson.build
@@ -24,6 +24,12 @@
     install: true,
 )
 
+sdbusplus_dep = declare_dependency(
+    include_directories: root_inc,
+    link_with: libsdbusplus,
+    dependencies: libsystemd_pkg
+)
+
 subdir('tools')
 
 boost_dep = dependency(
diff --git a/test/meson.build b/test/meson.build
index 7debf0e..59e17bb 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -22,13 +22,11 @@
         executable(
             'test-' + t.underscorify(),
             t + '.cpp',
-            include_directories: root_inc,
-            link_with: libsdbusplus,
             dependencies: [
                 gtest_dep,
                 gmock_dep,
                 gmock_main_dep,
-                libsystemd_pkg,
+                sdbusplus_dep,
             ],
         )
     )
@@ -40,9 +38,7 @@
         'test-vtable',
         'vtable/vtable.cpp',
         'vtable/vtable_c.c',
-        include_directories: root_inc,
-        link_with: libsdbusplus,
-        dependencies: [ gtest_dep, gtest_main_dep, libsystemd_pkg ],
+        dependencies: [ gtest_dep, gtest_main_dep, sdbusplus_dep ],
     ),
 )
 
@@ -63,14 +59,13 @@
         'test-server',
         'server/object.cpp',
         server_files,
-        include_directories: [ root_inc, include_directories('server') ],
-        link_with: libsdbusplus,
+        include_directories: include_directories('server'),
         dependencies: [
             gmock_dep,
             gmock_main_dep,
             gtest_dep,
-            libsystemd_pkg,
             pthread_dep,
+            sdbusplus_dep,
         ],
     ),
 )