1project(
2  'phosphor-ipmi-flash',
3  'cpp',
4  version: '0.1',
5  meson_version: '>=0.58.0',
6  default_options: [
7    'cpp_std=c++20',
8    'warning_level=3',
9    'werror=true',
10  ])
11
12root_inc = include_directories('.')
13
14# Setting up config data
15conf_data = configuration_data()
16conf_data.set_quoted('STATIC_HANDLER_STAGED_NAME', get_option('static-handler-staged-name'))
17conf_data.set_quoted('PREPARATION_DBUS_SERVICE', get_option('preparation-dbus-service'))
18conf_data.set_quoted('VERIFY_DBUS_SERVICE', get_option('verify-dbus-service'))
19conf_data.set_quoted('UPDATE_DBUS_SERVICE', get_option('update-dbus-service'))
20conf_data.set_quoted('BIOS_STAGED_NAME', get_option('bios-staged-name'))
21conf_data.set_quoted('PREPARATION_BIOS_TARGET', get_option('preparation-bios-target'))
22conf_data.set_quoted('VERIFY_BIOS_TARGET', get_option('verify-bios-target'))
23conf_data.set_quoted('UPDATE_BIOS_TARGET', get_option('update-bios-target'))
24
25conf_data.set_quoted('TARBALL_STAGED_NAME', get_option('tarball-staged-name'))
26conf_data.set_quoted('HASH_FILENAME', get_option('hash-filename'))
27conf_data.set_quoted('VERIFY_STATUS_FILENAME', get_option('verify-status-filename'))
28conf_data.set_quoted('UPDATE_STATUS_FILENAME', get_option('update-status-filename'))
29conf_data.set_quoted('BIOS_VERIFY_STATUS_FILENAME', get_option('bios-verify-status-filename'))
30conf_data.set('MAPPED_ADDRESS', get_option('mapped-address'))
31
32
33conf_h = configure_file(
34  output: 'config.h',
35  configuration: conf_data)
36
37# Setup for the test config
38if not get_option('tests').disabled()
39  add_project_arguments('-DENABLE_STATIC_LAYOUT', language: 'cpp')
40  add_project_arguments('-DENABLE_TARBALL_UBI', language: 'cpp')
41  add_project_arguments('-DASPEED_P2A', language: 'cpp')
42  add_project_arguments('-DENABLE_PCI_BRIDGE', language: 'cpp')
43  add_project_arguments('-DASPEED_LPC', language: 'cpp')
44  add_project_arguments('-DNUVOTON_LPC', language: 'cpp')
45  add_project_arguments('-DENABLE_LPC_BRIDGE', language: 'cpp')
46  add_project_arguments('-DENABLE_HOST_BIOS', language: 'cpp')
47endif
48
49if get_option('lpc-type') != 'none'
50  add_project_arguments('-DENABLE_LPC_BRIDGE', language: 'cpp')
51endif
52
53# Enable LPC and PCI for tests only.
54assert(
55  not get_option('tests').disabled() \
56    or get_option('lpc-type') == 'none' \
57    or get_option('p2a-type') == 'none',
58  'Invalid configuration enabling both PCI and LPC.')
59
60if get_option('p2a-type') != 'none'
61  add_project_arguments('-DENABLE_PCI_BRIDGE', language: 'cpp')
62endif
63
64feature_map = {
65  'host-bios'        : '-DENABLE_HOST_BIOS',
66  'ppc'              : '-DENABLE_PPC',
67  'reboot-update'    : '-DENABLE_REBOOT_UPDATE',
68  'update-status'    : '-DENABLE_UPDATE_STATUS',
69  'net-bridge'       : '-DENABLE_NET_BRIDGE',
70}
71
72# Get the options status and build a project summary to show which flags are
73# being enabled during the configuration time.
74
75foreach option_key, option_value : feature_map
76  if get_option(option_key)
77    add_project_arguments(option_value, language: 'cpp')
78    summary(option_key, option_value, section : 'Enabled Features')
79  endif
80endforeach
81
82
83update_type_combo_map = {
84  'static-layout'    : '-DENABLE_STATIC_LAYOUT',
85  'tarball-ubi'      : '-DENABLE_TARBALL_UBI',
86}
87
88foreach option_key, option_value : update_type_combo_map
89  if get_option('update-type') == option_key
90    add_project_arguments(option_value, language: 'cpp')
91    summary(option_key, option_value, section : 'Enabled Firmware Update Features')
92  endif
93endforeach
94
95lpc_type_combo_map = {
96  'aspeed-lpc'       : '-DASPEED_LPC',
97  'nuvoton-lpc'      : '-DNUVOTON_LPC',
98}
99
100foreach option_key, option_value : lpc_type_combo_map
101  if get_option('lpc-type') == option_key
102    add_project_arguments(option_value, language: 'cpp')
103    summary(option_key, option_value, section : 'Enabled LPC Features')
104  endif
105endforeach
106
107pci_type_combo_map = {
108  'aspeed-p2a'       : '-DASPEED_P2A',
109  'nuvoton-p2a-vga'  : '-DNUVOTON_P2A_VGA',
110  'nuvoton-p2a-mbox' : '-DNUVOTON_P2A_MBOX',
111}
112
113foreach option_key, option_value : pci_type_combo_map
114  if get_option('p2a-type') == option_key
115    add_project_arguments(option_value, language: 'cpp')
116    summary(option_key, option_value, section : 'Enabled PCI Features')
117  endif
118endforeach
119
120
121sys_lib = static_library(
122  'sys',
123  'internal/sys.cpp',
124  implicit_include_directories: false)
125
126sys_dep = declare_dependency(
127  link_with: sys_lib)
128
129blobs_dep = dependency('phosphor-ipmi-blobs')
130
131cpp = meson.get_compiler('cpp')
132# Function2 might not have a pkg-config. It is header only so just make
133# sure we can access the needed symbols from the header.
134function2_dep = dependency('function2', required: false)
135has_function2 = cpp.has_header_symbol(
136  'function2/function2.hpp',
137  'fu2::unique_function',
138  dependencies: function2_dep,
139  required: false)
140if not has_function2
141  function2_opts = import('cmake').subproject_options()
142  function2_opts.add_cmake_defines({'BUILD_TESTING': 'OFF'})
143  function2_proj = import('cmake').subproject(
144    'function2',
145    options: function2_opts,
146    required: false)
147  assert(function2_proj.found(), 'function2 is required')
148  if function2_proj.found()
149    function2_dep = function2_proj.dependency('function2')
150  endif
151endif
152
153if cpp.has_header('nlohmann/json.hpp')
154    json_dep = declare_dependency()
155else
156    json_dep = dependency('nlohmann_json')
157endif
158
159if not get_option('tests').disabled()
160  gtest = dependency('gtest', main: true, disabler: true, required: false)
161  gmock = dependency('gmock', disabler: true, required: false)
162  if not gtest.found() or not gmock.found()
163    gtest_opt = import('cmake').subproject_options()
164    gtest_opt.append_compile_args('c++', ['-DCMAKE_CXX_FLAGS=-Wno-pedantic'])
165    gtest_proj = cmake.subproject('googletest', options: gtest_opt, required: false)
166    fmt_depj.dependency('fmt')
167
168    if gtest_proj.found()
169      gtest = declare_dependency(
170        dependencies: [
171          dependency('threads'),
172          gtest_proj.dependency('gtest'),
173          gtest_proj.dependency('gtest_main'),
174        ])
175      gmock = gtest_proj.dependency('gmock')
176    endif
177  endif
178endif
179
180
181if not get_option('bmc-blob-handler').disabled()
182  subdir('bmc')
183endif
184
185if not get_option('host-tool').disabled()
186  subdir('tools')
187endif
188
189if not get_option('cleanup-delete').disabled()
190  subdir('cleanup')
191endif
192