blob: bdc514bdc2197678aed56066e278213d1587fa4c [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',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053079'static-hosting' : '-DBMCWEB_ENABLE_STATIC_HOSTING',
80'insecure-tftp-update' : '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE',
Ed Tanousefb80622021-02-20 11:04:01 -080081#'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053082'vm-websocket' : '-DBMCWEB_ENABLE_VM_WEBSOCKET',
83}
84
85# Get the options status and build a project summary to show which flags are
86# being enabled during the configuration time.
87
88foreach option_key,option_value : feature_map
89 if(get_option(option_key).enabled())
90 if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl')
91 if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled())
92 add_project_arguments(option_value,language:'cpp')
93 summary(option_key,option_value, section : 'Enabled Features')
94 endif
95 else
96 summary(option_key,option_value, section : 'Enabled Features')
97 add_project_arguments(option_value,language:'cpp')
98 endif
99 else
100 if(option_key == 'insecure-disable-ssl')
101 summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features')
102 add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp')
103 endif
104 endif
105endforeach
106
107if(get_option('tests').enabled())
108 summary('unittest','NA', section : 'Enabled Features')
109endif
110
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530111# Add compiler arguments
112
113# -Wpedantic, -Wextra comes by default with warning level
114add_project_arguments(
115 cxx.get_supported_arguments([
116 '-Wold-style-cast',
117 '-Wcast-align',
118 '-Wunused',
119 '-Woverloaded-virtual',
120 '-Wconversion',
121 '-Wsign-conversion',
122 '-Wno-attributes',
123 ]),
124 language: 'cpp'
125)
126
127if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
128add_project_arguments(
129 cxx.get_supported_arguments([
130 '-Weverything',
131 '-Wno-c++98-compat',
132 '-Wno-c++98-compat-pedantic',
133 '-Wno-global-constructors',
134 '-Wno-exit-time-destructors',
135 '-Wno-shadow',
136 '-Wno-used-but-marked-unused',
137 '-Wno-documentation-unknown-command',
138 '-Wno-weak-vtables',
139 '-Wno-documentation',
140 '-Wno-padded',
141 '-Wunused-parameter',
142 '-Wcovered-switch-default',
143 '-Wcomma',
144 '-Wextra-semi',
145 '-Wzero-as-null-pointer-constant',
146 '-Wswitch-enum',
147 '-Wnull-dereference',
148 '-Wdouble-promotion',
149 '-Wformat=2',
150 ]),
151 language:'cpp')
152endif
153
154# if compiler is gnu-gcc , and version is > 8.0 then we add few more
155# compiler arguments , we know that will pass
156
157if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
158
159 ## remove once bmcweb/issues/147 is fixed
160 add_global_link_arguments('-Wno-stringop-overflow',language:['c','cpp'])
161 add_project_arguments('-Wno-stringop-overflow',language:['c','cpp'])
162
163 add_project_arguments(
164 cxx.get_supported_arguments([
165 '-Wduplicated-cond',
166 '-Wduplicated-branches',
167 '-Wlogical-op',
168 '-Wunused-parameter',
169 '-Wnull-dereference',
170 '-Wdouble-promotion',
171 '-Wformat=2',
172 ]),
173 language:'cpp')
174
175 if (get_option('buildtype') != 'plain')
176 if (get_option('b_lto') == true and get_option('optimization')!='0')
177 # Reduce the binary size by removing unnecessary
178 # dynamic symbol table entries
179
180 add_project_arguments(
181 cxx.get_supported_arguments([
182 '-fno-fat-lto-objects',
183 '-fvisibility=hidden',
184 '-fvisibility-inlines-hidden'
185 ]),
186 language: 'cpp')
187
188 if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
189 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
190 endif
191 endif
192
Manojkiran Eda620a6e12020-10-04 21:02:02 +0530193 if( get_option('bmcweb-logging').enabled() or \
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530194 get_option('buildtype').startswith('debug'))
195 add_project_arguments([
196 '-DBMCWEB_ENABLE_LOGGING',
197 '-DBMCWEB_ENABLE_DEBUG'
198 ],
199 language : 'cpp')
200
201 summary({'debug' :'-DBMCWEB_ENABLE_DEBUG',
202 'logging' : '-DBMCWEB_ENABLE_LOGGING',
203 },section : 'Enabled Features')
204 endif
205
Johnathan Mantey2db77d32020-11-20 08:51:11 -0800206 if( get_option('redfish-allow-deprecated-hostname-patch').enabled())
207 add_project_arguments([
208 '-DBMCWEB_ALLOW_DEPRECATED_HOSTNAME_PATCH'
209 ],
210 language : 'cpp')
211
212 summary({'hostname-patch' :'-DBMCWEB_ALLOW_DEPRECATED_HOSTNAME_PATCH'
213 },section : 'Enabled Features')
214 endif
215
zhanghch050256b692021-06-12 10:26:52 +0800216 if( get_option('redfish-allow-deprecated-power-thermal').enabled())
217 add_project_arguments([
218 '-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL'
219 ],
220 language : 'cpp')
221
222 summary({'power-thermal' :'-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL'
223 },section : 'Enabled Features')
224 endif
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530225 endif
226endif
227
228# Set Compiler Security flags
229
230security_flags = [
231'-fstack-protector-strong',
232'-fPIE',
233'-fPIC',
234'-D_FORTIFY_SOURCE=2',
235'-Wformat',
236'-Wformat-security'
237]
238
239## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
240
241if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
242 add_project_arguments(
243 cxx.get_supported_arguments([
244 security_flags
245 ]),
246 language: 'cpp')
247endif
248
249# Boost dependency configuration
250
251add_project_arguments(
252cxx.get_supported_arguments([
253'-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
254'-DBOOST_ASIO_DISABLE_THREADS',
255'-DBOOST_BEAST_USE_STD_STRING_VIEW',
256'-DBOOST_ERROR_CODE_HEADER_ONLY',
257'-DBOOST_SYSTEM_NO_DEPRECATED',
258'-DBOOST_ASIO_NO_DEPRECATED',
259'-DBOOST_ALL_NO_LIB',
260'-DBOOST_NO_RTTI',
261'-DBOOST_NO_TYPEID',
262'-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
263'-DBOOST_URL_STANDALONE',
Ed Tanous19a88152021-01-11 12:50:47 -0800264'-DBOOST_URL_HEADER_ONLY',
265'-DBOOST_ALLOW_DEPRECATED_HEADERS'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530266]),
267language : 'cpp')
268
269# Find the dependency modules, if not found use meson wrap to get them
270# automatically during the configure step
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800271bmcweb_dependencies = []
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530272
273pam = cxx.find_library('pam', required: get_option('pam'))
274atomic = cxx.find_library('atomic', required: true)
275openssl = dependency('openssl', required : true)
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800276bmcweb_dependencies += [pam, atomic, openssl]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530277
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800278sdbusplus = dependency('sdbusplus',required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530279if not sdbusplus.found()
280 sdbusplus_proj = subproject('sdbusplus', required: true)
281 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
282 sdbusplus = sdbusplus.as_system('system')
283endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800284bmcweb_dependencies += sdbusplus
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530285
286if get_option('rest').enabled()
287 tinyxml = dependency('tinyxml2', required: false)
288 if not tinyxml.found()
289 tinyxml_proj = subproject('tinyxml2', required: true)
290 tinyxml = tinyxml_proj.get_variable('tinyxml2_dep')
291 tinyxml = tinyxml.as_system('system')
292 endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800293 bmcweb_dependencies += tinyxml
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530294endif
295
296systemd = dependency('systemd')
297zlib = dependency('zlib')
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800298bmcweb_dependencies += [systemd, zlib]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530299
300if cxx.has_header('nlohmann/json.hpp')
301 nlohmann_json = declare_dependency()
302else
303 subproject('nlohmann', required: false)
304 nlohmann_json = declare_dependency(
305 include_directories: [
306 'subprojects/nlohmann/single_include',
307 'subprojects/nlohmann/single_include/nlohmann',
308 ]
309 )
Ed Tanousb00dcc22021-02-23 12:52:50 -0800310 nlohmann_json = nlohmann_json.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530311endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800312bmcweb_dependencies += nlohmann_json
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530313
Ed Tanous65f73652021-02-17 10:20:27 -0800314boost = dependency('boost',version : '>=1.75.0', required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530315if not boost.found()
316 subproject('boost', required: false)
Ed Tanous65f73652021-02-17 10:20:27 -0800317 boost_inc = include_directories('subprojects/boost_1_75_0/', is_system:true)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530318 boost = declare_dependency(include_directories : boost_inc)
Ed Tanousb00dcc22021-02-23 12:52:50 -0800319 boost = boost.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530320endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800321bmcweb_dependencies += boost
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530322
323if cxx.has_header('boost/url/url_view.hpp')
324 boost_url = declare_dependency()
325else
326 subproject('boost-url', required: false)
327 boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true)
328 boost_url= declare_dependency(include_directories : boost_url_inc)
Ed Tanousb00dcc22021-02-23 12:52:50 -0800329 boost_url = boost_url.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530330endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800331bmcweb_dependencies += boost_url
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530332
333if get_option('tests').enabled()
334 gtest = dependency('gtest', main: true,disabler: true, required : false)
335 gmock = dependency('gmock', required : false)
336 if not gtest.found() and get_option('tests').enabled()
337 gtest_proj = subproject('gtest', required: true)
338 gtest = gtest_proj.get_variable('gtest_main_dep')
339 gmock = gtest_proj.get_variable('gmock_dep')
340 endif
Ed Tanousb00dcc22021-02-23 12:52:50 -0800341 gtest = gtest.as_system('system')
342 gmock = gmock.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530343endif
344
345# Source files
346
347srcfiles_bmcweb = ['src/webserver_main.cpp','redfish-core/src/error_messages.cpp',
348 'redfish-core/src/utils/json_utils.cpp']
349
Manojkiran Eda17a897d2020-09-12 15:31:58 +0530350srcfiles_unittest = ['include/ut/dbus_utility_test.cpp',
351 'redfish-core/ut/privileges_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530352 'redfish-core/ut/lock_test.cpp',
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500353 'redfish-core/ut/configfile_test.cpp',
Wludzik, Jozef4dbb8ae2020-05-18 11:56:57 +0200354 'redfish-core/ut/time_utils_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530355 'http/ut/utility_test.cpp']
356
357# Gather the Configuration data
358
359conf_data = configuration_data()
Ed Tanous0260d9d2021-02-07 19:31:07 +0000360conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB', get_option('http-body-limit'))
361xss_enabled = get_option('insecure-disable-xss')
Ed Tanousfeaf1502021-02-23 08:53:50 -0800362conf_data.set10('BMCWEB_INSECURE_DISABLE_XSS_PREVENTION', xss_enabled.enabled())
Ed Tanous0260d9d2021-02-07 19:31:07 +0000363conf_data.set('MESON_INSTALL_PREFIX', get_option('prefix'))
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700364conf_data.set('HTTPS_PORT', get_option('https_port'))
Ed Tanous75312982021-02-11 14:26:02 -0800365configure_file(input: 'bmcweb_config.h.in',
366 output: 'bmcweb_config.h',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530367 configuration: conf_data)
368
369# Configure and install systemd unit files
370
371systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
372
373bindir = get_option('prefix') + '/' +get_option('bindir')
374
375summary({
376 'prefix' : get_option('prefix'),
377 'bindir' : bindir,
378 'systemd unit directory' : systemd_system_unit_dir
379 }, section : 'Directories')
380
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700381configure_file(input : 'bmcweb.socket.in',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530382 output : 'bmcweb.socket',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530383 install_dir: systemd_system_unit_dir,
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700384 configuration: conf_data,
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530385 install : true)
386
387configure_file(input : 'bmcweb.service.in',
388 output : 'bmcweb.service',
389 install_dir: systemd_system_unit_dir,
390 configuration: conf_data,
391 install : true)
392
393# Copy pam-webserver to etc/pam.d
394configure_file(input : 'pam-webserver',
395 output : 'webserver',
396 copy : true,
397 install_dir: '/etc/pam.d',
398 install : true)
399
400install_subdir('static', install_dir : 'share/www', strip_directory : true)
401
402# Generate the bmcweb executable and the test binary
403
404executable('bmcweb',srcfiles_bmcweb,
405 include_directories : incdir,
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800406 dependencies: bmcweb_dependencies,
Ed Tanous5e34b672021-02-05 14:21:27 -0800407 link_args: '-Wl,--gc-sections',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530408 install: true,
409 install_dir:bindir)
410
411if(get_option('tests').enabled())
412 foreach src_test : srcfiles_unittest
413 testname = src_test.split('/')[-1].split('.')[0]
414 test(testname,executable(testname,src_test,
415 include_directories : incdir,
416 install_dir: bindir,
417 dependencies: [
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500418 boost, boost_url, gtest,openssl,gmock,nlohmann_json,sdbusplus,pam
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530419 ]))
420 endforeach
421endif