blob: 5079bfcb35bb2519bdc7a54f526bd6fde4734565 [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',
11# enable when https://github.com/chriskohlhoff/asio/issues/533
12# is resolved. ASIO default executor doesn't build with no-rtti
13 #'cpp_rtti=false'
14 ])
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
37# remove debug information for minsize buildtype
38if(get_option('buildtype') == 'minsize')
39 add_project_arguments('-DNDEBUG', language : 'cpp')
40endif
41
42# Disable lto when compiling with no optimization
43if(get_option('optimization') == '0')
44 add_project_arguments('-fno-lto', language: 'cpp')
45 message('Disabling lto & its supported features as optimization is disabled')
46endif
47
48# Include Directories
49
50incdir = include_directories('include','redfish-core/include',
51 'redfish-core/lib','http')
52
53# Get the options and enable the respective features
54## create a MAP of "options : feature_flag"
55
56feature_map = {
57'insecure-disable-auth' : '-DBMCWEB_INSECURE_DISABLE_AUTHENTICATION',
58'insecure-disable-csrf' : '-DBMCWEB_INSECURE_DISABLE_CSRF_PREVENTION',
59'insecure-disable-ssl' : '-DBMCWEB_INSECURE_DISABLE_SSL',
60'insecure-disable-xss' : '-DBMCWEB_INSECURE_DISABLE_XSS_PREVENTION',
61'host-serial-socket' : '-DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET',
62'ibm-management-console' : '-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE',
63'kvm' : '-DBMCWEB_ENABLE_KVM' ,
64'mutual-tls-auth' : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION',
65'pam' : '-DWEBSERVER_ENABLE_PAM',
66'insecure-push-style-notification': '-DBMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING',
67'redfish' : '-DBMCWEB_ENABLE_REDFISH',
68'redfish-bmc-journal' : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL',
69'redfish-cpu-log' : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG',
70'redfish-dbus-log' : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES',
71'redfish-provisioning-feature' : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE',
72'redfish-raw-peci' : '-DBMCWEB_ENABLE_REDFISH_RAW_PECI',
Ravi Teja3fad0d52020-10-16 11:18:02 -050073'redfish-dump-log' : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053074'rest' : '-DBMCWEB_ENABLE_DBUS_REST',
75'insecure-sensor-override' : '-DBMCWEB_INSECURE_UNRESTRICTED_SENSOR_OVERRIDE',
76'static-hosting' : '-DBMCWEB_ENABLE_STATIC_HOSTING',
77'insecure-tftp-update' : '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE',
78'validate-unsecure-feature' : '-DBMCWEB_ENABLE_VALIDATION_UNSECURE_FEATURE',
79'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY',
80'vm-websocket' : '-DBMCWEB_ENABLE_VM_WEBSOCKET',
81}
82
83# Get the options status and build a project summary to show which flags are
84# being enabled during the configuration time.
85
86foreach option_key,option_value : feature_map
87 if(get_option(option_key).enabled())
88 if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl')
89 if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled())
90 add_project_arguments(option_value,language:'cpp')
91 summary(option_key,option_value, section : 'Enabled Features')
92 endif
93 else
94 summary(option_key,option_value, section : 'Enabled Features')
95 add_project_arguments(option_value,language:'cpp')
96 endif
97 else
98 if(option_key == 'insecure-disable-ssl')
99 summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features')
100 add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp')
101 endif
102 endif
103endforeach
104
105if(get_option('tests').enabled())
106 summary('unittest','NA', section : 'Enabled Features')
107endif
108
109if get_option('yocto-deps').disabled()
110 # This is an out of tree build, so enable ibm console flag
111 # for CI purpose.
112 add_project_arguments('-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE', language: 'cpp')
113 summary('ibm-management-console','-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE',section : 'Enabled Features')
114endif
115
116# Add compiler arguments
117
118# -Wpedantic, -Wextra comes by default with warning level
119add_project_arguments(
120 cxx.get_supported_arguments([
121 '-Wold-style-cast',
122 '-Wcast-align',
123 '-Wunused',
124 '-Woverloaded-virtual',
125 '-Wconversion',
126 '-Wsign-conversion',
127 '-Wno-attributes',
128 ]),
129 language: 'cpp'
130)
131
132if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
133add_project_arguments(
134 cxx.get_supported_arguments([
135 '-Weverything',
136 '-Wno-c++98-compat',
137 '-Wno-c++98-compat-pedantic',
138 '-Wno-global-constructors',
139 '-Wno-exit-time-destructors',
140 '-Wno-shadow',
141 '-Wno-used-but-marked-unused',
142 '-Wno-documentation-unknown-command',
143 '-Wno-weak-vtables',
144 '-Wno-documentation',
145 '-Wno-padded',
146 '-Wunused-parameter',
147 '-Wcovered-switch-default',
148 '-Wcomma',
149 '-Wextra-semi',
150 '-Wzero-as-null-pointer-constant',
151 '-Wswitch-enum',
152 '-Wnull-dereference',
153 '-Wdouble-promotion',
154 '-Wformat=2',
155 ]),
156 language:'cpp')
157endif
158
159# if compiler is gnu-gcc , and version is > 8.0 then we add few more
160# compiler arguments , we know that will pass
161
162if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
163
164 ## remove once bmcweb/issues/147 is fixed
165 add_global_link_arguments('-Wno-stringop-overflow',language:['c','cpp'])
166 add_project_arguments('-Wno-stringop-overflow',language:['c','cpp'])
167
168 add_project_arguments(
169 cxx.get_supported_arguments([
170 '-Wduplicated-cond',
171 '-Wduplicated-branches',
172 '-Wlogical-op',
173 '-Wunused-parameter',
174 '-Wnull-dereference',
175 '-Wdouble-promotion',
176 '-Wformat=2',
177 ]),
178 language:'cpp')
179
180 if (get_option('buildtype') != 'plain')
181 if (get_option('b_lto') == true and get_option('optimization')!='0')
182 # Reduce the binary size by removing unnecessary
183 # dynamic symbol table entries
184
185 add_project_arguments(
186 cxx.get_supported_arguments([
187 '-fno-fat-lto-objects',
188 '-fvisibility=hidden',
189 '-fvisibility-inlines-hidden'
190 ]),
191 language: 'cpp')
192
193 if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
194 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
195 endif
196 endif
197
Manojkiran Eda620a6e12020-10-04 21:02:02 +0530198 if( get_option('bmcweb-logging').enabled() or \
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530199 get_option('buildtype').startswith('debug'))
200 add_project_arguments([
201 '-DBMCWEB_ENABLE_LOGGING',
202 '-DBMCWEB_ENABLE_DEBUG'
203 ],
204 language : 'cpp')
205
206 summary({'debug' :'-DBMCWEB_ENABLE_DEBUG',
207 'logging' : '-DBMCWEB_ENABLE_LOGGING',
208 },section : 'Enabled Features')
209 endif
210
211 endif
212endif
213
214# Set Compiler Security flags
215
216security_flags = [
217'-fstack-protector-strong',
218'-fPIE',
219'-fPIC',
220'-D_FORTIFY_SOURCE=2',
221'-Wformat',
222'-Wformat-security'
223]
224
225## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
226
227if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
228 add_project_arguments(
229 cxx.get_supported_arguments([
230 security_flags
231 ]),
232 language: 'cpp')
233endif
234
235# Boost dependency configuration
236
237add_project_arguments(
238cxx.get_supported_arguments([
239'-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
240'-DBOOST_ASIO_DISABLE_THREADS',
241'-DBOOST_BEAST_USE_STD_STRING_VIEW',
242'-DBOOST_ERROR_CODE_HEADER_ONLY',
243'-DBOOST_SYSTEM_NO_DEPRECATED',
244'-DBOOST_ASIO_NO_DEPRECATED',
245'-DBOOST_ALL_NO_LIB',
246'-DBOOST_NO_RTTI',
247'-DBOOST_NO_TYPEID',
248'-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
249'-DBOOST_URL_STANDALONE',
250'-DBOOST_URL_HEADER_ONLY'
251]),
252language : 'cpp')
253
254# Find the dependency modules, if not found use meson wrap to get them
255# automatically during the configure step
256
257pam = cxx.find_library('pam', required: get_option('pam'))
258atomic = cxx.find_library('atomic', required: true)
259openssl = dependency('openssl', required : true)
260sdbusplus = dependency('sdbusplus',required : false)
261
262if not sdbusplus.found()
263 sdbusplus_proj = subproject('sdbusplus', required: true)
264 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
265 sdbusplus = sdbusplus.as_system('system')
266endif
267
268if get_option('rest').enabled()
269 tinyxml = dependency('tinyxml2', required: false)
270 if not tinyxml.found()
271 tinyxml_proj = subproject('tinyxml2', required: true)
272 tinyxml = tinyxml_proj.get_variable('tinyxml2_dep')
273 tinyxml = tinyxml.as_system('system')
274 endif
275endif
276
277systemd = dependency('systemd')
278zlib = dependency('zlib')
279
280if cxx.has_header('nlohmann/json.hpp')
281 nlohmann_json = declare_dependency()
282else
283 subproject('nlohmann', required: false)
284 nlohmann_json = declare_dependency(
285 include_directories: [
286 'subprojects/nlohmann/single_include',
287 'subprojects/nlohmann/single_include/nlohmann',
288 ]
289 )
290endif
291
Ed Tanous309b0832020-10-06 14:39:08 -0700292boost = dependency('boost',version : '>=1.73.0', required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530293if not boost.found()
294 subproject('boost', required: false)
295 boost_inc = include_directories('subprojects/boost_1_73_0/', is_system:true)
296 boost = declare_dependency(include_directories : boost_inc)
297endif
298
299if cxx.has_header('boost/url/url_view.hpp')
300 boost_url = declare_dependency()
301else
302 subproject('boost-url', required: false)
303 boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true)
304 boost_url= declare_dependency(include_directories : boost_url_inc)
305endif
306
307if get_option('tests').enabled()
308 gtest = dependency('gtest', main: true,disabler: true, required : false)
309 gmock = dependency('gmock', required : false)
310 if not gtest.found() and get_option('tests').enabled()
311 gtest_proj = subproject('gtest', required: true)
312 gtest = gtest_proj.get_variable('gtest_main_dep')
313 gmock = gtest_proj.get_variable('gmock_dep')
314 endif
315endif
316
317# Source files
318
319srcfiles_bmcweb = ['src/webserver_main.cpp','redfish-core/src/error_messages.cpp',
320 'redfish-core/src/utils/json_utils.cpp']
321
Manojkiran Eda27987562020-10-04 12:26:12 +0530322srcfiles_unittest = ['redfish-core/ut/privileges_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530323 'redfish-core/ut/lock_test.cpp',
324 'http/ut/utility_test.cpp']
325
326# Gather the Configuration data
327
328conf_data = configuration_data()
329conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB',get_option('http-body-limit'))
330conf_data.set('MESON_INSTALL_PREFIX',get_option('prefix'))
331configure_file(output: 'config.h',
332 configuration: conf_data)
333
334# Configure and install systemd unit files
335
336systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
337
338bindir = get_option('prefix') + '/' +get_option('bindir')
339
340summary({
341 'prefix' : get_option('prefix'),
342 'bindir' : bindir,
343 'systemd unit directory' : systemd_system_unit_dir
344 }, section : 'Directories')
345
346configure_file(input : 'bmcweb.socket',
347 output : 'bmcweb.socket',
348 copy : true,
349 install_dir: systemd_system_unit_dir,
350 install : true)
351
352configure_file(input : 'bmcweb.service.in',
353 output : 'bmcweb.service',
354 install_dir: systemd_system_unit_dir,
355 configuration: conf_data,
356 install : true)
357
358# Copy pam-webserver to etc/pam.d
359configure_file(input : 'pam-webserver',
360 output : 'webserver',
361 copy : true,
362 install_dir: '/etc/pam.d',
363 install : true)
364
365install_subdir('static', install_dir : 'share/www', strip_directory : true)
366
367# Generate the bmcweb executable and the test binary
368
369executable('bmcweb',srcfiles_bmcweb,
370 include_directories : incdir,
371 dependencies: [
372 boost, boost_url, pam, atomic, sdbusplus, openssl,
Manojkiran Eda94217992020-10-04 14:00:27 +0530373 tinyxml, systemd, zlib, nlohmann_json
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530374 ],
375 install: true,
376 install_dir:bindir)
377
378if(get_option('tests').enabled())
379 foreach src_test : srcfiles_unittest
380 testname = src_test.split('/')[-1].split('.')[0]
381 test(testname,executable(testname,src_test,
382 include_directories : incdir,
383 install_dir: bindir,
384 dependencies: [
Manojkiran Eda94217992020-10-04 14:00:27 +0530385 boost, boost_url, gtest,openssl,gmock,nlohmann_json
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530386 ]))
387 endforeach
388endif