compile: Add meson build support
Signed-off-by: Jie Yang <jjy@google.com>
Change-Id: I71c0e2a62b4bd9b97cbe9a87788a0569f74847a0
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..4d2e011
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,61 @@
+project(
+ 'phosphor-ipmi-blobs-binarystore',
+ 'cpp',
+ version: '0.1',
+ meson_version: '>=0.57.0',
+ default_options: [
+ 'cpp_std=c++20',
+ 'warning_level=3',
+ 'werror=true',
+ ]
+)
+
+
+cpp = meson.get_compiler('cpp')
+cpp.has_header('boost/endian/arithmetic.hpp')
+cpp.has_header('nlohmann/json.hpp')
+protobuf_dep = dependency('protobuf')
+ipmi_blob_dep = dependency('phosphor-ipmi-blobs')
+phosphor_logging_dep = dependency('phosphor-logging')
+
+subdir('proto')
+
+binarystoreblob_pre = declare_dependency(
+ include_directories: [
+ include_directories('.'),
+ include_directories('proto')],
+ dependencies: [
+ protobuf_dep,
+ ipmi_blob_dep,
+ phosphor_logging_dep,
+ ])
+
+binarystoreblob_lib = library(
+ 'binarystore',
+ 'binarystore.cpp',
+ 'sys.cpp',
+ 'sys_file_impl.cpp',
+ 'handler.cpp',
+ proto,
+ implicit_include_directories: false,
+ dependencies: binarystoreblob_pre,
+ install: true,
+ install_dir: get_option('libdir') / 'blob-ipmid')
+
+binarystoreblob_dep = declare_dependency(
+ link_with: binarystoreblob_lib,
+ dependencies: binarystoreblob_pre)
+
+if not get_option('blobtool').disabled()
+ executable(
+ 'blobtool',
+ 'blobtool.cpp',
+ implicit_include_directories: false,
+ dependencies: binarystoreblob_dep,
+ install: true)
+endif
+
+
+if not get_option('tests').disabled()
+ subdir('test')
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..30c97e5
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,2 @@
+option('tests', type: 'feature', description: 'Build tests')
+option('blobtool', type: 'feature', description: 'Build blobtool cli')
diff --git a/proto/meson.build b/proto/meson.build
new file mode 100644
index 0000000..0600083
--- /dev/null
+++ b/proto/meson.build
@@ -0,0 +1,13 @@
+proto = custom_target(
+ 'proto',
+ command: [
+ find_program('protoc', native: true),
+ '--proto_path=@CURRENT_SOURCE_DIR@',
+ '--cpp_out=@OUTDIR@',
+ '@INPUT@'
+ ],
+ output: [
+ 'binaryblob.pb.cc',
+ 'binaryblob.pb.h',
+ ],
+ input: 'binaryblob.proto')
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..66a964c
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,26 @@
+gtest = dependency('gtest', main: true, disabler: true, required: get_option('tests'))
+gmock = dependency('gmock', disabler: true, required: get_option('tests'))
+
+test_dep = declare_dependency(
+ include_directories: include_directories('.'),
+ dependencies: [gtest, gmock])
+
+tests = [
+ 'parse_config_unittest',
+ 'sys_file_unittest',
+ 'handler_unittest',
+ 'handler_open_unittest',
+ 'handler_readwrite_unittest',
+ 'handler_commit_unittest',
+ 'handler_stat_unittest',
+]
+
+foreach t : tests
+ test(
+ t,
+ executable(
+ t.underscorify(),
+ t + '.cpp',
+ implicit_include_directories: false,
+ dependencies: [binarystoreblob_dep, test_dep]))
+endforeach