build: Add options for tweaking what is built

We don't need to always build tests or examples so make it possible for
the user to configure what is built. The default is to automatically
build them if possible.

Change-Id: I5cb6b1689c408188f14d1fcbcfb0006c17f1c90d
Signed-off-by: William A. Kennington III <wak@google.com>
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/example/meson.build b/example/meson.build
index 044d3a9..957c01d 100644
--- a/example/meson.build
+++ b/example/meson.build
@@ -4,6 +4,11 @@
     dependencies: sdbusplus_dep,
 )
 
+assert(
+    not get_option('examples').enabled() or boost_dep.found(),
+    'Boost is required when examples are enabled'
+)
+
 executable(
     'asio-example',
     'asio-example.cpp',
diff --git a/meson.build b/meson.build
index bbf43a7..6cacf8c 100644
--- a/meson.build
+++ b/meson.build
@@ -40,8 +40,12 @@
     modules: [ 'coroutine', 'context' ],
 )
 
-subdir('example')
-subdir('test')
+if not get_option('examples').disabled()
+  subdir('example')
+endif
+if not get_option('tests').disabled()
+  subdir('test')
+endif
 
 install_subdir(
     'include/sdbusplus',
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..f4c22c4
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,2 @@
+option('tests', type: 'feature', description: 'Build tests')
+option('examples', type: 'feature', description: 'Build examples')
diff --git a/test/meson.build b/test/meson.build
index c33593a..1784e4c 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,5 +1,5 @@
-gtest_dep = dependency('gtest', main: true, disabler: true)
-gmock_dep = dependency('gmock', disabler: true)
+gtest_dep = dependency('gtest', main: true, disabler: true, required: get_option('tests'))
+gmock_dep = dependency('gmock', disabler: true, required: get_option('tests'))
 
 tests = [
     'bus/list_names',
@@ -29,6 +29,11 @@
     )
 endforeach
 
+assert(
+    not get_option('tests').enabled() or boost_dep.found(),
+    'Boost is required when tests are enabled'
+)
+
 test(
     'test-bus_aio',
     executable(