build: Add wrapfiles for dependencies

- Update meson.build and add wrapfiles so that all dependencies are
  handled as subprojects.

- This allows builds completely outside of bitbake or an SDK.
  refer: https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-virtual-sensor/+/42349

Tested: built ledManager repo successfully using `meson build`.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I35db603d4aa9c2eee41c3cfb27eba6953950fe44
diff --git a/meson.build b/meson.build
index 387c469..f0c7d11 100644
--- a/meson.build
+++ b/meson.build
@@ -38,11 +38,27 @@
     )
 endif
 
-sdeventplus = dependency('sdeventplus')
-phosphorlogging = dependency('phosphor-logging')
-phosphordbusinterfaces = dependency('phosphor-dbus-interfaces')
-gtest = dependency('gtest', main: true, disabler: true, required: true)
-gmock = dependency('gmock', disabler: true, required: true)
+sdeventplus_dep = dependency(
+    'sdeventplus',
+    fallback: [
+        'sdeventplus',
+        'sdeventplus_dep'
+    ],
+)
+phosphor_logging_dep = dependency(
+    'phosphor-logging',
+    fallback: [
+        'phosphor-logging',
+        'phosphor_logging_dep'
+    ],
+)
+phosphor_dbus_interfaces_dep = dependency(
+    'phosphor-dbus-interfaces',
+    fallback: [
+        'phosphor-dbus-interfaces',
+        'phosphor_dbus_interfaces_dep'
+    ],
+)
 prog_python = find_program('python3', required: true)
 realpath_prog = find_program('realpath')
 
@@ -97,9 +113,9 @@
 
 deps = [
     sdbusplus_dep,
-    sdeventplus,
-    phosphorlogging,
-    phosphordbusinterfaces,
+    sdeventplus_dep,
+    phosphor_logging_dep,
+    phosphor_dbus_interfaces_dep,
     nlohmann_json
 ]
 
diff --git a/subprojects/googletest.wrap b/subprojects/googletest.wrap
new file mode 100644
index 0000000..766a562
--- /dev/null
+++ b/subprojects/googletest.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/google/googletest.git
+revision = HEAD
diff --git a/subprojects/phosphor-dbus-interfaces.wrap b/subprojects/phosphor-dbus-interfaces.wrap
new file mode 100644
index 0000000..935a8b2
--- /dev/null
+++ b/subprojects/phosphor-dbus-interfaces.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/phosphor-dbus-interfaces.git
+revision = HEAD
diff --git a/subprojects/phosphor-logging.wrap b/subprojects/phosphor-logging.wrap
new file mode 100644
index 0000000..a039fcf
--- /dev/null
+++ b/subprojects/phosphor-logging.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/phosphor-logging.git
+revision = HEAD
diff --git a/subprojects/sdeventplus.wrap b/subprojects/sdeventplus.wrap
new file mode 100644
index 0000000..085bb5e
--- /dev/null
+++ b/subprojects/sdeventplus.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/sdeventplus.git
+revision = HEAD
diff --git a/test/meson.build b/test/meson.build
index feb6578..059d13c 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,3 +1,24 @@
+gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
+gmock_dep = dependency('gmock', disabler: true, required: false)
+if not gtest_dep.found() or not gmock_dep.found()
+    gtest_proj = import('cmake').subproject('googletest', required: false)
+    if gtest_proj.found()
+        gtest_dep = declare_dependency(
+            dependencies: [
+                dependency('threads'),
+                gtest_proj.dependency('gtest'),
+                gtest_proj.dependency('gtest_main'),
+            ]
+        )
+        gmock_dep = gtest_proj.dependency('gmock')
+  else
+        assert(
+            not get_option('tests').enabled(),
+            'Googletest is required if tests are enabled'
+        )
+  endif
+endif
+
 test_sources = [
   '../manager.cpp',
   '../serialize.cpp',
@@ -18,8 +39,8 @@
                      test_sources,
                      include_directories: ['..'],
                      dependencies: [
-                         gtest,
-                         gmock,
+                         gtest_dep,
+                         gmock_dep,
                          deps
                          ]),
        workdir: meson.current_source_dir())