blob: f6a66f1462640d5b1a6376573bbaf7939082a605 [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
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530226 endif
227endif
228
229# Set Compiler Security flags
230
231security_flags = [
232'-fstack-protector-strong',
233'-fPIE',
234'-fPIC',
235'-D_FORTIFY_SOURCE=2',
236'-Wformat',
237'-Wformat-security'
238]
239
240## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
241
242if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
243 add_project_arguments(
244 cxx.get_supported_arguments([
245 security_flags
246 ]),
247 language: 'cpp')
248endif
249
250# Boost dependency configuration
251
252add_project_arguments(
253cxx.get_supported_arguments([
254'-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
255'-DBOOST_ASIO_DISABLE_THREADS',
256'-DBOOST_BEAST_USE_STD_STRING_VIEW',
257'-DBOOST_ERROR_CODE_HEADER_ONLY',
258'-DBOOST_SYSTEM_NO_DEPRECATED',
259'-DBOOST_ASIO_NO_DEPRECATED',
260'-DBOOST_ALL_NO_LIB',
261'-DBOOST_NO_RTTI',
262'-DBOOST_NO_TYPEID',
263'-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
264'-DBOOST_URL_STANDALONE',
Ed Tanous19a88152021-01-11 12:50:47 -0800265'-DBOOST_URL_HEADER_ONLY',
266'-DBOOST_ALLOW_DEPRECATED_HEADERS'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530267]),
268language : 'cpp')
269
270# Find the dependency modules, if not found use meson wrap to get them
271# automatically during the configure step
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800272bmcweb_dependencies = []
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530273
274pam = cxx.find_library('pam', required: get_option('pam'))
275atomic = cxx.find_library('atomic', required: true)
276openssl = dependency('openssl', required : true)
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800277bmcweb_dependencies += [pam, atomic, openssl]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530278
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800279sdbusplus = dependency('sdbusplus',required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530280if not sdbusplus.found()
281 sdbusplus_proj = subproject('sdbusplus', required: true)
282 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
283 sdbusplus = sdbusplus.as_system('system')
284endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800285bmcweb_dependencies += sdbusplus
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530286
287if get_option('rest').enabled()
288 tinyxml = dependency('tinyxml2', required: false)
289 if not tinyxml.found()
290 tinyxml_proj = subproject('tinyxml2', required: true)
291 tinyxml = tinyxml_proj.get_variable('tinyxml2_dep')
292 tinyxml = tinyxml.as_system('system')
293 endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800294 bmcweb_dependencies += tinyxml
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530295endif
296
297systemd = dependency('systemd')
298zlib = dependency('zlib')
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800299bmcweb_dependencies += [systemd, zlib]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530300
301if cxx.has_header('nlohmann/json.hpp')
302 nlohmann_json = declare_dependency()
303else
304 subproject('nlohmann', required: false)
305 nlohmann_json = declare_dependency(
306 include_directories: [
307 'subprojects/nlohmann/single_include',
308 'subprojects/nlohmann/single_include/nlohmann',
309 ]
310 )
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 Tanous65f73652021-02-17 10:20:27 -0800315boost = dependency('boost',version : '>=1.75.0', required : false)
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
348srcfiles_bmcweb = ['src/webserver_main.cpp','redfish-core/src/error_messages.cpp',
349 'redfish-core/src/utils/json_utils.cpp']
350
Manojkiran Eda17a897d2020-09-12 15:31:58 +0530351srcfiles_unittest = ['include/ut/dbus_utility_test.cpp',
352 'redfish-core/ut/privileges_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530353 'redfish-core/ut/lock_test.cpp',
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500354 'redfish-core/ut/configfile_test.cpp',
Wludzik, Jozef4dbb8ae2020-05-18 11:56:57 +0200355 'redfish-core/ut/time_utils_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530356 'http/ut/utility_test.cpp']
357
358# Gather the Configuration data
359
360conf_data = configuration_data()
Ed Tanous0260d9d2021-02-07 19:31:07 +0000361conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB', get_option('http-body-limit'))
362xss_enabled = get_option('insecure-disable-xss')
Ed Tanousfeaf1502021-02-23 08:53:50 -0800363conf_data.set10('BMCWEB_INSECURE_DISABLE_XSS_PREVENTION', xss_enabled.enabled())
Ed Tanous0260d9d2021-02-07 19:31:07 +0000364conf_data.set('MESON_INSTALL_PREFIX', get_option('prefix'))
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700365conf_data.set('HTTPS_PORT', get_option('https_port'))
Ed Tanous75312982021-02-11 14:26:02 -0800366configure_file(input: 'bmcweb_config.h.in',
367 output: 'bmcweb_config.h',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530368 configuration: conf_data)
369
370# Configure and install systemd unit files
371
372systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
373
374bindir = get_option('prefix') + '/' +get_option('bindir')
375
376summary({
377 'prefix' : get_option('prefix'),
378 'bindir' : bindir,
379 'systemd unit directory' : systemd_system_unit_dir
380 }, section : 'Directories')
381
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700382configure_file(input : 'bmcweb.socket.in',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530383 output : 'bmcweb.socket',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530384 install_dir: systemd_system_unit_dir,
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700385 configuration: conf_data,
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530386 install : true)
387
388configure_file(input : 'bmcweb.service.in',
389 output : 'bmcweb.service',
390 install_dir: systemd_system_unit_dir,
391 configuration: conf_data,
392 install : true)
393
394# Copy pam-webserver to etc/pam.d
395configure_file(input : 'pam-webserver',
396 output : 'webserver',
397 copy : true,
398 install_dir: '/etc/pam.d',
399 install : true)
400
401install_subdir('static', install_dir : 'share/www', strip_directory : true)
402
403# Generate the bmcweb executable and the test binary
404
405executable('bmcweb',srcfiles_bmcweb,
406 include_directories : incdir,
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800407 dependencies: bmcweb_dependencies,
Ed Tanous5e34b672021-02-05 14:21:27 -0800408 link_args: '-Wl,--gc-sections',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530409 install: true,
410 install_dir:bindir)
411
412if(get_option('tests').enabled())
413 foreach src_test : srcfiles_unittest
414 testname = src_test.split('/')[-1].split('.')[0]
415 test(testname,executable(testname,src_test,
416 include_directories : incdir,
417 install_dir: bindir,
418 dependencies: [
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500419 boost, boost_url, gtest,openssl,gmock,nlohmann_json,sdbusplus,pam
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530420 ]))
421 endforeach
422endif