Add meson build
This commit is to add meson.build.
And later, we will remove Autotools and replace it with meson build.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I3107491093a6b69f966bab6eeb4f2d7581bfa186
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..0b66f4b
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,52 @@
+project(
+ 'phosphor-ledcontroller', 'cpp',
+ version : '1.0.0',
+ meson_version: '>=0.57.0',
+ default_options: [
+ 'warning_level=3',
+ 'werror=true',
+ 'cpp_std=c++20',
+ 'buildtype=debugoptimized'
+ ]
+)
+
+sdbusplus_dep = dependency(
+ 'sdbusplus',
+ fallback: [
+ 'sdbusplus',
+ 'sdbusplus_dep'
+ ],
+)
+phosphor_dbus_interfaces_dep = dependency(
+ 'phosphor-dbus-interfaces',
+ fallback: [
+ 'phosphor-dbus-interfaces',
+ 'phosphor_dbus_interfaces_dep'
+ ],
+)
+
+deps = [
+ sdbusplus_dep,
+ phosphor_dbus_interfaces_dep,
+]
+
+sources = [
+ 'argument.cpp',
+ 'controller.cpp',
+ 'physical.cpp',
+ 'sysfs.cpp',
+]
+
+executable(
+ 'phosphor-ledcontroller',
+ sources,
+ implicit_include_directories: true,
+ dependencies: deps,
+ install: true,
+ install_dir: '/usr/sbin'
+)
+
+build_tests = get_option('tests')
+if build_tests.enabled()
+ subdir('test')
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..a0d316a
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1 @@
+option('tests', type : 'feature', description : 'Build tests', value: 'enabled')
\ No newline at end of file
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/sdbusplus.wrap b/subprojects/sdbusplus.wrap
new file mode 100644
index 0000000..d470130
--- /dev/null
+++ b/subprojects/sdbusplus.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/sdbusplus.git
+revision = HEAD
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..00f3005
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,46 @@
+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 = [
+ '../physical.cpp',
+ '../sysfs.cpp',
+]
+
+tests = [
+ 'physical.cpp',
+ 'sysfs.cpp',
+]
+
+foreach t : tests
+ test(t,
+ executable(
+ t.underscorify(),
+ t,
+ test_sources,
+ include_directories: ['..'],
+ dependencies: [
+ gtest_dep,
+ gmock_dep,
+ deps
+ ]
+ )
+ )
+endforeach
\ No newline at end of file