blob: 01417f2b3b1ca873681716d57c36375e267636f8 [file] [log] [blame]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +05301project('bmcweb', 'cpp',
2 version : '1.0',
Patrick Williamsc52ee722021-10-06 15:17:42 -05003 meson_version: '>=0.57.0',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +05304 default_options: [
5 'werror=true',
6 'warning_level=3',
Patrick Williamsc52ee722021-10-06 15:17:42 -05007 'cpp_std=c++20',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +05308 '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
Patrick Williamsc52ee722021-10-06 15:17:42 -050025if get_option('cpp_std') != 'c++20'
26 error('This project requires c++20 support')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053027endif
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
Ed Tanouscf2f9322021-09-22 15:34:41 -070052incdir = include_directories(
53 'include',
54 'redfish-core/include',
55 'redfish-core/lib',
56 'http'
57)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053058
59# Get the options and enable the respective features
60## create a MAP of "options : feature_flag"
61
62feature_map = {
Manojkiran Eda2d74fbc2021-10-28 12:39:49 +053063 'basic-auth' : '-DBMCWEB_ENABLE_BASIC_AUTHENTICATION',
64 'cookie-auth' : '-DBMCWEB_ENABLE_COOKIE_AUTHENTICATION',
65 'google-api' : '-DBMCWEB_ENABLE_GOOGLE_API',
66 'host-serial-socket' : '-DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET',
67 'ibm-management-console' : '-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE',
68 'insecure-disable-auth' : '-DBMCWEB_INSECURE_DISABLE_AUTHENTICATION',
69 'insecure-disable-csrf' : '-DBMCWEB_INSECURE_DISABLE_CSRF_PREVENTION',
70 'insecure-disable-ssl' : '-DBMCWEB_INSECURE_DISABLE_SSL',
71 'insecure-push-style-notification' : '-DBMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING',
72 'insecure-tftp-update' : '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE',
73 'kvm' : '-DBMCWEB_ENABLE_KVM' ,
74 'mutual-tls-auth' : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION',
Manojkiran Eda2d74fbc2021-10-28 12:39:49 +053075 'redfish' : '-DBMCWEB_ENABLE_REDFISH',
76 'redfish-bmc-journal' : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL',
77 'redfish-cpu-log' : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG',
78 'redfish-dbus-log' : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES',
Spencer Kub7028eb2021-10-26 15:27:35 +080079 'redfish-host-logger' : '-DBMCWEB_ENABLE_REDFISH_HOST_LOGGER',
Manojkiran Eda2d74fbc2021-10-28 12:39:49 +053080 'redfish-dump-log' : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG',
81 'redfish-provisioning-feature' : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE',
82 'rest' : '-DBMCWEB_ENABLE_DBUS_REST',
83 'redfish-allow-deprecated-power-thermal' : '-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL',
84 'redfish-new-powersubsystem-thermalsubsystem' : '-DBMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM',
85 'session-auth' : '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION',
86 'static-hosting' : '-DBMCWEB_ENABLE_STATIC_HOSTING',
87 #'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY',
88 'vm-websocket' : '-DBMCWEB_ENABLE_VM_WEBSOCKET',
89 'xtoken-auth' : '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053090}
91
92# Get the options status and build a project summary to show which flags are
93# being enabled during the configuration time.
94
95foreach option_key,option_value : feature_map
96 if(get_option(option_key).enabled())
97 if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl')
98 if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled())
99 add_project_arguments(option_value,language:'cpp')
100 summary(option_key,option_value, section : 'Enabled Features')
101 endif
102 else
103 summary(option_key,option_value, section : 'Enabled Features')
104 add_project_arguments(option_value,language:'cpp')
105 endif
106 else
107 if(option_key == 'insecure-disable-ssl')
108 summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features')
109 add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp')
110 endif
111 endif
112endforeach
113
114if(get_option('tests').enabled())
115 summary('unittest','NA', section : 'Enabled Features')
116endif
117
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530118# Add compiler arguments
119
120# -Wpedantic, -Wextra comes by default with warning level
121add_project_arguments(
122 cxx.get_supported_arguments([
123 '-Wold-style-cast',
124 '-Wcast-align',
125 '-Wunused',
126 '-Woverloaded-virtual',
127 '-Wconversion',
128 '-Wsign-conversion',
129 '-Wno-attributes',
130 ]),
131 language: 'cpp'
132)
133
134if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
135add_project_arguments(
136 cxx.get_supported_arguments([
137 '-Weverything',
138 '-Wno-c++98-compat',
139 '-Wno-c++98-compat-pedantic',
140 '-Wno-global-constructors',
141 '-Wno-exit-time-destructors',
142 '-Wno-shadow',
143 '-Wno-used-but-marked-unused',
144 '-Wno-documentation-unknown-command',
145 '-Wno-weak-vtables',
146 '-Wno-documentation',
147 '-Wno-padded',
148 '-Wunused-parameter',
149 '-Wcovered-switch-default',
150 '-Wcomma',
151 '-Wextra-semi',
152 '-Wzero-as-null-pointer-constant',
153 '-Wswitch-enum',
154 '-Wnull-dereference',
155 '-Wdouble-promotion',
Ed Tanousd32c4fa2021-09-14 13:16:51 -0700156 '-Wno-newline-eof',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530157 '-Wformat=2',
158 ]),
159 language:'cpp')
160endif
161
162# if compiler is gnu-gcc , and version is > 8.0 then we add few more
163# compiler arguments , we know that will pass
164
165if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
166
167 ## remove once bmcweb/issues/147 is fixed
168 add_global_link_arguments('-Wno-stringop-overflow',language:['c','cpp'])
169 add_project_arguments('-Wno-stringop-overflow',language:['c','cpp'])
170
171 add_project_arguments(
172 cxx.get_supported_arguments([
173 '-Wduplicated-cond',
174 '-Wduplicated-branches',
175 '-Wlogical-op',
176 '-Wunused-parameter',
177 '-Wnull-dereference',
178 '-Wdouble-promotion',
179 '-Wformat=2',
180 ]),
181 language:'cpp')
Ed Tanousc66403c2021-09-22 15:28:57 -0700182endif
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530183
Ed Tanousc66403c2021-09-22 15:28:57 -0700184if (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
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530188
Ed Tanousc66403c2021-09-22 15:28:57 -0700189 add_project_arguments(
190 cxx.get_supported_arguments([
191 '-fno-fat-lto-objects',
192 '-fvisibility=hidden',
193 '-fvisibility-inlines-hidden'
194 ]),
195 language: 'cpp')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530196
Ed Tanousc66403c2021-09-22 15:28:57 -0700197 if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
198 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
George Liue8204932021-02-01 14:42:49 +0800199 endif
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530200 endif
201endif
202
Ed Tanousc66403c2021-09-22 15:28:57 -0700203if( get_option('bmcweb-logging').enabled() or \
204 get_option('buildtype').startswith('debug'))
205 add_project_arguments([
206 '-DBMCWEB_ENABLE_LOGGING',
207 '-DBMCWEB_ENABLE_DEBUG'
208 ],
209 language : 'cpp')
210
211 summary({'debug' :'-DBMCWEB_ENABLE_DEBUG',
212 'logging' : '-DBMCWEB_ENABLE_LOGGING',
Ed Tanousc66403c2021-09-22 15:28:57 -0700213
Ed Tanousc66403c2021-09-22 15:28:57 -0700214 },section : 'Enabled Features')
215endif
216
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530217# Set Compiler Security flags
218
219security_flags = [
Ed Tanouscf2f9322021-09-22 15:34:41 -0700220 '-fstack-protector-strong',
221 '-fPIE',
222 '-fPIC',
223 '-D_FORTIFY_SOURCE=2',
224 '-Wformat',
225 '-Wformat-security'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530226]
227
228## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
229
230if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
231 add_project_arguments(
232 cxx.get_supported_arguments([
233 security_flags
234 ]),
235 language: 'cpp')
236endif
237
238# Boost dependency configuration
239
240add_project_arguments(
241cxx.get_supported_arguments([
Ed Tanouscf2f9322021-09-22 15:34:41 -0700242 '-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
243 '-DBOOST_ASIO_DISABLE_THREADS',
244 '-DBOOST_BEAST_USE_STD_STRING_VIEW',
Ed Tanous2107fe12021-10-09 16:10:52 -0700245 '-DBOOST_BEAST_SEPARATE_COMPILATION',
246 '-DBOOST_ASIO_SEPARATE_COMPILATION',
Ed Tanouscf2f9322021-09-22 15:34:41 -0700247 '-DBOOST_ERROR_CODE_HEADER_ONLY',
248 '-DBOOST_SYSTEM_NO_DEPRECATED',
249 '-DBOOST_ASIO_NO_DEPRECATED',
250 '-DBOOST_ALL_NO_LIB',
251 '-DBOOST_NO_RTTI',
252 '-DBOOST_NO_TYPEID',
253 '-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
254 '-DBOOST_URL_STANDALONE',
255 '-DBOOST_URL_HEADER_ONLY',
256 '-DBOOST_ALLOW_DEPRECATED_HEADERS',
257 '-DJSON_NOEXCEPTION'
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530258]),
259language : 'cpp')
260
261# Find the dependency modules, if not found use meson wrap to get them
262# automatically during the configure step
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800263bmcweb_dependencies = []
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530264
Nan Zhou8682c5a2021-11-13 11:00:07 -0800265pam = cxx.find_library('pam', required: true)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530266atomic = cxx.find_library('atomic', required: true)
267openssl = dependency('openssl', required : true)
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800268bmcweb_dependencies += [pam, atomic, openssl]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530269
Ed Tanous7bb985e2021-09-02 14:31:40 -0700270sdbusplus = dependency('sdbusplus', required : false, include_type: 'system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530271if not sdbusplus.found()
272 sdbusplus_proj = subproject('sdbusplus', required: true)
273 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
274 sdbusplus = sdbusplus.as_system('system')
275endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800276bmcweb_dependencies += sdbusplus
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530277
278if get_option('rest').enabled()
Patrick Williams565c0912021-10-12 20:22:45 -0500279 tinyxml = dependency('tinyxml2',
280 default_options: ['tests=false'],
281 include_type: 'system',
282 )
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800283 bmcweb_dependencies += tinyxml
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530284endif
285
286systemd = dependency('systemd')
287zlib = dependency('zlib')
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800288bmcweb_dependencies += [systemd, zlib]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530289
290if cxx.has_header('nlohmann/json.hpp')
291 nlohmann_json = declare_dependency()
292else
Josh Lehan259df352021-10-07 15:20:02 -0700293 nlohmann_json_proj = subproject('nlohmann', required: true)
294 nlohmann_json = nlohmann_json_proj.get_variable('nlohmann_json_dep')
Ed Tanousb00dcc22021-02-23 12:52:50 -0800295 nlohmann_json = nlohmann_json.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530296endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800297bmcweb_dependencies += nlohmann_json
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530298
Ed Tanous9c7b76c2021-10-25 12:06:39 -0700299boost = dependency('boost',version : '>=1.77.0', required : false, include_type: 'system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530300if not boost.found()
301 subproject('boost', required: false)
Ed Tanous9c7b76c2021-10-25 12:06:39 -0700302 boost_inc = include_directories('subprojects/boost_1_77_0/', is_system:true)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530303 boost = declare_dependency(include_directories : boost_inc)
Ed Tanousb00dcc22021-02-23 12:52:50 -0800304 boost = boost.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530305endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800306bmcweb_dependencies += boost
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530307
308if cxx.has_header('boost/url/url_view.hpp')
309 boost_url = declare_dependency()
310else
311 subproject('boost-url', required: false)
312 boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true)
313 boost_url= declare_dependency(include_directories : boost_url_inc)
Ed Tanousb00dcc22021-02-23 12:52:50 -0800314 boost_url = boost_url.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530315endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800316bmcweb_dependencies += boost_url
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530317
318if get_option('tests').enabled()
319 gtest = dependency('gtest', main: true,disabler: true, required : false)
320 gmock = dependency('gmock', required : false)
321 if not gtest.found() and get_option('tests').enabled()
322 gtest_proj = subproject('gtest', required: true)
323 gtest = gtest_proj.get_variable('gtest_main_dep')
324 gmock = gtest_proj.get_variable('gmock_dep')
325 endif
Ed Tanousb00dcc22021-02-23 12:52:50 -0800326 gtest = gtest.as_system('system')
327 gmock = gmock.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530328endif
329
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530330# Gather the Configuration data
331
332conf_data = configuration_data()
Ed Tanous0260d9d2021-02-07 19:31:07 +0000333conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB', get_option('http-body-limit'))
334xss_enabled = get_option('insecure-disable-xss')
Ed Tanousfeaf1502021-02-23 08:53:50 -0800335conf_data.set10('BMCWEB_INSECURE_DISABLE_XSS_PREVENTION', xss_enabled.enabled())
Ed Tanous0260d9d2021-02-07 19:31:07 +0000336conf_data.set('MESON_INSTALL_PREFIX', get_option('prefix'))
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700337conf_data.set('HTTPS_PORT', get_option('https_port'))
Ed Tanous75312982021-02-11 14:26:02 -0800338configure_file(input: 'bmcweb_config.h.in',
339 output: 'bmcweb_config.h',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530340 configuration: conf_data)
341
342# Configure and install systemd unit files
343
Patrick Williams6a779932021-10-12 20:08:44 -0500344systemd_system_unit_dir = systemd.get_variable(pkgconfig: 'systemdsystemunitdir')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530345
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
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700354configure_file(input : 'bmcweb.socket.in',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530355 output : 'bmcweb.socket',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530356 install_dir: systemd_system_unit_dir,
Vivekanand Veeracholan54d13552021-06-14 19:16:36 -0700357 configuration: conf_data,
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530358 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
Ed Tanous02f1cd92021-10-27 12:09:06 -0700375# Source files
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530376
Ed Tanous02f1cd92021-10-27 12:09:06 -0700377srcfiles_bmcweb = [
378 'redfish-core/src/error_messages.cpp',
379 'redfish-core/src/utils/json_utils.cpp',
380 'src/boost_url.cpp',
381 'src/boost_beast.cpp',
382 'src/boost_asio.cpp',
383 'src/boost_asio_ssl.cpp',
384]
385
386# Generate the bmcweb executable
387executable(
388 'bmcweb',
389 srcfiles_bmcweb + ['src/webserver_main.cpp'],
390 include_directories : incdir,
391 dependencies: bmcweb_dependencies,
392 link_args: '-Wl,--gc-sections',
393 install: true,
394 install_dir:bindir
395)
396
397srcfiles_unittest = [
398 'include/ut/dbus_utility_test.cpp',
399 'include/ut/http_utility_test.cpp',
400 'include/ut/human_sort_test.cpp',
401 'redfish-core/ut/privileges_test.cpp',
402 'redfish-core/ut/lock_test.cpp',
403 'redfish-core/ut/configfile_test.cpp',
404 'redfish-core/ut/time_utils_test.cpp',
405 'redfish-core/ut/stl_utils_test.cpp',
406 'redfish-core/ut/hex_utils_test.cpp',
Ed Tanous333b5302021-11-17 00:11:28 +0000407 'http/ut/utility_test.cpp'
Ed Tanous02f1cd92021-10-27 12:09:06 -0700408]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530409
410if(get_option('tests').enabled())
Ed Tanous02f1cd92021-10-27 12:09:06 -0700411 # generate the test executable
412 ut_bin = executable(
413 'bmcweb_unit_test',
414 srcfiles_unittest + srcfiles_bmcweb,
415 include_directories : incdir,
416 install_dir: bindir,
417 dependencies: bmcweb_dependencies + [
418 gtest,
419 gmock,
420 ]
421 )
422 test('bmcweb_unit_test', ut_bin)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530423endif