blob: 2b27e866afcc5ad3051cffc87048ad6ba3345e9e [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
52incdir = include_directories('include','redfish-core/include',
53 'redfish-core/lib','http')
54
55# Get the options and enable the respective features
56## create a MAP of "options : feature_flag"
57
58feature_map = {
59'insecure-disable-auth' : '-DBMCWEB_INSECURE_DISABLE_AUTHENTICATION',
60'insecure-disable-csrf' : '-DBMCWEB_INSECURE_DISABLE_CSRF_PREVENTION',
61'insecure-disable-ssl' : '-DBMCWEB_INSECURE_DISABLE_SSL',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053062'host-serial-socket' : '-DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET',
63'ibm-management-console' : '-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE',
Feras Aldahlawi735ef6d2021-03-19 14:01:46 -070064'google-api' : '-DBMCWEB_ENABLE_GOOGLE_API',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053065'kvm' : '-DBMCWEB_ENABLE_KVM' ,
Alan Kuof16f6262020-12-08 19:29:59 +080066'basic-auth' : '-DBMCWEB_ENABLE_BASIC_AUTHENTICATION',
67'session-auth' : '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION',
68'xtoken-auth' : '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION',
69'cookie-auth' : '-DBMCWEB_ENABLE_COOKIE_AUTHENTICATION',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053070'mutual-tls-auth' : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION',
71'pam' : '-DWEBSERVER_ENABLE_PAM',
72'insecure-push-style-notification': '-DBMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING',
73'redfish' : '-DBMCWEB_ENABLE_REDFISH',
74'redfish-bmc-journal' : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL',
75'redfish-cpu-log' : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG',
76'redfish-dbus-log' : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES',
77'redfish-provisioning-feature' : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE',
Ravi Teja3fad0d52020-10-16 11:18:02 -050078'redfish-dump-log' : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053079'rest' : '-DBMCWEB_ENABLE_DBUS_REST',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053080'static-hosting' : '-DBMCWEB_ENABLE_STATIC_HOSTING',
81'insecure-tftp-update' : '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE',
Ed Tanousefb80622021-02-20 11:04:01 -080082#'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053083'vm-websocket' : '-DBMCWEB_ENABLE_VM_WEBSOCKET',
84}
85
86# Get the options status and build a project summary to show which flags are
87# being enabled during the configuration time.
88
89foreach option_key,option_value : feature_map
90 if(get_option(option_key).enabled())
91 if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl')
92 if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled())
93 add_project_arguments(option_value,language:'cpp')
94 summary(option_key,option_value, section : 'Enabled Features')
95 endif
96 else
97 summary(option_key,option_value, section : 'Enabled Features')
98 add_project_arguments(option_value,language:'cpp')
99 endif
100 else
101 if(option_key == 'insecure-disable-ssl')
102 summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features')
103 add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp')
104 endif
105 endif
106endforeach
107
108if(get_option('tests').enabled())
109 summary('unittest','NA', section : 'Enabled Features')
110endif
111
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530112# Add compiler arguments
113
114# -Wpedantic, -Wextra comes by default with warning level
115add_project_arguments(
116 cxx.get_supported_arguments([
117 '-Wold-style-cast',
118 '-Wcast-align',
119 '-Wunused',
120 '-Woverloaded-virtual',
121 '-Wconversion',
122 '-Wsign-conversion',
123 '-Wno-attributes',
124 ]),
125 language: 'cpp'
126)
127
128if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
129add_project_arguments(
130 cxx.get_supported_arguments([
131 '-Weverything',
132 '-Wno-c++98-compat',
133 '-Wno-c++98-compat-pedantic',
134 '-Wno-global-constructors',
135 '-Wno-exit-time-destructors',
136 '-Wno-shadow',
137 '-Wno-used-but-marked-unused',
138 '-Wno-documentation-unknown-command',
139 '-Wno-weak-vtables',
140 '-Wno-documentation',
141 '-Wno-padded',
142 '-Wunused-parameter',
143 '-Wcovered-switch-default',
144 '-Wcomma',
145 '-Wextra-semi',
146 '-Wzero-as-null-pointer-constant',
147 '-Wswitch-enum',
148 '-Wnull-dereference',
149 '-Wdouble-promotion',
150 '-Wformat=2',
151 ]),
152 language:'cpp')
153endif
154
155# if compiler is gnu-gcc , and version is > 8.0 then we add few more
156# compiler arguments , we know that will pass
157
158if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
159
160 ## remove once bmcweb/issues/147 is fixed
161 add_global_link_arguments('-Wno-stringop-overflow',language:['c','cpp'])
162 add_project_arguments('-Wno-stringop-overflow',language:['c','cpp'])
163
164 add_project_arguments(
165 cxx.get_supported_arguments([
166 '-Wduplicated-cond',
167 '-Wduplicated-branches',
168 '-Wlogical-op',
169 '-Wunused-parameter',
170 '-Wnull-dereference',
171 '-Wdouble-promotion',
172 '-Wformat=2',
173 ]),
174 language:'cpp')
175
176 if (get_option('buildtype') != 'plain')
177 if (get_option('b_lto') == true and get_option('optimization')!='0')
178 # Reduce the binary size by removing unnecessary
179 # dynamic symbol table entries
180
181 add_project_arguments(
182 cxx.get_supported_arguments([
183 '-fno-fat-lto-objects',
184 '-fvisibility=hidden',
185 '-fvisibility-inlines-hidden'
186 ]),
187 language: 'cpp')
188
189 if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
190 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
191 endif
192 endif
193
Manojkiran Eda620a6e12020-10-04 21:02:02 +0530194 if( get_option('bmcweb-logging').enabled() or \
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530195 get_option('buildtype').startswith('debug'))
196 add_project_arguments([
197 '-DBMCWEB_ENABLE_LOGGING',
198 '-DBMCWEB_ENABLE_DEBUG'
199 ],
200 language : 'cpp')
201
202 summary({'debug' :'-DBMCWEB_ENABLE_DEBUG',
203 'logging' : '-DBMCWEB_ENABLE_LOGGING',
204 },section : 'Enabled Features')
205 endif
206
Johnathan Mantey2db77d32020-11-20 08:51:11 -0800207 if( get_option('redfish-allow-deprecated-hostname-patch').enabled())
208 add_project_arguments([
209 '-DBMCWEB_ALLOW_DEPRECATED_HOSTNAME_PATCH'
210 ],
211 language : 'cpp')
212
213 summary({'hostname-patch' :'-DBMCWEB_ALLOW_DEPRECATED_HOSTNAME_PATCH'
214 },section : 'Enabled Features')
215 endif
216
zhanghch050256b692021-06-12 10:26:52 +0800217 if( get_option('redfish-allow-deprecated-power-thermal').enabled())
218 add_project_arguments([
219 '-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL'
220 ],
221 language : 'cpp')
222
223 summary({'power-thermal' :'-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL'
224 },section : 'Enabled Features')
225 endif
George Liue8204932021-02-01 14:42:49 +0800226
227 if( get_option('redfish-new-powersubsystem-thermalsubsystem').enabled())
228 add_project_arguments([
229 '-DBMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM'
230 ],
231 language : 'cpp')
232
233 summary({'new-powersubsystem-thermalsubsystem' :'-DBMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM'
234 },section : 'Enabled Features')
235 endif
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530236 endif
237endif
238
239# Set Compiler Security flags
240
241security_flags = [
242'-fstack-protector-strong',
243'-fPIE',
244'-fPIC',
245'-D_FORTIFY_SOURCE=2',
246'-Wformat',
247'-Wformat-security'
248]
249
250## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
251
252if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
253 add_project_arguments(
254 cxx.get_supported_arguments([
255 security_flags
256 ]),
257 language: 'cpp')
258endif
259
260# Boost dependency configuration
261
262add_project_arguments(
263cxx.get_supported_arguments([
264'-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
265'-DBOOST_ASIO_DISABLE_THREADS',
266'-DBOOST_BEAST_USE_STD_STRING_VIEW',
267'-DBOOST_ERROR_CODE_HEADER_ONLY',
268'-DBOOST_SYSTEM_NO_DEPRECATED',
269'-DBOOST_ASIO_NO_DEPRECATED',
270'-DBOOST_ALL_NO_LIB',
271'-DBOOST_NO_RTTI',
272'-DBOOST_NO_TYPEID',
273'-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
274'-DBOOST_URL_STANDALONE',
Ed Tanous19a88152021-01-11 12:50:47 -0800275'-DBOOST_URL_HEADER_ONLY',
Ed Tanous58e42b12021-08-22 15:04:10 -0700276'-DBOOST_ALLOW_DEPRECATED_HEADERS',
277'-DJSON_NOEXCEPTION'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530278]),
279language : 'cpp')
280
281# Find the dependency modules, if not found use meson wrap to get them
282# automatically during the configure step
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800283bmcweb_dependencies = []
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530284
285pam = cxx.find_library('pam', required: get_option('pam'))
286atomic = cxx.find_library('atomic', required: true)
287openssl = dependency('openssl', required : true)
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800288bmcweb_dependencies += [pam, atomic, openssl]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530289
Ed Tanous7bb985e2021-09-02 14:31:40 -0700290sdbusplus = dependency('sdbusplus', required : false, include_type: 'system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530291if not sdbusplus.found()
292 sdbusplus_proj = subproject('sdbusplus', required: true)
293 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
294 sdbusplus = sdbusplus.as_system('system')
295endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800296bmcweb_dependencies += sdbusplus
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530297
298if get_option('rest').enabled()
299 tinyxml = dependency('tinyxml2', required: false)
300 if not tinyxml.found()
301 tinyxml_proj = subproject('tinyxml2', required: true)
302 tinyxml = tinyxml_proj.get_variable('tinyxml2_dep')
303 tinyxml = tinyxml.as_system('system')
304 endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800305 bmcweb_dependencies += tinyxml
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530306endif
307
308systemd = dependency('systemd')
309zlib = dependency('zlib')
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800310bmcweb_dependencies += [systemd, zlib]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530311
312if cxx.has_header('nlohmann/json.hpp')
313 nlohmann_json = declare_dependency()
314else
315 subproject('nlohmann', required: false)
316 nlohmann_json = declare_dependency(
317 include_directories: [
318 'subprojects/nlohmann/single_include',
319 'subprojects/nlohmann/single_include/nlohmann',
320 ]
321 )
Ed Tanousb00dcc22021-02-23 12:52:50 -0800322 nlohmann_json = nlohmann_json.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530323endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800324bmcweb_dependencies += nlohmann_json
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530325
Ed Tanous7bb985e2021-09-02 14:31:40 -0700326boost = dependency('boost',version : '>=1.75.0', required : false, include_type: 'system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530327if not boost.found()
328 subproject('boost', required: false)
Ed Tanous65f73652021-02-17 10:20:27 -0800329 boost_inc = include_directories('subprojects/boost_1_75_0/', is_system:true)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530330 boost = declare_dependency(include_directories : boost_inc)
Ed Tanousb00dcc22021-02-23 12:52:50 -0800331 boost = boost.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530332endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800333bmcweb_dependencies += boost
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530334
335if cxx.has_header('boost/url/url_view.hpp')
336 boost_url = declare_dependency()
337else
338 subproject('boost-url', required: false)
339 boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true)
340 boost_url= declare_dependency(include_directories : boost_url_inc)
Ed Tanousb00dcc22021-02-23 12:52:50 -0800341 boost_url = boost_url.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530342endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800343bmcweb_dependencies += boost_url
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530344
345if get_option('tests').enabled()
346 gtest = dependency('gtest', main: true,disabler: true, required : false)
347 gmock = dependency('gmock', required : false)
348 if not gtest.found() and get_option('tests').enabled()
349 gtest_proj = subproject('gtest', required: true)
350 gtest = gtest_proj.get_variable('gtest_main_dep')
351 gmock = gtest_proj.get_variable('gmock_dep')
352 endif
Ed Tanousb00dcc22021-02-23 12:52:50 -0800353 gtest = gtest.as_system('system')
354 gmock = gmock.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530355endif
356
357# Source files
358
359srcfiles_bmcweb = ['src/webserver_main.cpp','redfish-core/src/error_messages.cpp',
360 'redfish-core/src/utils/json_utils.cpp']
361
Manojkiran Eda17a897d2020-09-12 15:31:58 +0530362srcfiles_unittest = ['include/ut/dbus_utility_test.cpp',
George Liu647b3cd2021-07-05 12:43:56 +0800363 'include/ut/http_utility_test.cpp',
Manojkiran Eda17a897d2020-09-12 15:31:58 +0530364 'redfish-core/ut/privileges_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530365 'redfish-core/ut/lock_test.cpp',
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500366 'redfish-core/ut/configfile_test.cpp',
Wludzik, Jozef4dbb8ae2020-05-18 11:56:57 +0200367 'redfish-core/ut/time_utils_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530368 'http/ut/utility_test.cpp']
369
370# Gather the Configuration data
371
372conf_data = configuration_data()
Ed Tanous0260d9d2021-02-07 19:31:07 +0000373conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB', get_option('http-body-limit'))
374xss_enabled = get_option('insecure-disable-xss')
Ed Tanousfeaf1502021-02-23 08:53:50 -0800375conf_data.set10('BMCWEB_INSECURE_DISABLE_XSS_PREVENTION', xss_enabled.enabled())
Ed Tanous0260d9d2021-02-07 19:31:07 +0000376conf_data.set('MESON_INSTALL_PREFIX', get_option('prefix'))
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700377conf_data.set('HTTPS_PORT', get_option('https_port'))
Ed Tanous75312982021-02-11 14:26:02 -0800378configure_file(input: 'bmcweb_config.h.in',
379 output: 'bmcweb_config.h',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530380 configuration: conf_data)
381
382# Configure and install systemd unit files
383
384systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
385
386bindir = get_option('prefix') + '/' +get_option('bindir')
387
388summary({
389 'prefix' : get_option('prefix'),
390 'bindir' : bindir,
391 'systemd unit directory' : systemd_system_unit_dir
392 }, section : 'Directories')
393
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700394configure_file(input : 'bmcweb.socket.in',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530395 output : 'bmcweb.socket',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530396 install_dir: systemd_system_unit_dir,
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700397 configuration: conf_data,
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530398 install : true)
399
400configure_file(input : 'bmcweb.service.in',
401 output : 'bmcweb.service',
402 install_dir: systemd_system_unit_dir,
403 configuration: conf_data,
404 install : true)
405
406# Copy pam-webserver to etc/pam.d
407configure_file(input : 'pam-webserver',
408 output : 'webserver',
409 copy : true,
410 install_dir: '/etc/pam.d',
411 install : true)
412
413install_subdir('static', install_dir : 'share/www', strip_directory : true)
414
415# Generate the bmcweb executable and the test binary
416
417executable('bmcweb',srcfiles_bmcweb,
418 include_directories : incdir,
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800419 dependencies: bmcweb_dependencies,
Ed Tanous5e34b672021-02-05 14:21:27 -0800420 link_args: '-Wl,--gc-sections',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530421 install: true,
422 install_dir:bindir)
423
424if(get_option('tests').enabled())
425 foreach src_test : srcfiles_unittest
426 testname = src_test.split('/')[-1].split('.')[0]
427 test(testname,executable(testname,src_test,
428 include_directories : incdir,
429 install_dir: bindir,
430 dependencies: [
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500431 boost, boost_url, gtest,openssl,gmock,nlohmann_json,sdbusplus,pam
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530432 ]))
433 endforeach
434endif