blob: 0bcf3661fb90c992dbd8d95237ec93703aef5506 [file] [log] [blame]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +05301project('bmcweb', 'cpp',
2 version : '1.0',
3 meson_version: '>=0.53.2',
4 default_options: [
5 'werror=true',
6 'warning_level=3',
7 'cpp_std=c++17',
8 'buildtype=debugoptimized',
9 'b_ndebug=if-release',
10 'b_lto=true',
Manojkiran Edacb2ed192021-02-15 08:30:43 +053011 'cpp_rtti=false',
12 'b_lto_mode=default',
13 'b_lto_threads=0'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053014 ])
15
16# Project related links
17
18project_pretty_name = 'bmcweb'
19project_url = 'https://github.com/openbmc/' + project_pretty_name
20project_issues_url = project_url + '/issues/new'
21summary('Issues',project_issues_url, section: 'Report Issues')
22
23# Validate the c++ Standard
24
25if get_option('cpp_std') != 'c++17'
26 error('This project requires c++17 support')
27endif
28
29# Get compiler and default build type
30
31cxx = meson.get_compiler('cpp')
32build = get_option('buildtype')
33optimization = get_option('optimization')
34summary('Build Type',build, section : 'Build Info')
35summary('Optimization',optimization, section : 'Build Info')
36
Ed Tanous5e34b672021-02-05 14:21:27 -080037
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053038# remove debug information for minsize buildtype
39if(get_option('buildtype') == 'minsize')
Ed Tanous5e34b672021-02-05 14:21:27 -080040 add_project_arguments(['-fdata-sections', '-ffunction-sections'], language : 'cpp')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053041 add_project_arguments('-DNDEBUG', language : 'cpp')
42endif
43
44# Disable lto when compiling with no optimization
45if(get_option('optimization') == '0')
46 add_project_arguments('-fno-lto', language: 'cpp')
47 message('Disabling lto & its supported features as optimization is disabled')
48endif
49
50# Include Directories
51
Ed Tanouscf2f9322021-09-22 15:34:41 -070052incdir = include_directories(
53 'include',
54 'redfish-core/include',
55 'redfish-core/lib',
56 'http'
57)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053058
59# Get the options and enable the respective features
60## create a MAP of "options : feature_flag"
61
62feature_map = {
Ed Tanouscf2f9322021-09-22 15:34:41 -070063 'insecure-disable-auth' : '-DBMCWEB_INSECURE_DISABLE_AUTHENTICATION',
64 'insecure-disable-csrf' : '-DBMCWEB_INSECURE_DISABLE_CSRF_PREVENTION',
65 'insecure-disable-ssl' : '-DBMCWEB_INSECURE_DISABLE_SSL',
66 'host-serial-socket' : '-DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET',
67 'ibm-management-console' : '-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE',
68 'google-api' : '-DBMCWEB_ENABLE_GOOGLE_API',
69 'kvm' : '-DBMCWEB_ENABLE_KVM' ,
70 'basic-auth' : '-DBMCWEB_ENABLE_BASIC_AUTHENTICATION',
71 'session-auth' : '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION',
72 'xtoken-auth' : '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION',
73 'cookie-auth' : '-DBMCWEB_ENABLE_COOKIE_AUTHENTICATION',
74 'mutual-tls-auth' : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION',
75 'pam' : '-DWEBSERVER_ENABLE_PAM',
76 'insecure-push-style-notification': '-DBMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING',
77 'redfish' : '-DBMCWEB_ENABLE_REDFISH',
78 'redfish-bmc-journal' : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL',
79 'redfish-cpu-log' : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG',
SpencerKubf888502021-07-22 14:57:02 +080080 'redfish-host-logger' : '-DBMCWEB_ENABLE_REDFISH_HOST_LOGGER',
Ed Tanouscf2f9322021-09-22 15:34:41 -070081 'redfish-dbus-log' : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES',
82 'redfish-provisioning-feature' : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE',
83 'redfish-dump-log' : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG',
84 'rest' : '-DBMCWEB_ENABLE_DBUS_REST',
85 'static-hosting' : '-DBMCWEB_ENABLE_STATIC_HOSTING',
86 'insecure-tftp-update' : '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE',
87 #'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY',
88 'vm-websocket' : '-DBMCWEB_ENABLE_VM_WEBSOCKET',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053089}
90
91# Get the options status and build a project summary to show which flags are
92# being enabled during the configuration time.
93
94foreach option_key,option_value : feature_map
95 if(get_option(option_key).enabled())
96 if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl')
97 if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled())
98 add_project_arguments(option_value,language:'cpp')
99 summary(option_key,option_value, section : 'Enabled Features')
100 endif
101 else
102 summary(option_key,option_value, section : 'Enabled Features')
103 add_project_arguments(option_value,language:'cpp')
104 endif
105 else
106 if(option_key == 'insecure-disable-ssl')
107 summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features')
108 add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp')
109 endif
110 endif
111endforeach
112
113if(get_option('tests').enabled())
114 summary('unittest','NA', section : 'Enabled Features')
115endif
116
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530117# Add compiler arguments
118
119# -Wpedantic, -Wextra comes by default with warning level
120add_project_arguments(
121 cxx.get_supported_arguments([
122 '-Wold-style-cast',
123 '-Wcast-align',
124 '-Wunused',
125 '-Woverloaded-virtual',
126 '-Wconversion',
127 '-Wsign-conversion',
128 '-Wno-attributes',
129 ]),
130 language: 'cpp'
131)
132
133if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
134add_project_arguments(
135 cxx.get_supported_arguments([
136 '-Weverything',
137 '-Wno-c++98-compat',
138 '-Wno-c++98-compat-pedantic',
139 '-Wno-global-constructors',
140 '-Wno-exit-time-destructors',
141 '-Wno-shadow',
142 '-Wno-used-but-marked-unused',
143 '-Wno-documentation-unknown-command',
144 '-Wno-weak-vtables',
145 '-Wno-documentation',
146 '-Wno-padded',
147 '-Wunused-parameter',
148 '-Wcovered-switch-default',
149 '-Wcomma',
150 '-Wextra-semi',
151 '-Wzero-as-null-pointer-constant',
152 '-Wswitch-enum',
153 '-Wnull-dereference',
154 '-Wdouble-promotion',
Ed Tanousd32c4fa2021-09-14 13:16:51 -0700155 '-Wno-newline-eof',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530156 '-Wformat=2',
157 ]),
158 language:'cpp')
159endif
160
161# if compiler is gnu-gcc , and version is > 8.0 then we add few more
162# compiler arguments , we know that will pass
163
164if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
165
166 ## remove once bmcweb/issues/147 is fixed
167 add_global_link_arguments('-Wno-stringop-overflow',language:['c','cpp'])
168 add_project_arguments('-Wno-stringop-overflow',language:['c','cpp'])
169
170 add_project_arguments(
171 cxx.get_supported_arguments([
172 '-Wduplicated-cond',
173 '-Wduplicated-branches',
174 '-Wlogical-op',
175 '-Wunused-parameter',
176 '-Wnull-dereference',
177 '-Wdouble-promotion',
178 '-Wformat=2',
179 ]),
180 language:'cpp')
Ed Tanousc66403c2021-09-22 15:28:57 -0700181endif
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530182
Ed Tanousc66403c2021-09-22 15:28:57 -0700183if (get_option('buildtype') != 'plain')
184 if (get_option('b_lto') == true and get_option('optimization')!='0')
185 # Reduce the binary size by removing unnecessary
186 # dynamic symbol table entries
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530187
Ed Tanousc66403c2021-09-22 15:28:57 -0700188 add_project_arguments(
189 cxx.get_supported_arguments([
190 '-fno-fat-lto-objects',
191 '-fvisibility=hidden',
192 '-fvisibility-inlines-hidden'
193 ]),
194 language: 'cpp')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530195
Ed Tanousc66403c2021-09-22 15:28:57 -0700196 if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
197 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
George Liue8204932021-02-01 14:42:49 +0800198 endif
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530199 endif
200endif
201
Ed Tanousc66403c2021-09-22 15:28:57 -0700202if( get_option('bmcweb-logging').enabled() or \
203 get_option('buildtype').startswith('debug'))
204 add_project_arguments([
205 '-DBMCWEB_ENABLE_LOGGING',
206 '-DBMCWEB_ENABLE_DEBUG'
207 ],
208 language : 'cpp')
209
210 summary({'debug' :'-DBMCWEB_ENABLE_DEBUG',
211 'logging' : '-DBMCWEB_ENABLE_LOGGING',
212 },section : 'Enabled Features')
213endif
214
Ed Tanousc66403c2021-09-22 15:28:57 -0700215if( get_option('redfish-allow-deprecated-power-thermal').enabled())
216 add_project_arguments([
217 '-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL'
218 ],
219 language : 'cpp')
220
221 summary({'power-thermal' :'-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL'
222 },section : 'Enabled Features')
223endif
224
225if( get_option('redfish-new-powersubsystem-thermalsubsystem').enabled())
226 add_project_arguments([
227 '-DBMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM'
228 ],
229 language : 'cpp')
230
231 summary({'new-powersubsystem-thermalsubsystem' :'-DBMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM'
232 },section : 'Enabled Features')
233endif
234
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530235# Set Compiler Security flags
236
237security_flags = [
Ed Tanouscf2f9322021-09-22 15:34:41 -0700238 '-fstack-protector-strong',
239 '-fPIE',
240 '-fPIC',
241 '-D_FORTIFY_SOURCE=2',
242 '-Wformat',
243 '-Wformat-security'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530244]
245
246## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
247
248if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
249 add_project_arguments(
250 cxx.get_supported_arguments([
251 security_flags
252 ]),
253 language: 'cpp')
254endif
255
256# Boost dependency configuration
257
258add_project_arguments(
259cxx.get_supported_arguments([
Ed Tanouscf2f9322021-09-22 15:34:41 -0700260 '-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
261 '-DBOOST_ASIO_DISABLE_THREADS',
262 '-DBOOST_BEAST_USE_STD_STRING_VIEW',
263 '-DBOOST_ERROR_CODE_HEADER_ONLY',
264 '-DBOOST_SYSTEM_NO_DEPRECATED',
265 '-DBOOST_ASIO_NO_DEPRECATED',
266 '-DBOOST_ALL_NO_LIB',
267 '-DBOOST_NO_RTTI',
268 '-DBOOST_NO_TYPEID',
269 '-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
270 '-DBOOST_URL_STANDALONE',
271 '-DBOOST_URL_HEADER_ONLY',
272 '-DBOOST_ALLOW_DEPRECATED_HEADERS',
273 '-DJSON_NOEXCEPTION'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530274]),
275language : 'cpp')
276
277# Find the dependency modules, if not found use meson wrap to get them
278# automatically during the configure step
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800279bmcweb_dependencies = []
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530280
281pam = cxx.find_library('pam', required: get_option('pam'))
282atomic = cxx.find_library('atomic', required: true)
283openssl = dependency('openssl', required : true)
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800284bmcweb_dependencies += [pam, atomic, openssl]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530285
Ed Tanous7bb985e2021-09-02 14:31:40 -0700286sdbusplus = dependency('sdbusplus', required : false, include_type: 'system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530287if not sdbusplus.found()
288 sdbusplus_proj = subproject('sdbusplus', required: true)
289 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
290 sdbusplus = sdbusplus.as_system('system')
291endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800292bmcweb_dependencies += sdbusplus
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530293
294if get_option('rest').enabled()
Patrick Williams565c0912021-10-12 20:22:45 -0500295 tinyxml = dependency('tinyxml2',
296 default_options: ['tests=false'],
297 include_type: 'system',
298 )
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800299 bmcweb_dependencies += tinyxml
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530300endif
301
302systemd = dependency('systemd')
303zlib = dependency('zlib')
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800304bmcweb_dependencies += [systemd, zlib]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530305
306if cxx.has_header('nlohmann/json.hpp')
307 nlohmann_json = declare_dependency()
308else
Josh Lehan259df352021-10-07 15:20:02 -0700309 nlohmann_json_proj = subproject('nlohmann', required: true)
310 nlohmann_json = nlohmann_json_proj.get_variable('nlohmann_json_dep')
Ed Tanousb00dcc22021-02-23 12:52:50 -0800311 nlohmann_json = nlohmann_json.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530312endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800313bmcweb_dependencies += nlohmann_json
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530314
Ed Tanous7bb985e2021-09-02 14:31:40 -0700315boost = dependency('boost',version : '>=1.75.0', required : false, include_type: 'system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530316if not boost.found()
317 subproject('boost', required: false)
Ed Tanous65f73652021-02-17 10:20:27 -0800318 boost_inc = include_directories('subprojects/boost_1_75_0/', is_system:true)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530319 boost = declare_dependency(include_directories : boost_inc)
Ed Tanousb00dcc22021-02-23 12:52:50 -0800320 boost = boost.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530321endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800322bmcweb_dependencies += boost
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530323
324if cxx.has_header('boost/url/url_view.hpp')
325 boost_url = declare_dependency()
326else
327 subproject('boost-url', required: false)
328 boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true)
329 boost_url= declare_dependency(include_directories : boost_url_inc)
Ed Tanousb00dcc22021-02-23 12:52:50 -0800330 boost_url = boost_url.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530331endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800332bmcweb_dependencies += boost_url
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530333
334if get_option('tests').enabled()
335 gtest = dependency('gtest', main: true,disabler: true, required : false)
336 gmock = dependency('gmock', required : false)
337 if not gtest.found() and get_option('tests').enabled()
338 gtest_proj = subproject('gtest', required: true)
339 gtest = gtest_proj.get_variable('gtest_main_dep')
340 gmock = gtest_proj.get_variable('gmock_dep')
341 endif
Ed Tanousb00dcc22021-02-23 12:52:50 -0800342 gtest = gtest.as_system('system')
343 gmock = gmock.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530344endif
345
346# Source files
347
Ed Tanouscf2f9322021-09-22 15:34:41 -0700348srcfiles_bmcweb = [
349 'src/webserver_main.cpp',
350 'redfish-core/src/error_messages.cpp',
Ed Tanousd32c4fa2021-09-14 13:16:51 -0700351 'redfish-core/src/utils/json_utils.cpp',
352 'src/boost_url.cpp'
Ed Tanouscf2f9322021-09-22 15:34:41 -0700353]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530354
Ed Tanouscf2f9322021-09-22 15:34:41 -0700355srcfiles_unittest = [
356 'include/ut/dbus_utility_test.cpp',
357 'include/ut/http_utility_test.cpp',
Ed Tanousa8544a52021-09-29 14:31:13 -0700358 'include/ut/human_sort_test.cpp',
Ed Tanouscf2f9322021-09-22 15:34:41 -0700359 'redfish-core/ut/privileges_test.cpp',
360 'redfish-core/ut/lock_test.cpp',
361 'redfish-core/ut/configfile_test.cpp',
362 'redfish-core/ut/time_utils_test.cpp',
Ed Tanousf201ffb2021-10-09 14:49:28 -0700363 'redfish-core/ut/hex_utils_test.cpp',
Ed Tanouscf2f9322021-09-22 15:34:41 -0700364 'http/ut/utility_test.cpp'
365]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530366
367# Gather the Configuration data
368
369conf_data = configuration_data()
Ed Tanous0260d9d2021-02-07 19:31:07 +0000370conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB', get_option('http-body-limit'))
371xss_enabled = get_option('insecure-disable-xss')
Ed Tanousfeaf1502021-02-23 08:53:50 -0800372conf_data.set10('BMCWEB_INSECURE_DISABLE_XSS_PREVENTION', xss_enabled.enabled())
Ed Tanous0260d9d2021-02-07 19:31:07 +0000373conf_data.set('MESON_INSTALL_PREFIX', get_option('prefix'))
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700374conf_data.set('HTTPS_PORT', get_option('https_port'))
Ed Tanous75312982021-02-11 14:26:02 -0800375configure_file(input: 'bmcweb_config.h.in',
376 output: 'bmcweb_config.h',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530377 configuration: conf_data)
378
379# Configure and install systemd unit files
380
Patrick Williams6a779932021-10-12 20:08:44 -0500381systemd_system_unit_dir = systemd.get_variable(pkgconfig: 'systemdsystemunitdir')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530382
383bindir = get_option('prefix') + '/' +get_option('bindir')
384
385summary({
386 'prefix' : get_option('prefix'),
387 'bindir' : bindir,
388 'systemd unit directory' : systemd_system_unit_dir
389 }, section : 'Directories')
390
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700391configure_file(input : 'bmcweb.socket.in',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530392 output : 'bmcweb.socket',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530393 install_dir: systemd_system_unit_dir,
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700394 configuration: conf_data,
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530395 install : true)
396
397configure_file(input : 'bmcweb.service.in',
398 output : 'bmcweb.service',
399 install_dir: systemd_system_unit_dir,
400 configuration: conf_data,
401 install : true)
402
403# Copy pam-webserver to etc/pam.d
404configure_file(input : 'pam-webserver',
405 output : 'webserver',
406 copy : true,
407 install_dir: '/etc/pam.d',
408 install : true)
409
410install_subdir('static', install_dir : 'share/www', strip_directory : true)
411
412# Generate the bmcweb executable and the test binary
413
414executable('bmcweb',srcfiles_bmcweb,
415 include_directories : incdir,
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800416 dependencies: bmcweb_dependencies,
Ed Tanous5e34b672021-02-05 14:21:27 -0800417 link_args: '-Wl,--gc-sections',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530418 install: true,
419 install_dir:bindir)
420
421if(get_option('tests').enabled())
422 foreach src_test : srcfiles_unittest
423 testname = src_test.split('/')[-1].split('.')[0]
Patrick Williams6a779932021-10-12 20:08:44 -0500424 test(testname,executable(testname,
Ed Tanousd32c4fa2021-09-14 13:16:51 -0700425 [src_test,
426 'src/boost_url.cpp'],
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530427 include_directories : incdir,
428 install_dir: bindir,
429 dependencies: [
Ed Tanouscf2f9322021-09-22 15:34:41 -0700430 boost,
431 boost_url,
432 gtest,
433 openssl,
434 gmock,
435 nlohmann_json,
436 sdbusplus,
437 pam
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530438 ]))
439 endforeach
440endif