Enable Meson option to build parser and test cases
Meson script to build parser and test cases.
It will replace the use of auto tools to
build the code.
- Steps to build
In the directory, where you have meson.build file
execute the following commands.
meson -Doption=value builddir
<This will create a builddir>
ninja -C builddir
<Creates EXE>
ninja -C builddir test
<Executes unit tests>
Change-Id: Ic351daf2c135b06e1b04048a4a6ad8d9897fba54
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/.gitignore b/.gitignore
index 71665e0..4ab572b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,4 @@
store_test
*.log
*.trs
+builddir
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..8d95281
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,106 @@
+project(
+ 'openpower-vpd-parser',
+ 'c',
+ 'cpp',
+ default_options: [
+ 'cpp_std=c++17'
+ ],
+ version: '1.0'
+)
+
+build_tests = get_option('tests')
+
+sdbusplus = dependency('sdbusplus')
+phosphor_logging = dependency('phosphor-logging')
+
+compiler = meson.get_compiler('cpp')
+python = find_program('python3', required:true)
+
+if get_option('ibm-parser').enabled()
+compiler.has_header('CLI/CLI.hpp')
+compiler.has_header('nlohmann/json.hpp')
+configure_file(output: 'config.h',
+ configuration :{
+ 'INVENTORY_JSON': '"'+get_option('INVENTORY_JSON')+'"',
+ }
+ )
+ ibm_read_vpd_SOURCES = ['ibm_vpd_app.cpp',
+ 'ibm_vpd_type_check.cpp',
+ 'parser.cpp',
+ 'impl.cpp',
+ 'utils.cpp',
+ 'keyword_vpd_parser.cpp',
+ 'vpdecc/vpdecc.c',
+ 'vpdecc/vpdecc_support.c'
+ ]
+
+ ibm_vpd_exe = executable(
+ 'ibm-read-vpd',
+ ibm_read_vpd_SOURCES,
+ dependencies: [
+ sdbusplus,
+ phosphor_logging,
+ ],
+ install: true,
+ cpp_args : '-DIPZ_PARSER'
+ )
+else
+ FRUGEN = '$srcdir/extra-properties.py -e' + get_option('FRU_YAML')
+ PROPGEN = '$srcdir/extra-properties.py -e' + get_option('PROP_YAML')
+
+ src_dir = meson.source_root()
+ FRU_GEN_SCRIPT = src_dir + '/writefru.py'
+ FRU_GEN_SCRIPT_FILES = src_dir + '/writefru.yaml'
+
+ PROP_GEN_SCRIPT = src_dir + '/extra-properties.py'
+ PROP_GEN_SCRIPT_FILES = src_dir + '/extra-properties-example.yaml'
+
+ writefru_hpp = custom_target('writefru.hpp',
+ command:[python,
+ FRU_GEN_SCRIPT,
+ '-i',
+ get_option('FRU_YAML')
+ ],
+ depend_files :['writefru.mako.hpp',
+ 'writefru.py',
+ get_option('FRU_YAML')
+ ],
+ output:'writefru.hpp'
+ )
+
+ extra_properties_gen_hpp = custom_target(
+ 'extra-properties-gen.hpp',
+ command:[
+ python,
+ PROP_GEN_SCRIPT,
+ '-e',
+ get_option('PROP_YAML')
+ ],
+ depend_files : ['extra-properties.mako.hpp',
+ 'extra-properties.py',
+ get_option('PROP_YAML')
+ ],
+ output:'extra-properties-gen.hpp'
+ )
+
+ openpower_read_vpd_SOURCES = ['app.cpp',
+ 'args.cpp',
+ 'impl.cpp',
+ 'parser.cpp',
+ 'write.cpp',
+ 'utils.cpp',
+ writefru_hpp,
+ extra_properties_gen_hpp
+ ]
+
+ openpower_read_vpd_exe= executable(
+ 'openpower-read-vpd',
+ openpower_read_vpd_SOURCES,
+ dependencies: [
+ sdbusplus,
+ phosphor_logging,
+ ],
+ install: true,
+ )
+endif
+subdir('test')
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..f198832
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,6 @@
+option('oe-sdk', type: 'feature', description: 'ENABLE OE SDK FOR OPENPOWER VPD PARSER')
+option('tests', type: 'feature', value : 'enabled', description: 'Build tests')
+option('FRU_YAML',type: 'string', value: 'writefru.yaml', description: 'YAML STRING')
+option('PROP_YAML',type: 'string', value: 'extra-properties-example.yaml', description: 'YAML PROPERTY')
+option('ibm-parser', type: 'feature', description: 'ENABLE IBM PARSER')
+option('INVENTORY_JSON',type: 'string', value: '/usr/share/vpd/vpd_inventory.json', description: 'JSON file that defines inventory blueprint')
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..a8f9793
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,60 @@
+if get_option('oe-sdk').enabled()
+ # Setup OE SYSROOT
+ OECORE_TARGET_SYSROOT = run_command('sh', '-c', 'echo $OECORE_TARGET_SYSROOT').stdout().strip()
+ if OECORE_TARGET_SYSROOT == ''
+ error('Unable to get $OECORE_TARGET_SYSROOT, check your environment.')
+ endif
+ message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
+ rpath = ':'.join([OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'])
+ ld_so = run_command('sh', '-c', 'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1').stdout().strip()
+ dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
+else
+ dynamic_linker = []
+endif
+
+gmock = dependency('gmock', disabler: true, required: build_tests)
+gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
+
+application_src = ['../impl.cpp']
+
+test('store_test', executable('store_test',
+ ['store/store.cpp', application_src],
+build_rpath: get_option('oe-sdk').enabled() ? rpath : '',
+
+link_args: dynamic_linker,
+dependencies: [
+ gtest,
+ gmock,
+ sdbusplus,
+ phosphor_logging,
+ ],
+include_directories: '..'
+),
+workdir: meson.current_source_dir())
+
+vpd_test = ['ipz_parser/parser.cpp',
+ 'keyword_vpd_parser_test/kw_vpd_test.cpp'
+ ]
+application_src += ['../keyword_vpd_parser.cpp',
+ '../vpdecc/vpdecc.c',
+ '../vpdecc/vpdecc_support.c'
+ ]
+foreach t : vpd_test
+ test(t, executable(t.underscorify(),
+ [t, application_src],
+ build_rpath: get_option('oe-sdk').enabled() ? rpath : '',
+
+ link_args: dynamic_linker,
+ cpp_args: '-DIPZ_PARSER',
+ c_args: ['-Wno-unused-parameter',
+ '-Wno-unused-variable'],
+ dependencies: [
+ gtest,
+ gmock,
+ sdbusplus,
+ phosphor_logging,
+ ],
+ include_directories: '..'
+ ),
+ workdir: meson.current_source_dir())
+endforeach