blob: 7145ce58947cd583f5fd07f0f9a6f309302009bc [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',
64'kvm' : '-DBMCWEB_ENABLE_KVM' ,
Alan Kuof16f6262020-12-08 19:29:59 +080065'basic-auth' : '-DBMCWEB_ENABLE_BASIC_AUTHENTICATION',
66'session-auth' : '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION',
67'xtoken-auth' : '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION',
68'cookie-auth' : '-DBMCWEB_ENABLE_COOKIE_AUTHENTICATION',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053069'mutual-tls-auth' : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION',
70'pam' : '-DWEBSERVER_ENABLE_PAM',
71'insecure-push-style-notification': '-DBMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING',
72'redfish' : '-DBMCWEB_ENABLE_REDFISH',
73'redfish-bmc-journal' : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL',
74'redfish-cpu-log' : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG',
75'redfish-dbus-log' : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES',
76'redfish-provisioning-feature' : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE',
Ravi Teja3fad0d52020-10-16 11:18:02 -050077'redfish-dump-log' : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053078'rest' : '-DBMCWEB_ENABLE_DBUS_REST',
79'insecure-sensor-override' : '-DBMCWEB_INSECURE_UNRESTRICTED_SENSOR_OVERRIDE',
80'static-hosting' : '-DBMCWEB_ENABLE_STATIC_HOSTING',
81'insecure-tftp-update' : '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE',
82'validate-unsecure-feature' : '-DBMCWEB_ENABLE_VALIDATION_UNSECURE_FEATURE',
Ed Tanousefb80622021-02-20 11:04:01 -080083#'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053084'vm-websocket' : '-DBMCWEB_ENABLE_VM_WEBSOCKET',
85}
86
87# Get the options status and build a project summary to show which flags are
88# being enabled during the configuration time.
89
90foreach option_key,option_value : feature_map
91 if(get_option(option_key).enabled())
92 if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl')
93 if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled())
94 add_project_arguments(option_value,language:'cpp')
95 summary(option_key,option_value, section : 'Enabled Features')
96 endif
97 else
98 summary(option_key,option_value, section : 'Enabled Features')
99 add_project_arguments(option_value,language:'cpp')
100 endif
101 else
102 if(option_key == 'insecure-disable-ssl')
103 summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features')
104 add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp')
105 endif
106 endif
107endforeach
108
109if(get_option('tests').enabled())
110 summary('unittest','NA', section : 'Enabled Features')
111endif
112
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530113# Add compiler arguments
114
115# -Wpedantic, -Wextra comes by default with warning level
116add_project_arguments(
117 cxx.get_supported_arguments([
118 '-Wold-style-cast',
119 '-Wcast-align',
120 '-Wunused',
121 '-Woverloaded-virtual',
122 '-Wconversion',
123 '-Wsign-conversion',
124 '-Wno-attributes',
125 ]),
126 language: 'cpp'
127)
128
129if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
130add_project_arguments(
131 cxx.get_supported_arguments([
132 '-Weverything',
133 '-Wno-c++98-compat',
134 '-Wno-c++98-compat-pedantic',
135 '-Wno-global-constructors',
136 '-Wno-exit-time-destructors',
137 '-Wno-shadow',
138 '-Wno-used-but-marked-unused',
139 '-Wno-documentation-unknown-command',
140 '-Wno-weak-vtables',
141 '-Wno-documentation',
142 '-Wno-padded',
143 '-Wunused-parameter',
144 '-Wcovered-switch-default',
145 '-Wcomma',
146 '-Wextra-semi',
147 '-Wzero-as-null-pointer-constant',
148 '-Wswitch-enum',
149 '-Wnull-dereference',
150 '-Wdouble-promotion',
151 '-Wformat=2',
152 ]),
153 language:'cpp')
154endif
155
156# if compiler is gnu-gcc , and version is > 8.0 then we add few more
157# compiler arguments , we know that will pass
158
159if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
160
161 ## remove once bmcweb/issues/147 is fixed
162 add_global_link_arguments('-Wno-stringop-overflow',language:['c','cpp'])
163 add_project_arguments('-Wno-stringop-overflow',language:['c','cpp'])
164
165 add_project_arguments(
166 cxx.get_supported_arguments([
167 '-Wduplicated-cond',
168 '-Wduplicated-branches',
169 '-Wlogical-op',
170 '-Wunused-parameter',
171 '-Wnull-dereference',
172 '-Wdouble-promotion',
173 '-Wformat=2',
174 ]),
175 language:'cpp')
176
177 if (get_option('buildtype') != 'plain')
178 if (get_option('b_lto') == true and get_option('optimization')!='0')
179 # Reduce the binary size by removing unnecessary
180 # dynamic symbol table entries
181
182 add_project_arguments(
183 cxx.get_supported_arguments([
184 '-fno-fat-lto-objects',
185 '-fvisibility=hidden',
186 '-fvisibility-inlines-hidden'
187 ]),
188 language: 'cpp')
189
190 if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
191 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
192 endif
193 endif
194
Manojkiran Eda620a6e12020-10-04 21:02:02 +0530195 if( get_option('bmcweb-logging').enabled() or \
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530196 get_option('buildtype').startswith('debug'))
197 add_project_arguments([
198 '-DBMCWEB_ENABLE_LOGGING',
199 '-DBMCWEB_ENABLE_DEBUG'
200 ],
201 language : 'cpp')
202
203 summary({'debug' :'-DBMCWEB_ENABLE_DEBUG',
204 'logging' : '-DBMCWEB_ENABLE_LOGGING',
205 },section : 'Enabled Features')
206 endif
207
Johnathan Mantey2db77d32020-11-20 08:51:11 -0800208 if( get_option('redfish-allow-deprecated-hostname-patch').enabled())
209 add_project_arguments([
210 '-DBMCWEB_ALLOW_DEPRECATED_HOSTNAME_PATCH'
211 ],
212 language : 'cpp')
213
214 summary({'hostname-patch' :'-DBMCWEB_ALLOW_DEPRECATED_HOSTNAME_PATCH'
215 },section : 'Enabled Features')
216 endif
217
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530218 endif
219endif
220
221# Set Compiler Security flags
222
223security_flags = [
224'-fstack-protector-strong',
225'-fPIE',
226'-fPIC',
227'-D_FORTIFY_SOURCE=2',
228'-Wformat',
229'-Wformat-security'
230]
231
232## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
233
234if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
235 add_project_arguments(
236 cxx.get_supported_arguments([
237 security_flags
238 ]),
239 language: 'cpp')
240endif
241
242# Boost dependency configuration
243
244add_project_arguments(
245cxx.get_supported_arguments([
246'-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
247'-DBOOST_ASIO_DISABLE_THREADS',
248'-DBOOST_BEAST_USE_STD_STRING_VIEW',
249'-DBOOST_ERROR_CODE_HEADER_ONLY',
250'-DBOOST_SYSTEM_NO_DEPRECATED',
251'-DBOOST_ASIO_NO_DEPRECATED',
252'-DBOOST_ALL_NO_LIB',
253'-DBOOST_NO_RTTI',
254'-DBOOST_NO_TYPEID',
255'-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
256'-DBOOST_URL_STANDALONE',
Ed Tanous19a88152021-01-11 12:50:47 -0800257'-DBOOST_URL_HEADER_ONLY',
258'-DBOOST_ALLOW_DEPRECATED_HEADERS'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530259]),
260language : 'cpp')
261
262# Find the dependency modules, if not found use meson wrap to get them
263# automatically during the configure step
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800264bmcweb_dependencies = []
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530265
266pam = cxx.find_library('pam', required: get_option('pam'))
267atomic = cxx.find_library('atomic', required: true)
268openssl = dependency('openssl', required : true)
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800269bmcweb_dependencies += [pam, atomic, openssl]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530270
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800271sdbusplus = dependency('sdbusplus',required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530272if not sdbusplus.found()
273 sdbusplus_proj = subproject('sdbusplus', required: true)
274 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
275 sdbusplus = sdbusplus.as_system('system')
276endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800277bmcweb_dependencies += sdbusplus
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530278
279if get_option('rest').enabled()
280 tinyxml = dependency('tinyxml2', required: false)
281 if not tinyxml.found()
282 tinyxml_proj = subproject('tinyxml2', required: true)
283 tinyxml = tinyxml_proj.get_variable('tinyxml2_dep')
284 tinyxml = tinyxml.as_system('system')
285 endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800286 bmcweb_dependencies += tinyxml
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530287endif
288
289systemd = dependency('systemd')
290zlib = dependency('zlib')
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800291bmcweb_dependencies += [systemd, zlib]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530292
293if cxx.has_header('nlohmann/json.hpp')
294 nlohmann_json = declare_dependency()
295else
296 subproject('nlohmann', required: false)
297 nlohmann_json = declare_dependency(
298 include_directories: [
299 'subprojects/nlohmann/single_include',
300 'subprojects/nlohmann/single_include/nlohmann',
301 ]
302 )
Ed Tanousb00dcc22021-02-23 12:52:50 -0800303 nlohmann_json = nlohmann_json.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530304endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800305bmcweb_dependencies += nlohmann_json
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530306
Ed Tanous65f73652021-02-17 10:20:27 -0800307boost = dependency('boost',version : '>=1.75.0', required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530308if not boost.found()
309 subproject('boost', required: false)
Ed Tanous65f73652021-02-17 10:20:27 -0800310 boost_inc = include_directories('subprojects/boost_1_75_0/', is_system:true)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530311 boost = declare_dependency(include_directories : boost_inc)
Ed Tanousb00dcc22021-02-23 12:52:50 -0800312 boost = boost.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530313endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800314bmcweb_dependencies += boost
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530315
316if cxx.has_header('boost/url/url_view.hpp')
317 boost_url = declare_dependency()
318else
319 subproject('boost-url', required: false)
320 boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true)
321 boost_url= declare_dependency(include_directories : boost_url_inc)
Ed Tanousb00dcc22021-02-23 12:52:50 -0800322 boost_url = boost_url.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530323endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800324bmcweb_dependencies += boost_url
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530325
326if get_option('tests').enabled()
327 gtest = dependency('gtest', main: true,disabler: true, required : false)
328 gmock = dependency('gmock', required : false)
329 if not gtest.found() and get_option('tests').enabled()
330 gtest_proj = subproject('gtest', required: true)
331 gtest = gtest_proj.get_variable('gtest_main_dep')
332 gmock = gtest_proj.get_variable('gmock_dep')
333 endif
Ed Tanousb00dcc22021-02-23 12:52:50 -0800334 gtest = gtest.as_system('system')
335 gmock = gmock.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530336endif
337
338# Source files
339
340srcfiles_bmcweb = ['src/webserver_main.cpp','redfish-core/src/error_messages.cpp',
341 'redfish-core/src/utils/json_utils.cpp']
342
Manojkiran Eda17a897d2020-09-12 15:31:58 +0530343srcfiles_unittest = ['include/ut/dbus_utility_test.cpp',
344 'redfish-core/ut/privileges_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530345 'redfish-core/ut/lock_test.cpp',
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500346 'redfish-core/ut/configfile_test.cpp',
Wludzik, Jozef4dbb8ae2020-05-18 11:56:57 +0200347 'redfish-core/ut/time_utils_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530348 'http/ut/utility_test.cpp']
349
350# Gather the Configuration data
351
352conf_data = configuration_data()
Ed Tanous0260d9d2021-02-07 19:31:07 +0000353conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB', get_option('http-body-limit'))
354xss_enabled = get_option('insecure-disable-xss')
Ed Tanousfeaf1502021-02-23 08:53:50 -0800355conf_data.set10('BMCWEB_INSECURE_DISABLE_XSS_PREVENTION', xss_enabled.enabled())
Ed Tanous0260d9d2021-02-07 19:31:07 +0000356conf_data.set('MESON_INSTALL_PREFIX', get_option('prefix'))
Ed Tanous75312982021-02-11 14:26:02 -0800357configure_file(input: 'bmcweb_config.h.in',
358 output: 'bmcweb_config.h',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530359 configuration: conf_data)
360
361# Configure and install systemd unit files
362
363systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
364
365bindir = get_option('prefix') + '/' +get_option('bindir')
366
367summary({
368 'prefix' : get_option('prefix'),
369 'bindir' : bindir,
370 'systemd unit directory' : systemd_system_unit_dir
371 }, section : 'Directories')
372
373configure_file(input : 'bmcweb.socket',
374 output : 'bmcweb.socket',
375 copy : true,
376 install_dir: systemd_system_unit_dir,
377 install : true)
378
379configure_file(input : 'bmcweb.service.in',
380 output : 'bmcweb.service',
381 install_dir: systemd_system_unit_dir,
382 configuration: conf_data,
383 install : true)
384
385# Copy pam-webserver to etc/pam.d
386configure_file(input : 'pam-webserver',
387 output : 'webserver',
388 copy : true,
389 install_dir: '/etc/pam.d',
390 install : true)
391
392install_subdir('static', install_dir : 'share/www', strip_directory : true)
393
394# Generate the bmcweb executable and the test binary
395
396executable('bmcweb',srcfiles_bmcweb,
397 include_directories : incdir,
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800398 dependencies: bmcweb_dependencies,
Ed Tanous5e34b672021-02-05 14:21:27 -0800399 link_args: '-Wl,--gc-sections',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530400 install: true,
401 install_dir:bindir)
402
403if(get_option('tests').enabled())
404 foreach src_test : srcfiles_unittest
405 testname = src_test.split('/')[-1].split('.')[0]
406 test(testname,executable(testname,src_test,
407 include_directories : incdir,
408 install_dir: bindir,
409 dependencies: [
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500410 boost, boost_url, gtest,openssl,gmock,nlohmann_json,sdbusplus,pam
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530411 ]))
412 endforeach
413endif