build: Propagate boost arguments as needed

This aligns sdbusplus_dep and the packageconfig to pass the needed
dependency information to utilize boost ASIO with the expected compiler
arguments.

Change-Id: I4916fbeaf741db3165358d800229e984f53b687b
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/example/meson.build b/example/meson.build
index 5a6606e..837c6f7 100644
--- a/example/meson.build
+++ b/example/meson.build
@@ -4,48 +4,44 @@
     dependencies: sdbusplus_dep,
 )
 
+has_asio = meson.get_compiler('cpp').has_header_symbol(
+  'boost/asio.hpp',
+  'boost::asio::io_context',
+  required: false)
+asio_dep = sdbusplus_dep
+if not has_asio
+  asio_dep = disabler()
+endif
+
 assert(
-    not get_option('examples').enabled() or boost_dep.found(),
+    not get_option('examples').enabled() or has_asio,
     'Boost is required when examples are enabled'
 )
 
 executable(
     'asio-example',
     'asio-example.cpp',
-    cpp_args: [
-        '-DBOOST_ASIO_DISABLE_THREADS',
-        '-DBOOST_ALL_NO_LIB',
-        '-DBOOST_SYSTEM_NO_DEPRECATED',
-        '-DBOOST_ERROR_CODE_HEADER_ONLY',
-        '-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
+    dependencies: [
+        asio_dep,
+        dependency(
+            'boost',
+            modules: ['coroutine', 'context'],
+            disabler: true,
+            required: false,
+        ),
     ],
-    dependencies: [ boost_dep, sdbusplus_dep ],
 )
 
 executable(
     'register-property',
     'register-property.cpp',
-    cpp_args: [
-        '-DBOOST_ASIO_DISABLE_THREADS',
-        '-DBOOST_ALL_NO_LIB',
-        '-DBOOST_SYSTEM_NO_DEPRECATED',
-        '-DBOOST_ERROR_CODE_HEADER_ONLY',
-        '-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
-    ],
-    dependencies: [ boost_dep, sdbusplus_dep ],
+    dependencies: asio_dep,
 )
 
 executable(
     'get-all-properties',
     'get-all-properties.cpp',
-    cpp_args: [
-        '-DBOOST_ASIO_DISABLE_THREADS',
-        '-DBOOST_ALL_NO_LIB',
-        '-DBOOST_SYSTEM_NO_DEPRECATED',
-        '-DBOOST_ERROR_CODE_HEADER_ONLY',
-        '-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
-    ],
-    dependencies: [ boost_dep, sdbusplus_dep ],
+    dependencies: asio_dep,
 )
 
 calc_buildroot = meson.current_build_dir()
diff --git a/meson.build b/meson.build
index 790684e..3a8a5cf 100644
--- a/meson.build
+++ b/meson.build
@@ -31,21 +31,26 @@
     install: true,
 )
 
+boost_compile_args = [
+    '-DBOOST_ASIO_DISABLE_THREADS',
+    '-DBOOST_ALL_NO_LIB',
+    '-DBOOST_SYSTEM_NO_DEPRECATED',
+    '-DBOOST_ERROR_CODE_HEADER_ONLY',
+    '-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
+]
+
+boost_dep = declare_dependency(
+    dependencies: dependency('boost', required: false),
+    compile_args: boost_compile_args)
+
 sdbusplus_dep = declare_dependency(
     include_directories: root_inc,
     link_with: libsdbusplus,
-    dependencies: libsystemd_pkg
+    dependencies: [ libsystemd_pkg, boost_dep ],
 )
 
 subdir('tools')
 
-boost_dep = dependency(
-    'boost',
-    disabler: true,
-    required: false,
-    modules: [ 'coroutine', 'context' ],
-)
-
 if not get_option('examples').disabled()
   subdir('example')
 endif
@@ -64,5 +69,6 @@
     name: meson.project_name(),
     version: meson.project_version(),
     requires: libsystemd_pkg,
+    extra_cflags: boost_compile_args,
     description: 'C++ bindings for sdbus',
 )