1project(
2  'phosphor-host-ipmid',
3  'cpp',
4  version: '0.1',
5  meson_version: '>=1.1.1',
6  default_options: [
7    'werror=true',
8    'warning_level=3',
9    'cpp_std=c++23',
10  ])
11
12# Setting up config data
13conf_data = configuration_data()
14
15# The name of the callout's forward association
16conf_data.set_quoted('CALLOUT_FWD_ASSOCIATION', 'callout')
17conf_data.set_quoted('BOARD_SENSOR', get_option('board-sensor'))
18conf_data.set_quoted('SYSTEM_SENSOR', get_option('system-sensor'))
19conf_data.set('IPMI_SMS_ATN_ACK_TIMEOUT_SECS', get_option('ipmi-sms-atn-ack-timeout-secs'))
20
21# Soft Power off related.
22if not get_option('softoff').disabled()
23  conf_data.set_quoted('SOFTOFF_BUSNAME', get_option('softoff-busname'))
24  conf_data.set_quoted('SOFTOFF_OBJPATH', get_option('softoff-objpath'))
25  conf_data.set('IPMI_HOST_SHUTDOWN_COMPLETE_TIMEOUT_SECS', get_option('ipmi-host-shutdown-complete-timeout-secs'))
26  conf_data.set_quoted('HOST_INBAND_REQUEST_DIR', get_option('host-inband-request-dir'))
27  conf_data.set_quoted('HOST_INBAND_REQUEST_FILE', get_option('host-inband-request-file'))
28endif
29
30conf_data.set_quoted('CONTROL_HOST_BUSNAME', get_option('control-host-busname'))
31conf_data.set_quoted('CONTROL_HOST_OBJ_MGR', get_option('control-host-obj-mgr'))
32conf_data.set_quoted('HOST_NAME', get_option('host-name'))
33conf_data.set_quoted('POWER_READING_SENSOR', get_option('power-reading-sensor'))
34conf_data.set_quoted('HOST_IPMI_LIB_PATH', get_option('host-ipmi-lib-path'))
35conf_data.set_quoted('FW_VER_REGEX', get_option('fw-ver-regex'))
36
37if get_option('shortname-remove-suffix').enabled()
38  conf_data.set_quoted('SHORTNAME_REMOVE_SUFFIX', '1')
39endif
40if get_option('shortname-replace-words').enabled()
41  conf_data.set_quoted('SHORTNAME_REPLACE_WORDS', '1')
42endif
43if get_option('open-power').allowed()
44  conf_data.set_quoted('OPEN_POWER_SUPPORT', '1')
45endif
46
47matches_map = get_option('matches-map')
48conf_data.set('MAJOR_MATCH_INDEX', matches_map[0])
49conf_data.set('MINOR_MATCH_INDEX', matches_map[1])
50conf_data.set('AUX_0_MATCH_INDEX', matches_map[2])
51conf_data.set('AUX_1_MATCH_INDEX', matches_map[3])
52conf_data.set('AUX_2_MATCH_INDEX', matches_map[4])
53conf_data.set('AUX_3_MATCH_INDEX', matches_map[5])
54
55conf_h = configure_file(
56  output: 'config.h',
57  configuration: conf_data)
58
59root = meson.current_source_dir()
60root_inc = include_directories('.', 'include')
61
62# Project Arguments
63cpp = meson.get_compiler('cpp')
64add_project_arguments(
65  cpp.get_supported_arguments([
66    '-DBOOST_ERROR_CODE_HEADER_ONLY',
67    '-DBOOST_SYSTEM_NO_DEPRECATED',
68    '-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
69    '-DBOOST_ASIO_DISABLE_THREADS',
70    '-DBOOST_ALL_NO_LIB',
71  ]),
72  language : 'cpp')
73
74if not get_option('get-dbus-active-software').disabled()
75  add_project_arguments(
76    cpp.get_supported_arguments([
77      '-DGET_DBUS_ACTIVE_SOFTWARE',
78    ]),
79    language : 'cpp')
80endif
81
82feature_map = {
83  'boot-flag-safe-mode-support': '-DENABLE_BOOT_FLAG_SAFE_MODE_SUPPORT',
84  'i2c-whitelist-check'        : '-DENABLE_I2C_WHITELIST_CHECK',
85  'update-functional-on-fail'  : '-DUPDATE_FUNCTIONAL_ON_FAIL',
86  'dynamic-sensors'            : '-DFEATURE_DYNAMIC_SENSORS',
87  'dynamic-sensors-write'      : '-DFEATURE_DYNAMIC_SENSORS_WRITE',
88  'entity-manager-decorators'  : '-DUSING_ENTITY_MANAGER_DECORATORS',
89  'hybrid-sensors'             : '-DFEATURE_HYBRID_SENSORS',
90  'sensors-cache'              : '-DFEATURE_SENSORS_CACHE',
91  'dynamic-storages-only'      : '-DFEATURE_DYNAMIC_STORAGES_ONLY',
92}
93
94foreach option_key, option_value : feature_map
95  if(get_option(option_key).enabled())
96    summary(option_key,option_value, section : 'Enabled Features')
97    add_project_arguments(option_value,language:'cpp')
98  endif
99endforeach
100
101add_project_arguments(
102  cpp.get_supported_arguments([
103    '-Wno-psabi',
104    '-Wno-missing-field-initializers',
105    '-Wno-pedantic',
106    '-Wno-non-virtual-dtor'
107  ]),
108  language: 'cpp')
109
110# Dependencies
111phosphor_logging_dep = dependency('phosphor-logging')
112phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
113sdeventplus_dep = dependency('sdeventplus')
114systemd = dependency('systemd')
115crypto = dependency('libcrypto', version : '>=1.0.2g')
116pam = cpp.find_library('pam', required: true)
117mapper = dependency('libmapper')
118boost_coroutine = cpp.find_library('boost_coroutine', required: true)
119sdbusplus_dep = dependency('sdbusplus')
120
121if cpp.has_header_symbol(
122        'nlohmann/json.hpp',
123        'nlohmann::json::string_t',
124        required:false)
125    nlohmann_json_dep = declare_dependency()
126else
127    nlohmann_json_dep = dependency('nlohmann-json')
128endif
129
130generated_src = []
131
132# Subfolders
133subdir('libipmid')
134subdir('include')
135subdir('user_channel')
136subdir('scripts')
137
138if not get_option('softoff').disabled()
139  subdir('xyz/openbmc_project/Ipmi/Internal/SoftPowerOff')
140  subdir('softoff')
141endif
142
143# whitelist
144if not get_option('ipmi-whitelist').disabled()
145  generate_whitelist_script = files('generate_whitelist_create.sh')
146
147  whitelist_conf = get_option('whitelist-conf')
148  ipmiwhitelist = run_command( \
149    'bash', \
150    generate_whitelist_script, \
151    whitelist_conf)
152
153  whitelist_pre = declare_dependency(
154    include_directories: root_inc,
155    dependencies: [
156      crypto,
157      ipmid_dep,
158      phosphor_dbus_interfaces_dep,
159      phosphor_logging_dep,
160      sdbusplus_dep,
161    ],
162  )
163
164  whitelist_lib = library(
165    'whitelist',
166    'whitelist-filter.cpp',
167    'ipmiwhitelist.cpp',
168    implicit_include_directories: false,
169    dependencies: whitelist_pre,
170    version: meson.project_version(),
171    override_options: ['b_lundef=false'],
172    install: true,
173    install_dir: get_option('libdir') / 'ipmid-providers')
174endif
175
176# libsysintfcmds
177sysintfcmds_pre = declare_dependency(
178  include_directories: root_inc,
179  dependencies: [
180    channellayer_dep,
181    crypto,
182    mapper,
183    phosphor_dbus_interfaces_dep,
184    phosphor_logging_dep,
185    sdbusplus_dep,
186    ipmid_dep,
187  ])
188
189sysintfcmds_lib = library(
190  'sysintfcmds',
191  'systemintfcmds.cpp',
192  'host-interface.cpp',
193  implicit_include_directories: false,
194  dependencies: sysintfcmds_pre,
195  version: meson.project_version(),
196  override_options: ['b_lundef=false'],
197  install: true,
198  install_dir: get_option('libdir') / 'ipmid-providers')
199
200# ipmid
201ipmid_pre = [
202  sdbusplus_dep,
203  phosphor_logging_dep,
204  phosphor_dbus_interfaces_dep,
205  boost_coroutine,
206  crypto,
207  ipmid_dep,
208  channellayer_dep,
209  mapper,
210]
211
212transportoem_src = []
213if not get_option('transport-oem').disabled()
214  transportoem_src = ['transporthandler_oem.cpp']
215endif
216
217storage_cmds_src = []
218if get_option('dynamic-sensors').disabled() and not get_option('dynamic-storages-only').disabled()
219  storage_cmds_src = ['dbus-sdr/storagecommands.cpp', 'dbus-sdr/sdrutils.cpp']
220endif
221
222openpower_cmds_src = []
223if get_option('open-power').allowed()
224  openpower_cmds_src = [ 'storageaddsel.cpp' ]
225endif
226
227libipmi20_src = [
228  'app/channel.cpp',
229  'app/watchdog.cpp',
230  'app/watchdog_service.cpp',
231  'apphandler.cpp',
232  'sys_info_param.cpp',
233  'sensorhandler.cpp',
234  'storagehandler.cpp',
235  'chassishandler.cpp',
236  'dcmihandler.cpp',
237  'ipmisensor.cpp',
238  'transporthandler.cpp',
239  'globalhandler.cpp',
240  'groupext.cpp',
241  'selutility.cpp',
242  'ipmi_fru_info_area.cpp',
243  'read_fru_data.cpp',
244  'sensordatahandler.cpp',
245  'user_channel/channelcommands.cpp',
246  generated_src,
247  transportoem_src,
248  storage_cmds_src,
249  openpower_cmds_src,
250  conf_h,
251]
252
253ipmi20_lib = library(
254  'ipmi20',
255  libipmi20_src,
256  dependencies: [ipmid_pre, nlohmann_json_dep],
257  include_directories: root_inc,
258  install: true,
259  install_dir: get_option('libdir') / 'ipmid-providers',
260  version: meson.project_version(),
261  override_options: ['b_lundef=false'])
262
263libipmi20_dep = declare_dependency(
264  dependencies: ipmid_pre,
265  include_directories: root_inc,
266  link_with: ipmi20_lib)
267
268# ipmid binary
269executable(
270  'ipmid',
271  'ipmid-new.cpp',
272  'host-cmd-manager.cpp',
273  'settings.cpp',
274  implicit_include_directories: false,
275  dependencies: [libipmi20_dep],
276  include_directories: root_inc,
277  export_dynamic: true,
278  install: true,
279  install_dir: get_option('bindir'))
280
281# Dynamic Sensor Stack
282subdir('dbus-sdr')
283
284if not get_option('dynamic-sensors').disabled() or not get_option('tests').disabled()
285  library(
286    'dynamiccmds',
287    dbus_sdr_src,
288    implicit_include_directories: false,
289    dependencies: dbus_sdr_pre,
290    version: meson.project_version(),
291    override_options: ['b_lundef=false'],
292    install: true,
293    install_dir: get_option('libdir') / 'ipmid-providers')
294endif
295
296if not get_option('tests').disabled()
297  subdir('test')
298endif
299
300install_subdir(
301  'user_channel',
302  install_dir: get_option('includedir'),
303  strip_directory: false,
304  exclude_files: '*.cpp')
305