blob: 529b9cbfcc9734db43295c83a27e65af7a7338eb [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' ,
Alan Kuof16f6262020-12-08 19:29:59 +080064'basic-auth' : '-DBMCWEB_ENABLE_BASIC_AUTHENTICATION',
65'session-auth' : '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION',
66'xtoken-auth' : '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION',
67'cookie-auth' : '-DBMCWEB_ENABLE_COOKIE_AUTHENTICATION',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053068'mutual-tls-auth' : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION',
69'pam' : '-DWEBSERVER_ENABLE_PAM',
70'insecure-push-style-notification': '-DBMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING',
71'redfish' : '-DBMCWEB_ENABLE_REDFISH',
72'redfish-bmc-journal' : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL',
73'redfish-cpu-log' : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG',
74'redfish-dbus-log' : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES',
75'redfish-provisioning-feature' : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE',
76'redfish-raw-peci' : '-DBMCWEB_ENABLE_REDFISH_RAW_PECI',
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',
83'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY',
84'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
113if get_option('yocto-deps').disabled()
114 # This is an out of tree build, so enable ibm console flag
115 # for CI purpose.
116 add_project_arguments('-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE', language: 'cpp')
117 summary('ibm-management-console','-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE',section : 'Enabled Features')
118endif
119
120# Add compiler arguments
121
122# -Wpedantic, -Wextra comes by default with warning level
123add_project_arguments(
124 cxx.get_supported_arguments([
125 '-Wold-style-cast',
126 '-Wcast-align',
127 '-Wunused',
128 '-Woverloaded-virtual',
129 '-Wconversion',
130 '-Wsign-conversion',
131 '-Wno-attributes',
132 ]),
133 language: 'cpp'
134)
135
136if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
137add_project_arguments(
138 cxx.get_supported_arguments([
139 '-Weverything',
140 '-Wno-c++98-compat',
141 '-Wno-c++98-compat-pedantic',
142 '-Wno-global-constructors',
143 '-Wno-exit-time-destructors',
144 '-Wno-shadow',
145 '-Wno-used-but-marked-unused',
146 '-Wno-documentation-unknown-command',
147 '-Wno-weak-vtables',
148 '-Wno-documentation',
149 '-Wno-padded',
150 '-Wunused-parameter',
151 '-Wcovered-switch-default',
152 '-Wcomma',
153 '-Wextra-semi',
154 '-Wzero-as-null-pointer-constant',
155 '-Wswitch-enum',
156 '-Wnull-dereference',
157 '-Wdouble-promotion',
158 '-Wformat=2',
159 ]),
160 language:'cpp')
161endif
162
163# if compiler is gnu-gcc , and version is > 8.0 then we add few more
164# compiler arguments , we know that will pass
165
166if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
167
168 ## remove once bmcweb/issues/147 is fixed
169 add_global_link_arguments('-Wno-stringop-overflow',language:['c','cpp'])
170 add_project_arguments('-Wno-stringop-overflow',language:['c','cpp'])
171
172 add_project_arguments(
173 cxx.get_supported_arguments([
174 '-Wduplicated-cond',
175 '-Wduplicated-branches',
176 '-Wlogical-op',
177 '-Wunused-parameter',
178 '-Wnull-dereference',
179 '-Wdouble-promotion',
180 '-Wformat=2',
181 ]),
182 language:'cpp')
183
184 if (get_option('buildtype') != 'plain')
185 if (get_option('b_lto') == true and get_option('optimization')!='0')
186 # Reduce the binary size by removing unnecessary
187 # dynamic symbol table entries
188
189 add_project_arguments(
190 cxx.get_supported_arguments([
191 '-fno-fat-lto-objects',
192 '-fvisibility=hidden',
193 '-fvisibility-inlines-hidden'
194 ]),
195 language: 'cpp')
196
197 if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
198 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
199 endif
200 endif
201
Manojkiran Eda620a6e12020-10-04 21:02:02 +0530202 if( get_option('bmcweb-logging').enabled() or \
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530203 get_option('buildtype').startswith('debug'))
204 add_project_arguments([
205 '-DBMCWEB_ENABLE_LOGGING',
206 '-DBMCWEB_ENABLE_DEBUG'
207 ],
208 language : 'cpp')
209
210 summary({'debug' :'-DBMCWEB_ENABLE_DEBUG',
211 'logging' : '-DBMCWEB_ENABLE_LOGGING',
212 },section : 'Enabled Features')
213 endif
214
215 endif
216endif
217
218# Set Compiler Security flags
219
220security_flags = [
221'-fstack-protector-strong',
222'-fPIE',
223'-fPIC',
224'-D_FORTIFY_SOURCE=2',
225'-Wformat',
226'-Wformat-security'
227]
228
229## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
230
231if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
232 add_project_arguments(
233 cxx.get_supported_arguments([
234 security_flags
235 ]),
236 language: 'cpp')
237endif
238
239# Boost dependency configuration
240
241add_project_arguments(
242cxx.get_supported_arguments([
243'-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
244'-DBOOST_ASIO_DISABLE_THREADS',
245'-DBOOST_BEAST_USE_STD_STRING_VIEW',
246'-DBOOST_ERROR_CODE_HEADER_ONLY',
247'-DBOOST_SYSTEM_NO_DEPRECATED',
248'-DBOOST_ASIO_NO_DEPRECATED',
249'-DBOOST_ALL_NO_LIB',
250'-DBOOST_NO_RTTI',
251'-DBOOST_NO_TYPEID',
252'-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
253'-DBOOST_URL_STANDALONE',
254'-DBOOST_URL_HEADER_ONLY'
255]),
256language : 'cpp')
257
258# Find the dependency modules, if not found use meson wrap to get them
259# automatically during the configure step
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800260bmcweb_dependencies = []
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530261
262pam = cxx.find_library('pam', required: get_option('pam'))
263atomic = cxx.find_library('atomic', required: true)
264openssl = dependency('openssl', required : true)
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800265bmcweb_dependencies += [pam, atomic, openssl]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530266
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800267sdbusplus = dependency('sdbusplus',required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530268if not sdbusplus.found()
269 sdbusplus_proj = subproject('sdbusplus', required: true)
270 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
271 sdbusplus = sdbusplus.as_system('system')
272endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800273bmcweb_dependencies += sdbusplus
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530274
275if get_option('rest').enabled()
276 tinyxml = dependency('tinyxml2', required: false)
277 if not tinyxml.found()
278 tinyxml_proj = subproject('tinyxml2', required: true)
279 tinyxml = tinyxml_proj.get_variable('tinyxml2_dep')
280 tinyxml = tinyxml.as_system('system')
281 endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800282 bmcweb_dependencies += tinyxml
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530283endif
284
285systemd = dependency('systemd')
286zlib = dependency('zlib')
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800287bmcweb_dependencies += [systemd, zlib]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530288
289if cxx.has_header('nlohmann/json.hpp')
290 nlohmann_json = declare_dependency()
291else
292 subproject('nlohmann', required: false)
293 nlohmann_json = declare_dependency(
294 include_directories: [
295 'subprojects/nlohmann/single_include',
296 'subprojects/nlohmann/single_include/nlohmann',
297 ]
298 )
299endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800300bmcweb_dependencies += nlohmann_json
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530301
Ed Tanous309b0832020-10-06 14:39:08 -0700302boost = dependency('boost',version : '>=1.73.0', required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530303if not boost.found()
304 subproject('boost', required: false)
305 boost_inc = include_directories('subprojects/boost_1_73_0/', is_system:true)
306 boost = declare_dependency(include_directories : boost_inc)
307endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800308bmcweb_dependencies += boost
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530309
310if cxx.has_header('boost/url/url_view.hpp')
311 boost_url = declare_dependency()
312else
313 subproject('boost-url', required: false)
314 boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true)
315 boost_url= declare_dependency(include_directories : boost_url_inc)
316endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800317bmcweb_dependencies += boost_url
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530318
319if get_option('tests').enabled()
320 gtest = dependency('gtest', main: true,disabler: true, required : false)
321 gmock = dependency('gmock', required : false)
322 if not gtest.found() and get_option('tests').enabled()
323 gtest_proj = subproject('gtest', required: true)
324 gtest = gtest_proj.get_variable('gtest_main_dep')
325 gmock = gtest_proj.get_variable('gmock_dep')
326 endif
327endif
328
329# Source files
330
331srcfiles_bmcweb = ['src/webserver_main.cpp','redfish-core/src/error_messages.cpp',
332 'redfish-core/src/utils/json_utils.cpp']
333
Manojkiran Eda17a897d2020-09-12 15:31:58 +0530334srcfiles_unittest = ['include/ut/dbus_utility_test.cpp',
335 'redfish-core/ut/privileges_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530336 'redfish-core/ut/lock_test.cpp',
337 'http/ut/utility_test.cpp']
338
339# Gather the Configuration data
340
341conf_data = configuration_data()
342conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB',get_option('http-body-limit'))
343conf_data.set('MESON_INSTALL_PREFIX',get_option('prefix'))
344configure_file(output: 'config.h',
345 configuration: conf_data)
346
347# Configure and install systemd unit files
348
349systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
350
351bindir = get_option('prefix') + '/' +get_option('bindir')
352
353summary({
354 'prefix' : get_option('prefix'),
355 'bindir' : bindir,
356 'systemd unit directory' : systemd_system_unit_dir
357 }, section : 'Directories')
358
359configure_file(input : 'bmcweb.socket',
360 output : 'bmcweb.socket',
361 copy : true,
362 install_dir: systemd_system_unit_dir,
363 install : true)
364
365configure_file(input : 'bmcweb.service.in',
366 output : 'bmcweb.service',
367 install_dir: systemd_system_unit_dir,
368 configuration: conf_data,
369 install : true)
370
371# Copy pam-webserver to etc/pam.d
372configure_file(input : 'pam-webserver',
373 output : 'webserver',
374 copy : true,
375 install_dir: '/etc/pam.d',
376 install : true)
377
378install_subdir('static', install_dir : 'share/www', strip_directory : true)
379
380# Generate the bmcweb executable and the test binary
381
382executable('bmcweb',srcfiles_bmcweb,
383 include_directories : incdir,
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800384 dependencies: bmcweb_dependencies,
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: [
Sathish Vae907c72020-12-02 17:49:34 +0530395 boost, boost_url, gtest,openssl,gmock,nlohmann_json,sdbusplus
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530396 ]))
397 endforeach
398endif