xref: /openbmc/openpower-vpd-parser/meson.build (revision 735dee9b9c2aa84aa43459002a67f56c47b0d69d)
1project(
2     'openpower-vpd-parser',
3     'c',
4     'cpp',
5     default_options: [
6       'warning_level=3',
7       'werror=true',
8       'cpp_std=c++20',
9       'buildtype=debugoptimized'
10     ],
11     version: '1.0',
12     meson_version: '>=0.57.0',
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').enabled(),
48                   'Googletest is required if tests are enabled')
49        endif
50    endif
51endif
52
53phosphor_dbus_interfaces = dependency('phosphor-dbus-interfaces',
54    default_options: [ 'data_com_ibm=true', 'data_org_open_power=true' ],
55    fallback: ['phosphor-dbus-interfaces', 'phosphor_dbus_interfaces_dep'])
56
57phosphor_logging = dependency('phosphor-logging',
58    default_options: [ 'openpower-pel-extension=enabled' ],
59    fallback: ['phosphor-logging', 'phosphor_logging_dep'])
60
61sdbusplus = dependency('sdbusplus', fallback: [ 'sdbusplus', 'sdbusplus_dep' ])
62
63if not build_tests.disabled()
64    subdir('test')
65endif
66
67compiler = meson.get_compiler('cpp')
68python = find_program('python3', required:true)
69
70compiler.has_header('CLI/CLI.hpp')
71compiler.has_header('nlohmann/json.hpp')
72
73configure_file(output: 'config.h',
74                       configuration :{
75                       'INVENTORY_JSON_DEFAULT': '"'+get_option('INVENTORY_JSON_DEFAULT')+'"',
76                       'VPD_FILES_PATH': '"'+get_option('VPD_FILES_PATH')+'"',
77                       'INVENTORY_PATH': '"'+get_option('INVENTORY_PATH')+'"',
78                       'IPZ_INTERFACE': '"'+get_option('IPZ_INTERFACE')+'"',
79                       'INVENTORY_MANAGER_SERVICE': '"'+get_option('INVENTORY_MANAGER_SERVICE')+'"',
80                       'BUSNAME' : '"' + get_option('BUSNAME') + '"',
81                       'OBJPATH' : '"' + get_option('OBJPATH') + '"',
82                       'IFACE' : '"' + get_option('IFACE') + '"',
83                       'OBJECT_MAPPER_SERVICE' : '"'+get_option('OBJECT_MAPPER_SERVICE')+'"',
84                       'OBJECT_MAPPER_OBJECT' : '"'+get_option('OBJECT_MAPPER_OBJECT')+'"',
85                       'POWER_SUPPLY_TYPE_INTERFACE' : '"'+get_option('POWER_SUPPLY_TYPE_INTERFACE')+'"',
86                       'INVENTORY_MANAGER_CACHE' : '"'+get_option('INVENTORY_MANAGER_CACHE')+'"',
87                       'INVENTORY_JSON_SYM_LINK': '"'+get_option('INVENTORY_JSON_SYM_LINK')+'"',
88                       'INVENTORY_JSON_2U': '"'+get_option('INVENTORY_JSON_2U')+'"',
89                       'INVENTORY_JSON_4U': '"'+get_option('INVENTORY_JSON_4U')+'"',
90                       'INVENTORY_JSON_EVEREST': '"'+get_option('INVENTORY_JSON_EVEREST')+'"',
91                       'DBUS_PROP_JSON': '"'+get_option('DBUS_PROP_JSON')+'"',
92                       'SYSTEM_JSON' : '"'+get_option('SYSTEM_JSON')+'"',
93                       'BAD_VPD_DIR': '"'+get_option('BAD_VPD_DIR')+'"',
94                       'FAN_INTERFACE': '"'+get_option('FAN_INTERFACE')+'"'
95                       }
96  )
97
98common_SOURCES =['common_utility.cpp',
99'vpd-parser/parser_factory.cpp',
100                 'vpd-parser/memory_vpd_parser.cpp',
101                 'vpd-parser/keyword_vpd_parser.cpp',
102                 'vpd-parser/ipz_parser.cpp', 'impl.cpp', 'ibm_vpd_utils.cpp',
103                 'vpdecc/vpdecc.c', 'vpdecc/vpdecc_support.c'
104]
105
106if get_option('ibm-parser').enabled()
107        libgpiodcxx = dependency('libgpiodcxx')
108        ibm_read_vpd_SOURCES = ['ibm_vpd_app.cpp'
109                               ]+common_SOURCES
110
111        ibm_vpd_exe = executable(
112                                'ibm-read-vpd',
113                                ibm_read_vpd_SOURCES,
114                                dependencies: [
115                                        sdbusplus,
116                                        phosphor_logging,
117                                        libgpiodcxx,
118                                ],
119                                include_directories : 'vpd-parser/',
120                                install: true,
121                                cpp_args : '-DIPZ_PARSER'
122                            )
123
124        vpd_tool_SOURCES = ['vpd_tool.cpp',
125                            'vpd_tool_impl.cpp',
126                            'vpd-manager/editor_impl.cpp',
127                           ]+common_SOURCES
128
129        vpd_tool_INCLUDE = include_directories('vpd-parser/', 'vpd-manager')
130
131        vpd_tool_exe = executable(
132                                 'vpd-tool',
133                                 vpd_tool_SOURCES,
134                                 dependencies: [
135                                   sdbusplus,
136                                   libgpiodcxx
137                                   ],
138                                 install: true,
139                                 include_directories : vpd_tool_INCLUDE
140                                 )
141if get_option('vpd-manager').enabled()
142    subdir('vpd-manager')
143endif
144
145else
146        FRUGEN = '$srcdir/extra-properties.py -e' + get_option('FRU_YAML')
147        PROPGEN = '$srcdir/extra-properties.py -e' + get_option('PROP_YAML')
148
149        src_dir = meson.source_root()
150        FRU_GEN_SCRIPT = src_dir + '/writefru.py'
151        FRU_GEN_SCRIPT_FILES = src_dir + '/writefru.yaml'
152
153        PROP_GEN_SCRIPT = src_dir + '/extra-properties.py'
154        PROP_GEN_SCRIPT_FILES = src_dir + '/extra-properties-example.yaml'
155
156        writefru_hpp = custom_target('writefru.hpp',
157                                     command:[python,
158                                              FRU_GEN_SCRIPT,
159                                              '-i',
160                                              get_option('FRU_YAML')
161                                     ],
162                                     depend_files :['writefru.mako.hpp',
163                                                    'writefru.py',
164                                                    get_option('FRU_YAML')
165                                     ],
166                                     output:'writefru.hpp'
167        )
168
169        extra_properties_gen_hpp = custom_target(
170                                        'extra-properties-gen.hpp',
171                                        command:[
172                                                python,
173                                                PROP_GEN_SCRIPT,
174                                                '-e',
175                                                get_option('PROP_YAML')
176                                        ],
177                                        depend_files : ['extra-properties.mako.hpp',
178                                                        'extra-properties.py',
179                                                        get_option('PROP_YAML')
180                                        ],
181                                        output:'extra-properties-gen.hpp'
182        )
183
184        openpower_read_vpd_SOURCES = ['app.cpp',
185                                      'args.cpp',
186                                      'impl.cpp',
187                                      'vpd-parser/ipz_parser.cpp',
188                                      'write.cpp',
189                                      'common_utility.cpp',
190                                      writefru_hpp,
191                                      extra_properties_gen_hpp
192        ]
193
194        openpower_read_vpd_exe= executable(
195                'openpower-read-vpd',
196                openpower_read_vpd_SOURCES,
197                dependencies: [
198                        sdbusplus,
199                        phosphor_logging,
200                ],
201                include_directories : 'vpd-parser/',
202                install: true,
203        )
204endif
205