1project(
2     'openpower-vpd-parser',
3     'c',
4     'cpp',
5     default_options: [
6       'warning_level=3',
7       'werror=true',
8       'cpp_std=c++17',
9       'buildtype=debugoptimized'
10     ],
11     version: '1.0'
12)
13
14build_tests = get_option('tests')
15
16add_global_arguments('-Wno-psabi', language : ['c', 'cpp'])
17
18phosphor_dbus_interfaces = dependency('phosphor-dbus-interfaces',
19    default_options: [ 'data_com_ibm=true', 'data_org_open_power=true' ],
20    fallback: ['phosphor-dbus-interfaces', 'phosphor_dbus_interfaces_dep'])
21
22phosphor_logging = dependency('phosphor-logging',
23    default_options: [ 'openpower-pel-extension=enabled' ],
24    fallback: ['phosphor-logging', 'phosphor_logging_dep'])
25
26sdbusplus = dependency('sdbusplus', fallback: [ 'sdbusplus', 'sdbusplus_dep' ])
27
28compiler = meson.get_compiler('cpp')
29python = find_program('python3', required:true)
30
31compiler.has_header('CLI/CLI.hpp')
32compiler.has_header('nlohmann/json.hpp')
33
34# Disable FORTIFY_SOURCE when compiling with no optimization
35if(get_option('optimization') == '0')
36  add_project_arguments('-U_FORTIFY_SOURCE',language:['cpp','c'])
37  message('Disabling FORTIFY_SOURCE as optimization is set to 0')
38endif
39
40configure_file(output: 'config.h',
41                       configuration :{
42                       'INVENTORY_JSON_DEFAULT': '"'+get_option('INVENTORY_JSON_DEFAULT')+'"',
43                       'VPD_FILES_PATH': '"'+get_option('VPD_FILES_PATH')+'"',
44                       'INVENTORY_PATH': '"'+get_option('INVENTORY_PATH')+'"',
45                       'IPZ_INTERFACE': '"'+get_option('IPZ_INTERFACE')+'"',
46                       'INVENTORY_MANAGER_SERVICE': '"'+get_option('INVENTORY_MANAGER_SERVICE')+'"',
47                       'BUSNAME' : '"' + get_option('BUSNAME') + '"',
48                       'OBJPATH' : '"' + get_option('OBJPATH') + '"',
49                       'IFACE' : '"' + get_option('IFACE') + '"',
50                       'OBJECT_MAPPER_SERVICE' : '"'+get_option('OBJECT_MAPPER_SERVICE')+'"',
51                       'OBJECT_MAPPER_OBJECT' : '"'+get_option('OBJECT_MAPPER_OBJECT')+'"',
52                       'POWER_SUPPLY_TYPE_INTERFACE' : '"'+get_option('POWER_SUPPLY_TYPE_INTERFACE')+'"',
53                       'INVENTORY_MANAGER_CACHE' : '"'+get_option('INVENTORY_MANAGER_CACHE')+'"',
54                       'INVENTORY_JSON_SYM_LINK': '"'+get_option('INVENTORY_JSON_SYM_LINK')+'"',
55                       'INVENTORY_JSON_2U': '"'+get_option('INVENTORY_JSON_2U')+'"',
56                       'INVENTORY_JSON_4U': '"'+get_option('INVENTORY_JSON_4U')+'"',
57                       'INVENTORY_JSON_EVEREST': '"'+get_option('INVENTORY_JSON_EVEREST')+'"',
58                       'DBUS_PROP_JSON': '"'+get_option('DBUS_PROP_JSON')+'"',
59                       'SYSTEM_JSON' : '"'+get_option('SYSTEM_JSON')+'"',
60                       'BAD_VPD_DIR': '"'+get_option('BAD_VPD_DIR')+'"',
61                       'FAN_INTERFACE': '"'+get_option('FAN_INTERFACE')+'"'
62                       }
63  )
64
65common_SOURCES =['common_utility.cpp',
66'vpd-parser/parser_factory.cpp',
67                 'vpd-parser/memory_vpd_parser.cpp',
68                 'vpd-parser/keyword_vpd_parser.cpp',
69                 'vpd-parser/ipz_parser.cpp', 'impl.cpp', 'ibm_vpd_utils.cpp',
70                 'vpdecc/vpdecc.c', 'vpdecc/vpdecc_support.c'
71]
72
73if get_option('ibm-parser').enabled()
74        libgpiodcxx = dependency('libgpiodcxx')
75        ibm_read_vpd_SOURCES = ['ibm_vpd_app.cpp'
76                               ]+common_SOURCES
77
78        ibm_vpd_exe = executable(
79                                'ibm-read-vpd',
80                                ibm_read_vpd_SOURCES,
81                                dependencies: [
82                                        sdbusplus,
83                                        phosphor_logging,
84                                        libgpiodcxx,
85                                ],
86                                include_directories : 'vpd-parser/',
87                                install: true,
88                                cpp_args : '-DIPZ_PARSER'
89                            )
90
91        vpd_tool_SOURCES = ['vpd_tool.cpp',
92                            'vpd_tool_impl.cpp',
93                            'vpd-manager/editor_impl.cpp',
94                           ]+common_SOURCES
95
96        vpd_tool_INCLUDE = include_directories('vpd-parser/', 'vpd-manager')
97
98        vpd_tool_exe = executable(
99                                 'vpd-tool',
100                                 vpd_tool_SOURCES,
101                                 dependencies: [
102                                   sdbusplus
103                                   ],
104                                 install: true,
105                                 include_directories : vpd_tool_INCLUDE
106                                 )
107if get_option('vpd-manager').enabled()
108    subdir('vpd-manager')
109endif
110
111else
112        FRUGEN = '$srcdir/extra-properties.py -e' + get_option('FRU_YAML')
113        PROPGEN = '$srcdir/extra-properties.py -e' + get_option('PROP_YAML')
114
115        src_dir = meson.source_root()
116        FRU_GEN_SCRIPT = src_dir + '/writefru.py'
117        FRU_GEN_SCRIPT_FILES = src_dir + '/writefru.yaml'
118
119        PROP_GEN_SCRIPT = src_dir + '/extra-properties.py'
120        PROP_GEN_SCRIPT_FILES = src_dir + '/extra-properties-example.yaml'
121
122        writefru_hpp = custom_target('writefru.hpp',
123                                     command:[python,
124                                              FRU_GEN_SCRIPT,
125                                              '-i',
126                                              get_option('FRU_YAML')
127                                     ],
128                                     depend_files :['writefru.mako.hpp',
129                                                    'writefru.py',
130                                                    get_option('FRU_YAML')
131                                     ],
132                                     output:'writefru.hpp'
133        )
134
135        extra_properties_gen_hpp = custom_target(
136                                        'extra-properties-gen.hpp',
137                                        command:[
138                                                python,
139                                                PROP_GEN_SCRIPT,
140                                                '-e',
141                                                get_option('PROP_YAML')
142                                        ],
143                                        depend_files : ['extra-properties.mako.hpp',
144                                                        'extra-properties.py',
145                                                        get_option('PROP_YAML')
146                                        ],
147                                        output:'extra-properties-gen.hpp'
148        )
149
150        openpower_read_vpd_SOURCES = ['app.cpp',
151                                      'args.cpp',
152                                      'impl.cpp',
153                                      'vpd-parser/ipz_parser.cpp',
154                                      'write.cpp',
155                                      'common_utility.cpp',
156                                      writefru_hpp,
157                                      extra_properties_gen_hpp
158        ]
159
160        openpower_read_vpd_exe= executable(
161                'openpower-read-vpd',
162                openpower_read_vpd_SOURCES,
163                dependencies: [
164                        sdbusplus,
165                        phosphor_logging,
166                ],
167                include_directories : 'vpd-parser/',
168                install: true,
169        )
170endif
171subdir('test')
172