meson: handle missing ldap dependency

Adjust the meson.build so that ldap can be an optional dependency.
This allows out-of-docker builds for environments which might not have
the LDAP libraries installed.  In the future this could also be
leveraged by a meson.option that would disable LDAP support.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I214b7e69580bd11432f88a85fa760a5e07f7fad2
diff --git a/meson.build b/meson.build
index c22c4c4..5611661 100644
--- a/meson.build
+++ b/meson.build
@@ -79,14 +79,15 @@
 
 conf_header = configure_file(output: 'config.h', configuration: conf_data)
 
-phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
-sdbusplus_dep = dependency('sdbusplus')
-phosphor_logging_dep = dependency('phosphor-logging')
-systemd_dep = dependency('systemd')
-
 cpp = meson.get_compiler('cpp')
 
 boost_dep = dependency('boost')
+ldap_dep = cpp.find_library('ldap', required: false)
+pam_dep = dependency('pam')
+phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
+phosphor_logging_dep = dependency('phosphor-logging')
+sdbusplus_dep = dependency('sdbusplus')
+systemd_dep = dependency('systemd')
 
 # Get Cereal dependency.
 cereal_dep = dependency('cereal', required: false)
@@ -109,7 +110,6 @@
     assert(cereal_proj.found(), 'cereal is required')
     cereal_dep = cereal_proj.dependency('cereal')
 endif
-pam_dep = dependency('pam')
 user_manager_src = ['mainapp.cpp', 'user_mgr.cpp', 'users.cpp']
 
 
@@ -185,7 +185,9 @@
     ),
 )
 
-subdir('phosphor-ldap-config')
+if ldap_dep.found()
+    subdir('phosphor-ldap-config')
+endif
 
 if get_option('tests').allowed()
     subdir('test')
diff --git a/phosphor-ldap-config/meson.build b/phosphor-ldap-config/meson.build
index 2f79486..05654f2 100644
--- a/phosphor-ldap-config/meson.build
+++ b/phosphor-ldap-config/meson.build
@@ -1,5 +1,3 @@
-ldap_dep = meson.get_compiler('cpp').find_library('ldap', required: true)
-
 phosphor_ldap_conf_deps = [
     boost_dep,
     cereal_dep,
diff --git a/test/meson.build b/test/meson.build
index 61965df..2bdc805 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -19,16 +19,23 @@
     endif
 endif
 
-test(
-    'ldap_config_test',
-    executable(
+if ldap_dep.found()
+    test(
         'ldap_config_test',
-        ['ldap_config_test.cpp', 'utils_test.cpp'],
-        include_directories: '..',
-        dependencies: [gtest_dep, gmock_dep, phosphor_ldap_conf_dep],
-        link_args: ['-lldap'],
-    ),
-)
+        executable(
+            'ldap_config_test',
+            ['ldap_config_test.cpp', 'utils_test.cpp'],
+            include_directories: '..',
+            dependencies: [
+                gmock_dep,
+                gtest_dep,
+                ldap_dep,
+                phosphor_ldap_conf_dep,
+            ],
+            link_args: ['-lldap'],
+        ),
+    )
+endif
 
 test(
     'user_mgr_test',