1project(
2     'openpower-vpd-parser',
3     'c',
4     'cpp',
5     default_options: [
6       'warning_level=3',
7       'werror=true',
8       'cpp_std=c++23',
9       'buildtype=debugoptimized'
10     ],
11     version: '1.0',
12     meson_version: '>=1.1.1',
13)
14
15add_global_arguments('-Wno-psabi', language : ['c', 'cpp'])
16
17# Disable FORTIFY_SOURCE when compiling with no optimization
18if(get_option('optimization') == '0')
19  add_project_arguments('-U_FORTIFY_SOURCE',language:['cpp','c'])
20  message('Disabling FORTIFY_SOURCE as optimization is set to 0')
21endif
22
23# Setup googletest before we import any projects that also depend on it to make
24# sure we have control over its configuration
25build_tests = get_option('tests')
26if not build_tests.disabled()
27    gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
28    gmock_dep = dependency('gmock', disabler: true, required: false)
29    if not gtest_dep.found() or not gmock_dep.found()
30        cmake = import('cmake')
31        gtest_opts = cmake.subproject_options()
32        gtest_opts.set_override_option('warning_level', '1')
33        gtest_opts.set_override_option('werror', 'false')
34        gtest_proj = cmake.subproject('googletest',
35                                      options: gtest_opts,
36                                      required: false)
37        if gtest_proj.found()
38            gtest_dep = declare_dependency(
39                dependencies: [
40                    dependency('threads'),
41                    gtest_proj.dependency('gtest'),
42                    gtest_proj.dependency('gtest_main'),
43                ]
44            )
45            gmock_dep = gtest_proj.dependency('gmock')
46        else
47            assert(not get_option('tests').allowed(),
48                   'Googletest is required if tests are enabled')
49        endif
50    endif
51endif
52
53nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
54
55phosphor_dbus_interfaces = dependency('phosphor-dbus-interfaces',
56    default_options: [ 'data_com_ibm=true', 'data_org_open_power=true' ],
57    fallback: ['phosphor-dbus-interfaces', 'phosphor_dbus_interfaces_dep'])
58
59phosphor_logging = dependency('phosphor-logging',
60    default_options: [ 'openpower-pel-extension=enabled' ],
61    fallback: ['phosphor-logging', 'phosphor_logging_dep'])
62
63sdbusplus = dependency('sdbusplus', fallback: [ 'sdbusplus', 'sdbusplus_dep' ])
64
65libvpdecc_src = files(
66    'vpdecc/vpdecc.c',
67    'vpdecc/vpdecc_support.c'
68)
69
70libvpdecc = shared_library(
71    'vpdecc',
72    libvpdecc_src,
73    version: meson.project_version(),
74    install: true,
75)
76
77compiler = meson.get_compiler('cpp')
78python = find_program('python3', required:true)
79
80if compiler.has_header('CLI/CLI.hpp')
81    CLI11_dep = declare_dependency()
82else
83    CLI11_dep = dependency('CLI11')
84endif
85
86if not build_tests.disabled()
87    subdir('test')
88endif
89
90configure_file(output: 'config.h',
91                       configuration :{
92                       'INVENTORY_JSON_DEFAULT': '"'+get_option('INVENTORY_JSON_DEFAULT')+'"',
93                       'VPD_FILES_PATH': '"'+get_option('VPD_FILES_PATH')+'"',
94                       'INVENTORY_PATH': '"'+get_option('INVENTORY_PATH')+'"',
95                       'IPZ_INTERFACE': '"'+get_option('IPZ_INTERFACE')+'"',
96                       'INVENTORY_MANAGER_SERVICE': '"'+get_option('INVENTORY_MANAGER_SERVICE')+'"',
97                       'BUSNAME' : '"' + get_option('BUSNAME') + '"',
98                       'OBJPATH' : '"' + get_option('OBJPATH') + '"',
99                       'IFACE' : '"' + get_option('IFACE') + '"',
100                       'POWER_SUPPLY_TYPE_INTERFACE' : '"'+get_option('POWER_SUPPLY_TYPE_INTERFACE')+'"',
101                       'INVENTORY_MANAGER_CACHE' : '"'+get_option('INVENTORY_MANAGER_CACHE')+'"',
102                       'INVENTORY_JSON_SYM_LINK': '"'+get_option('INVENTORY_JSON_SYM_LINK')+'"',
103                       'DBUS_PROP_JSON': '"'+get_option('DBUS_PROP_JSON')+'"',
104                       'SYSTEM_JSON' : '"'+get_option('SYSTEM_JSON')+'"',
105                       'BAD_VPD_DIR': '"'+get_option('BAD_VPD_DIR')+'"',
106                       'FAN_INTERFACE': '"'+get_option('FAN_INTERFACE')+'"'
107                       }
108  )
109
110common_SOURCES =['common_utility.cpp',
111'vpd-parser/parser_factory.cpp',
112                 'vpd-parser/memory_vpd_parser.cpp',
113                 'vpd-parser/isdimm_vpd_parser.cpp',
114                 'vpd-parser/keyword_vpd_parser.cpp',
115                 'vpd-parser/ipz_parser.cpp', 'impl.cpp', 'ibm_vpd_utils.cpp',
116]
117
118if get_option('ibm-parser').allowed()
119        libgpiodcxx = dependency(
120            'libgpiodcxx',
121            default_options: ['bindings=cxx'],
122        )
123        ibm_read_vpd_SOURCES = ['ibm_vpd_app.cpp',
124                                'vpd-manager/editor_impl.cpp',
125                               ]+common_SOURCES
126
127        vpd_tool_INCLUDE = include_directories('vpd-parser/', 'vpd-manager')
128
129        ibm_vpd_exe = executable(
130                                'ibm-read-vpd',
131                                ibm_read_vpd_SOURCES,
132                                dependencies: [
133                                        sdbusplus,
134                                        phosphor_logging,
135                                        libgpiodcxx,
136                                        nlohmann_json_dep,
137                                        CLI11_dep,
138                                ],
139                                link_with : libvpdecc,
140                                include_directories : vpd_tool_INCLUDE,
141                                install: true,
142                                cpp_args : '-DIPZ_PARSER'
143                            )
144
145        vpd_tool_SOURCES = ['vpd_tool.cpp',
146                            'vpd_tool_impl.cpp',
147                            'vpd-manager/editor_impl.cpp',
148                           ]+common_SOURCES
149
150
151        vpd_tool_exe = executable(
152                                 'vpd-tool',
153                                 vpd_tool_SOURCES,
154                                 dependencies: [
155                                   CLI11_dep,
156                                   libgpiodcxx,
157                                   nlohmann_json_dep,
158                                   phosphor_logging,
159                                   sdbusplus,
160                                   ],
161                                 link_with : libvpdecc,
162                                 install: true,
163                                 include_directories : vpd_tool_INCLUDE,
164                                 cpp_args : '-DIPZ_PARSER'
165                                 )
166if get_option('vpd-manager').allowed()
167    subdir('vpd-manager')
168endif
169
170systemd_system_unit_dir = dependency('systemd').get_variable(
171        'systemdsystemunitdir')
172
173udev_dir = dependency('udev').get_variable(
174        'udev_dir')
175
176rules = ['rules/70-ibm-vpd-parser.rules']
177
178install_data(rules, install_mode: 'rw-r--r--', install_dir: udev_dir/'rules.d')
179
180services = ['service_files/system-vpd.service',
181            'service_files/ibm-vpd-parser@.service',
182            'service_files/com.ibm.VPD.Manager.service',
183            'service_files/wait-vpd-parsers.service',
184            'service_files/ibm-isdimm-vpd-parser@.service',
185            'service_files/ibm-spi-vpd-parser@.service']
186
187install_data(services, install_dir: systemd_system_unit_dir)
188
189scripts = ['scripts/wait-vpd-parsers.sh']
190
191install_data(scripts,
192    install_mode: 'rwxr-xr-x',
193    install_dir: get_option('bindir'))
194
195package_datadir = join_paths('share', 'vpd')
196install_subdir('config/ibm/', install_mode: 'rwxr-xr-x', install_dir: package_datadir, strip_directory: true)
197
198else
199        FRUGEN = '$srcdir/extra-properties.py -e' + get_option('FRU_YAML')
200        PROPGEN = '$srcdir/extra-properties.py -e' + get_option('PROP_YAML')
201
202        src_dir = meson.project_source_root()
203        FRU_GEN_SCRIPT = src_dir + '/writefru.py'
204        FRU_GEN_SCRIPT_FILES = src_dir + '/writefru.yaml'
205
206        PROP_GEN_SCRIPT = src_dir + '/extra-properties.py'
207        PROP_GEN_SCRIPT_FILES = src_dir + '/extra-properties-example.yaml'
208
209        writefru_hpp = custom_target('writefru.hpp',
210                                     command:[python,
211                                              FRU_GEN_SCRIPT,
212                                              '-i',
213                                              get_option('FRU_YAML')
214                                     ],
215                                     depend_files :['writefru.mako.hpp',
216                                                    'writefru.py',
217                                                    get_option('FRU_YAML')
218                                     ],
219                                     output:'writefru.hpp'
220        )
221
222        extra_properties_gen_hpp = custom_target(
223                                        'extra-properties-gen.hpp',
224                                        command:[
225                                                python,
226                                                PROP_GEN_SCRIPT,
227                                                '-e',
228                                                get_option('PROP_YAML')
229                                        ],
230                                        depend_files : ['extra-properties.mako.hpp',
231                                                        'extra-properties.py',
232                                                        get_option('PROP_YAML')
233                                        ],
234                                        output:'extra-properties-gen.hpp'
235        )
236
237        openpower_read_vpd_SOURCES = ['app.cpp',
238                                      'args.cpp',
239                                      'impl.cpp',
240                                      'vpd-parser/ipz_parser.cpp',
241                                      'write.cpp',
242                                      'common_utility.cpp',
243                                      writefru_hpp,
244                                      extra_properties_gen_hpp
245        ]
246
247        openpower_read_vpd_exe= executable(
248                'openpower-read-vpd',
249                openpower_read_vpd_SOURCES,
250                dependencies: [
251                        sdbusplus,
252                        phosphor_logging,
253                        nlohmann_json_dep,
254                ],
255                include_directories : 'vpd-parser/',
256                install: true,
257        )
258endif
259