blob: a08c8dd3e9e5df3ff0d9c39f771e93c9dba2c3cc [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',
77'redfish-raw-peci' : '-DBMCWEB_ENABLE_REDFISH_RAW_PECI',
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',
80'insecure-sensor-override' : '-DBMCWEB_INSECURE_UNRESTRICTED_SENSOR_OVERRIDE',
81'static-hosting' : '-DBMCWEB_ENABLE_STATIC_HOSTING',
82'insecure-tftp-update' : '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE',
83'validate-unsecure-feature' : '-DBMCWEB_ENABLE_VALIDATION_UNSECURE_FEATURE',
84'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY',
85'vm-websocket' : '-DBMCWEB_ENABLE_VM_WEBSOCKET',
86}
87
88# Get the options status and build a project summary to show which flags are
89# being enabled during the configuration time.
90
91foreach option_key,option_value : feature_map
92 if(get_option(option_key).enabled())
93 if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl')
94 if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled())
95 add_project_arguments(option_value,language:'cpp')
96 summary(option_key,option_value, section : 'Enabled Features')
97 endif
98 else
99 summary(option_key,option_value, section : 'Enabled Features')
100 add_project_arguments(option_value,language:'cpp')
101 endif
102 else
103 if(option_key == 'insecure-disable-ssl')
104 summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features')
105 add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp')
106 endif
107 endif
108endforeach
109
110if(get_option('tests').enabled())
111 summary('unittest','NA', section : 'Enabled Features')
112endif
113
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530114# Add compiler arguments
115
116# -Wpedantic, -Wextra comes by default with warning level
117add_project_arguments(
118 cxx.get_supported_arguments([
119 '-Wold-style-cast',
120 '-Wcast-align',
121 '-Wunused',
122 '-Woverloaded-virtual',
123 '-Wconversion',
124 '-Wsign-conversion',
125 '-Wno-attributes',
126 ]),
127 language: 'cpp'
128)
129
130if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
131add_project_arguments(
132 cxx.get_supported_arguments([
133 '-Weverything',
134 '-Wno-c++98-compat',
135 '-Wno-c++98-compat-pedantic',
136 '-Wno-global-constructors',
137 '-Wno-exit-time-destructors',
138 '-Wno-shadow',
139 '-Wno-used-but-marked-unused',
140 '-Wno-documentation-unknown-command',
141 '-Wno-weak-vtables',
142 '-Wno-documentation',
143 '-Wno-padded',
144 '-Wunused-parameter',
145 '-Wcovered-switch-default',
146 '-Wcomma',
147 '-Wextra-semi',
148 '-Wzero-as-null-pointer-constant',
149 '-Wswitch-enum',
150 '-Wnull-dereference',
151 '-Wdouble-promotion',
152 '-Wformat=2',
153 ]),
154 language:'cpp')
155endif
156
157# if compiler is gnu-gcc , and version is > 8.0 then we add few more
158# compiler arguments , we know that will pass
159
160if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
161
162 ## remove once bmcweb/issues/147 is fixed
163 add_global_link_arguments('-Wno-stringop-overflow',language:['c','cpp'])
164 add_project_arguments('-Wno-stringop-overflow',language:['c','cpp'])
165
166 add_project_arguments(
167 cxx.get_supported_arguments([
168 '-Wduplicated-cond',
169 '-Wduplicated-branches',
170 '-Wlogical-op',
171 '-Wunused-parameter',
172 '-Wnull-dereference',
173 '-Wdouble-promotion',
174 '-Wformat=2',
175 ]),
176 language:'cpp')
177
178 if (get_option('buildtype') != 'plain')
179 if (get_option('b_lto') == true and get_option('optimization')!='0')
180 # Reduce the binary size by removing unnecessary
181 # dynamic symbol table entries
182
183 add_project_arguments(
184 cxx.get_supported_arguments([
185 '-fno-fat-lto-objects',
186 '-fvisibility=hidden',
187 '-fvisibility-inlines-hidden'
188 ]),
189 language: 'cpp')
190
191 if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
192 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
193 endif
194 endif
195
Manojkiran Eda620a6e12020-10-04 21:02:02 +0530196 if( get_option('bmcweb-logging').enabled() or \
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530197 get_option('buildtype').startswith('debug'))
198 add_project_arguments([
199 '-DBMCWEB_ENABLE_LOGGING',
200 '-DBMCWEB_ENABLE_DEBUG'
201 ],
202 language : 'cpp')
203
204 summary({'debug' :'-DBMCWEB_ENABLE_DEBUG',
205 'logging' : '-DBMCWEB_ENABLE_LOGGING',
206 },section : 'Enabled Features')
207 endif
208
209 endif
210endif
211
212# Set Compiler Security flags
213
214security_flags = [
215'-fstack-protector-strong',
216'-fPIE',
217'-fPIC',
218'-D_FORTIFY_SOURCE=2',
219'-Wformat',
220'-Wformat-security'
221]
222
223## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
224
225if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
226 add_project_arguments(
227 cxx.get_supported_arguments([
228 security_flags
229 ]),
230 language: 'cpp')
231endif
232
233# Boost dependency configuration
234
235add_project_arguments(
236cxx.get_supported_arguments([
237'-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
238'-DBOOST_ASIO_DISABLE_THREADS',
239'-DBOOST_BEAST_USE_STD_STRING_VIEW',
240'-DBOOST_ERROR_CODE_HEADER_ONLY',
241'-DBOOST_SYSTEM_NO_DEPRECATED',
242'-DBOOST_ASIO_NO_DEPRECATED',
243'-DBOOST_ALL_NO_LIB',
244'-DBOOST_NO_RTTI',
245'-DBOOST_NO_TYPEID',
246'-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
247'-DBOOST_URL_STANDALONE',
Ed Tanous19a88152021-01-11 12:50:47 -0800248'-DBOOST_URL_HEADER_ONLY',
249'-DBOOST_ALLOW_DEPRECATED_HEADERS'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530250]),
251language : 'cpp')
252
253# Find the dependency modules, if not found use meson wrap to get them
254# automatically during the configure step
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800255bmcweb_dependencies = []
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530256
257pam = cxx.find_library('pam', required: get_option('pam'))
258atomic = cxx.find_library('atomic', required: true)
259openssl = dependency('openssl', required : true)
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800260bmcweb_dependencies += [pam, atomic, openssl]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530261
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800262sdbusplus = dependency('sdbusplus',required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530263if not sdbusplus.found()
264 sdbusplus_proj = subproject('sdbusplus', required: true)
265 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
266 sdbusplus = sdbusplus.as_system('system')
267endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800268bmcweb_dependencies += sdbusplus
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530269
270if get_option('rest').enabled()
271 tinyxml = dependency('tinyxml2', required: false)
272 if not tinyxml.found()
273 tinyxml_proj = subproject('tinyxml2', required: true)
274 tinyxml = tinyxml_proj.get_variable('tinyxml2_dep')
275 tinyxml = tinyxml.as_system('system')
276 endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800277 bmcweb_dependencies += tinyxml
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530278endif
279
280systemd = dependency('systemd')
281zlib = dependency('zlib')
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800282bmcweb_dependencies += [systemd, zlib]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530283
284if cxx.has_header('nlohmann/json.hpp')
285 nlohmann_json = declare_dependency()
286else
287 subproject('nlohmann', required: false)
288 nlohmann_json = declare_dependency(
289 include_directories: [
290 'subprojects/nlohmann/single_include',
291 'subprojects/nlohmann/single_include/nlohmann',
292 ]
293 )
294endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800295bmcweb_dependencies += nlohmann_json
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530296
Ed Tanous65f73652021-02-17 10:20:27 -0800297boost = dependency('boost',version : '>=1.75.0', required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530298if not boost.found()
299 subproject('boost', required: false)
Ed Tanous65f73652021-02-17 10:20:27 -0800300 boost_inc = include_directories('subprojects/boost_1_75_0/', is_system:true)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530301 boost = declare_dependency(include_directories : boost_inc)
302endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800303bmcweb_dependencies += boost
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530304
305if cxx.has_header('boost/url/url_view.hpp')
306 boost_url = declare_dependency()
307else
308 subproject('boost-url', required: false)
309 boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true)
310 boost_url= declare_dependency(include_directories : boost_url_inc)
311endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800312bmcweb_dependencies += boost_url
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530313
314if get_option('tests').enabled()
315 gtest = dependency('gtest', main: true,disabler: true, required : false)
316 gmock = dependency('gmock', required : false)
317 if not gtest.found() and get_option('tests').enabled()
318 gtest_proj = subproject('gtest', required: true)
319 gtest = gtest_proj.get_variable('gtest_main_dep')
320 gmock = gtest_proj.get_variable('gmock_dep')
321 endif
322endif
323
324# Source files
325
326srcfiles_bmcweb = ['src/webserver_main.cpp','redfish-core/src/error_messages.cpp',
327 'redfish-core/src/utils/json_utils.cpp']
328
Manojkiran Eda17a897d2020-09-12 15:31:58 +0530329srcfiles_unittest = ['include/ut/dbus_utility_test.cpp',
330 'redfish-core/ut/privileges_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530331 'redfish-core/ut/lock_test.cpp',
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500332 'redfish-core/ut/configfile_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530333 'http/ut/utility_test.cpp']
334
335# Gather the Configuration data
336
337conf_data = configuration_data()
Ed Tanous0260d9d2021-02-07 19:31:07 +0000338conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB', get_option('http-body-limit'))
339xss_enabled = get_option('insecure-disable-xss')
340conf_data.set10('BMCWEB_INSECURE_DISABLE_XSS_PREVENTION', xss_enabled)
341conf_data.set('MESON_INSTALL_PREFIX', get_option('prefix'))
342configure_file(input: 'config.h.in',
343 output: 'config.h',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530344 configuration: conf_data)
345
346# Configure and install systemd unit files
347
348systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
349
350bindir = get_option('prefix') + '/' +get_option('bindir')
351
352summary({
353 'prefix' : get_option('prefix'),
354 'bindir' : bindir,
355 'systemd unit directory' : systemd_system_unit_dir
356 }, section : 'Directories')
357
358configure_file(input : 'bmcweb.socket',
359 output : 'bmcweb.socket',
360 copy : true,
361 install_dir: systemd_system_unit_dir,
362 install : true)
363
364configure_file(input : 'bmcweb.service.in',
365 output : 'bmcweb.service',
366 install_dir: systemd_system_unit_dir,
367 configuration: conf_data,
368 install : true)
369
370# Copy pam-webserver to etc/pam.d
371configure_file(input : 'pam-webserver',
372 output : 'webserver',
373 copy : true,
374 install_dir: '/etc/pam.d',
375 install : true)
376
377install_subdir('static', install_dir : 'share/www', strip_directory : true)
378
379# Generate the bmcweb executable and the test binary
380
381executable('bmcweb',srcfiles_bmcweb,
382 include_directories : incdir,
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800383 dependencies: bmcweb_dependencies,
Ed Tanous5e34b672021-02-05 14:21:27 -0800384 link_args: '-Wl,--gc-sections',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530385 install: true,
386 install_dir:bindir)
387
388if(get_option('tests').enabled())
389 foreach src_test : srcfiles_unittest
390 testname = src_test.split('/')[-1].split('.')[0]
391 test(testname,executable(testname,src_test,
392 include_directories : incdir,
393 install_dir: bindir,
394 dependencies: [
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500395 boost, boost_url, gtest,openssl,gmock,nlohmann_json,sdbusplus,pam
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530396 ]))
397 endforeach
398endif