blob: 6dd903bb3f2da581842d1df805deba7d4c3769c3 [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',
Ed Tanous65f73652021-02-17 10:20:27 -080011 'cpp_rtti=false'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053012 ])
13
14# Project related links
15
16project_pretty_name = 'bmcweb'
17project_url = 'https://github.com/openbmc/' + project_pretty_name
18project_issues_url = project_url + '/issues/new'
19summary('Issues',project_issues_url, section: 'Report Issues')
20
21# Validate the c++ Standard
22
23if get_option('cpp_std') != 'c++17'
24 error('This project requires c++17 support')
25endif
26
27# Get compiler and default build type
28
29cxx = meson.get_compiler('cpp')
30build = get_option('buildtype')
31optimization = get_option('optimization')
32summary('Build Type',build, section : 'Build Info')
33summary('Optimization',optimization, section : 'Build Info')
34
Ed Tanous5e34b672021-02-05 14:21:27 -080035
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053036# remove debug information for minsize buildtype
37if(get_option('buildtype') == 'minsize')
Ed Tanous5e34b672021-02-05 14:21:27 -080038 add_project_arguments(['-fdata-sections', '-ffunction-sections'], language : 'cpp')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053039 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
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
208 endif
209endif
210
211# Set Compiler Security flags
212
213security_flags = [
214'-fstack-protector-strong',
215'-fPIE',
216'-fPIC',
217'-D_FORTIFY_SOURCE=2',
218'-Wformat',
219'-Wformat-security'
220]
221
222## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
223
224if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
225 add_project_arguments(
226 cxx.get_supported_arguments([
227 security_flags
228 ]),
229 language: 'cpp')
230endif
231
232# Boost dependency configuration
233
234add_project_arguments(
235cxx.get_supported_arguments([
236'-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
237'-DBOOST_ASIO_DISABLE_THREADS',
238'-DBOOST_BEAST_USE_STD_STRING_VIEW',
239'-DBOOST_ERROR_CODE_HEADER_ONLY',
240'-DBOOST_SYSTEM_NO_DEPRECATED',
241'-DBOOST_ASIO_NO_DEPRECATED',
242'-DBOOST_ALL_NO_LIB',
243'-DBOOST_NO_RTTI',
244'-DBOOST_NO_TYPEID',
245'-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
246'-DBOOST_URL_STANDALONE',
Ed Tanous19a88152021-01-11 12:50:47 -0800247'-DBOOST_URL_HEADER_ONLY',
248'-DBOOST_ALLOW_DEPRECATED_HEADERS'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530249]),
250language : 'cpp')
251
252# Find the dependency modules, if not found use meson wrap to get them
253# automatically during the configure step
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800254bmcweb_dependencies = []
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530255
256pam = cxx.find_library('pam', required: get_option('pam'))
257atomic = cxx.find_library('atomic', required: true)
258openssl = dependency('openssl', required : true)
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800259bmcweb_dependencies += [pam, atomic, openssl]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530260
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800261sdbusplus = dependency('sdbusplus',required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530262if 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
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800267bmcweb_dependencies += sdbusplus
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530268
269if get_option('rest').enabled()
270 tinyxml = dependency('tinyxml2', required: false)
271 if not tinyxml.found()
272 tinyxml_proj = subproject('tinyxml2', required: true)
273 tinyxml = tinyxml_proj.get_variable('tinyxml2_dep')
274 tinyxml = tinyxml.as_system('system')
275 endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800276 bmcweb_dependencies += tinyxml
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530277endif
278
279systemd = dependency('systemd')
280zlib = dependency('zlib')
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800281bmcweb_dependencies += [systemd, zlib]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530282
283if cxx.has_header('nlohmann/json.hpp')
284 nlohmann_json = declare_dependency()
285else
286 subproject('nlohmann', required: false)
287 nlohmann_json = declare_dependency(
288 include_directories: [
289 'subprojects/nlohmann/single_include',
290 'subprojects/nlohmann/single_include/nlohmann',
291 ]
292 )
293endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800294bmcweb_dependencies += nlohmann_json
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530295
Ed Tanous65f73652021-02-17 10:20:27 -0800296boost = dependency('boost',version : '>=1.75.0', required : false)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530297if not boost.found()
298 subproject('boost', required: false)
Ed Tanous65f73652021-02-17 10:20:27 -0800299 boost_inc = include_directories('subprojects/boost_1_75_0/', is_system:true)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530300 boost = declare_dependency(include_directories : boost_inc)
301endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800302bmcweb_dependencies += boost
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530303
304if cxx.has_header('boost/url/url_view.hpp')
305 boost_url = declare_dependency()
306else
307 subproject('boost-url', required: false)
308 boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true)
309 boost_url= declare_dependency(include_directories : boost_url_inc)
310endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800311bmcweb_dependencies += boost_url
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530312
313if get_option('tests').enabled()
314 gtest = dependency('gtest', main: true,disabler: true, required : false)
315 gmock = dependency('gmock', required : false)
316 if not gtest.found() and get_option('tests').enabled()
317 gtest_proj = subproject('gtest', required: true)
318 gtest = gtest_proj.get_variable('gtest_main_dep')
319 gmock = gtest_proj.get_variable('gmock_dep')
320 endif
321endif
322
323# Source files
324
325srcfiles_bmcweb = ['src/webserver_main.cpp','redfish-core/src/error_messages.cpp',
326 'redfish-core/src/utils/json_utils.cpp']
327
Manojkiran Eda17a897d2020-09-12 15:31:58 +0530328srcfiles_unittest = ['include/ut/dbus_utility_test.cpp',
329 'redfish-core/ut/privileges_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530330 'redfish-core/ut/lock_test.cpp',
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500331 'redfish-core/ut/configfile_test.cpp',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530332 'http/ut/utility_test.cpp']
333
334# Gather the Configuration data
335
336conf_data = configuration_data()
337conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB',get_option('http-body-limit'))
338conf_data.set('MESON_INSTALL_PREFIX',get_option('prefix'))
339configure_file(output: 'config.h',
340 configuration: conf_data)
341
342# Configure and install systemd unit files
343
344systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
345
346bindir = get_option('prefix') + '/' +get_option('bindir')
347
348summary({
349 'prefix' : get_option('prefix'),
350 'bindir' : bindir,
351 'systemd unit directory' : systemd_system_unit_dir
352 }, section : 'Directories')
353
354configure_file(input : 'bmcweb.socket',
355 output : 'bmcweb.socket',
356 copy : true,
357 install_dir: systemd_system_unit_dir,
358 install : true)
359
360configure_file(input : 'bmcweb.service.in',
361 output : 'bmcweb.service',
362 install_dir: systemd_system_unit_dir,
363 configuration: conf_data,
364 install : true)
365
366# Copy pam-webserver to etc/pam.d
367configure_file(input : 'pam-webserver',
368 output : 'webserver',
369 copy : true,
370 install_dir: '/etc/pam.d',
371 install : true)
372
373install_subdir('static', install_dir : 'share/www', strip_directory : true)
374
375# Generate the bmcweb executable and the test binary
376
377executable('bmcweb',srcfiles_bmcweb,
378 include_directories : incdir,
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800379 dependencies: bmcweb_dependencies,
Ed Tanous5e34b672021-02-05 14:21:27 -0800380 link_args: '-Wl,--gc-sections',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530381 install: true,
382 install_dir:bindir)
383
384if(get_option('tests').enabled())
385 foreach src_test : srcfiles_unittest
386 testname = src_test.split('/')[-1].split('.')[0]
387 test(testname,executable(testname,src_test,
388 include_directories : incdir,
389 install_dir: bindir,
390 dependencies: [
Sunitha Harish7c0bbe72020-07-30 08:25:28 -0500391 boost, boost_url, gtest,openssl,gmock,nlohmann_json,sdbusplus,pam
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530392 ]))
393 endforeach
394endif