build: provide an option to skip systemd units

The systemd pkg-config tells clients to install unit files to (a subdir
of) rootprefix, not prefix.  This means our attempt to substitute our
prefix into systemd_system_unitdir doesn't have any impact - thus we
remove the substitution.

Rather than attempt to cook up some kind of support for rootprefix,
which is a quasi-standard variable anyway, provide a mechanism to simply
skip installing the systemd unit files.  This enables users with a
prefix pointing somewhere they can access to get all the way through the
install process without needing root or contaminating the build system.

It would be reasonable to use this option in the future to turn off any
additional systemd support added to the project.

Change-Id: I9a06cc09a2d940fed8a7fdc2f583f5949a0ecd47
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/meson.build b/meson.build
index 92315ac..14b67d5 100644
--- a/meson.build
+++ b/meson.build
@@ -73,7 +73,6 @@
   'sdeventplus',
   fallback: ['sdeventplus', 'sdeventplus_dep'],
 )
-systemd = dependency('systemd')
 
 cpp = meson.get_compiler('cpp')
 
@@ -197,27 +196,28 @@
   install: true,
   install_dir: get_option('bindir'))
 
-systemd_system_unit_dir = systemd.get_variable(
-        pkgconfig: 'systemdsystemunitdir',
-        pkgconfig_define: ['prefix', get_option('prefix')])
+if get_option('systemd').enabled()
+  systemd_system_unit_dir = dependency('systemd').get_variable(
+          pkgconfig: 'systemdsystemunitdir')
 
-configure_file(
-  copy: true,
-  input: 'pldmd/service_files/pldmd.service',
-  install: true,
-  install_dir: systemd_system_unit_dir,
-  output: 'pldmd.service',
-)
+  configure_file(
+    copy: true,
+    input: 'pldmd/service_files/pldmd.service',
+    install: true,
+    install_dir: systemd_system_unit_dir,
+    output: 'pldmd.service',
+  )
 
-configure_file(
-  input: 'pldmd/verbosity/verbosity',
-  output: 'pldm_verbosity',
-  configuration: conf_data,
-  install: true,
-  install_dir: join_paths(get_option('sysconfdir'), 'default'))
+  configure_file(
+    input: 'pldmd/verbosity/verbosity',
+    output: 'pldm_verbosity',
+    configuration: conf_data,
+    install: true,
+    install_dir: join_paths(get_option('sysconfdir'), 'default'))
 
-if get_option('oem-ibm').enabled()
-  subdir('oem/ibm/service_files')
+  if get_option('oem-ibm').enabled()
+    subdir('oem/ibm/service_files')
+  endif
 endif
 
 subdir('pldmtool')
diff --git a/meson_options.txt b/meson_options.txt
index 6df6dd9..9943e82 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -11,6 +11,8 @@
 option('softoff', type: 'feature', description: 'Build soft power off application', value: 'enabled')
 option('softoff-timeout-seconds', type: 'integer', description: 'softoff: Time to wait for host to gracefully shutdown', value: 7200)
 
+option('systemd', type: 'feature', description: 'Include systemd support', value: 'enabled')
+
 # Timing specifications for PLDM messages
 option('number-of-request-retries', type: 'integer', min: 2, max: 30, description: 'The number of times a requester is obligated to retry a request', value: 2)
 option('instance-id-expiration-interval', type: 'integer', min: 5, max: 6, description: 'Instance ID expiration interval in seconds', value: 5)
diff --git a/softoff/meson.build b/softoff/meson.build
index d67a444..a02a306 100644
--- a/softoff/meson.build
+++ b/softoff/meson.build
@@ -15,8 +15,10 @@
            install: true,
            install_dir: get_option('bindir'))
 
-configure_file(input: 'services/pldmSoftPowerOff.service',
-                 output: 'pldmSoftPowerOff.service',
-                 copy: true,
-                 install_dir: systemd_system_unit_dir)
+if get_option('systemd').enabled()
+  configure_file(input: 'services/pldmSoftPowerOff.service',
+                   output: 'pldmSoftPowerOff.service',
+                   copy: true,
+                   install_dir: systemd_system_unit_dir)
+endif