xref: /openbmc/bmcweb/meson.build (revision 10f270b4)
1project('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            'cpp_rtti=false',
12            'b_lto_mode=default',
13            'b_lto_threads=0'
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
38# remove debug information for minsize buildtype
39if(get_option('buildtype') == 'minsize')
40  add_project_arguments(['-fdata-sections', '-ffunction-sections'], language : 'cpp')
41  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',
62'host-serial-socket'              : '-DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET',
63'ibm-management-console'          : '-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE',
64'kvm'                             : '-DBMCWEB_ENABLE_KVM' ,
65'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',
69'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-dump-log'                : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG',
78'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
113# 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
195    if( get_option('bmcweb-logging').enabled() or \
196        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    if( get_option('redfish-allow-deprecated-hostname-patch').enabled())
209     add_project_arguments([
210       '-DBMCWEB_ALLOW_DEPRECATED_HOSTNAME_PATCH'
211       ],
212      language : 'cpp')
213
214      summary({'hostname-patch' :'-DBMCWEB_ALLOW_DEPRECATED_HOSTNAME_PATCH'
215              },section : 'Enabled Features')
216    endif
217
218  endif
219endif
220
221# Set Compiler Security flags
222
223security_flags = [
224'-fstack-protector-strong',
225'-fPIE',
226'-fPIC',
227'-D_FORTIFY_SOURCE=2',
228'-Wformat',
229'-Wformat-security'
230]
231
232## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
233
234if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
235  add_project_arguments(
236   cxx.get_supported_arguments([
237    security_flags
238  ]),
239  language: 'cpp')
240endif
241
242# Boost dependency configuration
243
244add_project_arguments(
245cxx.get_supported_arguments([
246'-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
247'-DBOOST_ASIO_DISABLE_THREADS',
248'-DBOOST_BEAST_USE_STD_STRING_VIEW',
249'-DBOOST_ERROR_CODE_HEADER_ONLY',
250'-DBOOST_SYSTEM_NO_DEPRECATED',
251'-DBOOST_ASIO_NO_DEPRECATED',
252'-DBOOST_ALL_NO_LIB',
253'-DBOOST_NO_RTTI',
254'-DBOOST_NO_TYPEID',
255'-DBOOST_COROUTINES_NO_DEPRECATION_WARNING',
256'-DBOOST_URL_STANDALONE',
257'-DBOOST_URL_HEADER_ONLY',
258'-DBOOST_ALLOW_DEPRECATED_HEADERS'
259]),
260language : 'cpp')
261
262# Find the dependency modules, if not found use meson wrap to get them
263# automatically during the configure step
264bmcweb_dependencies = []
265
266pam = cxx.find_library('pam', required: get_option('pam'))
267atomic =  cxx.find_library('atomic', required: true)
268openssl = dependency('openssl', required : true)
269bmcweb_dependencies += [pam, atomic, openssl]
270
271sdbusplus = dependency('sdbusplus',required : false)
272if not sdbusplus.found()
273  sdbusplus_proj = subproject('sdbusplus', required: true)
274  sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
275  sdbusplus = sdbusplus.as_system('system')
276endif
277bmcweb_dependencies += sdbusplus
278
279if get_option('rest').enabled()
280  tinyxml = dependency('tinyxml2', required: false)
281  if not tinyxml.found()
282    tinyxml_proj = subproject('tinyxml2', required: true)
283    tinyxml = tinyxml_proj.get_variable('tinyxml2_dep')
284    tinyxml = tinyxml.as_system('system')
285  endif
286  bmcweb_dependencies += tinyxml
287endif
288
289systemd = dependency('systemd')
290zlib = dependency('zlib')
291bmcweb_dependencies += [systemd, zlib]
292
293if cxx.has_header('nlohmann/json.hpp')
294    nlohmann_json = declare_dependency()
295else
296    subproject('nlohmann', required: false)
297    nlohmann_json = declare_dependency(
298        include_directories: [
299            'subprojects/nlohmann/single_include',
300            'subprojects/nlohmann/single_include/nlohmann',
301        ]
302    )
303    nlohmann_json = nlohmann_json.as_system('system')
304endif
305bmcweb_dependencies += nlohmann_json
306
307boost = dependency('boost',version : '>=1.75.0', required : false)
308if not boost.found()
309  subproject('boost', required: false)
310  boost_inc = include_directories('subprojects/boost_1_75_0/', is_system:true)
311  boost  = declare_dependency(include_directories : boost_inc)
312  boost = boost.as_system('system')
313endif
314bmcweb_dependencies += boost
315
316if cxx.has_header('boost/url/url_view.hpp')
317  boost_url = declare_dependency()
318else
319  subproject('boost-url', required: false)
320  boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true)
321  boost_url= declare_dependency(include_directories : boost_url_inc)
322  boost_url = boost_url.as_system('system')
323endif
324bmcweb_dependencies += boost_url
325
326if get_option('tests').enabled()
327  gtest = dependency('gtest', main: true,disabler: true, required : false)
328  gmock = dependency('gmock', required : false)
329  if not gtest.found() and get_option('tests').enabled()
330    gtest_proj = subproject('gtest', required: true)
331    gtest = gtest_proj.get_variable('gtest_main_dep')
332    gmock = gtest_proj.get_variable('gmock_dep')
333  endif
334  gtest = gtest.as_system('system')
335  gmock = gmock.as_system('system')
336endif
337
338# Source files
339
340srcfiles_bmcweb = ['src/webserver_main.cpp','redfish-core/src/error_messages.cpp',
341                   'redfish-core/src/utils/json_utils.cpp']
342
343srcfiles_unittest = ['include/ut/dbus_utility_test.cpp',
344                     'redfish-core/ut/privileges_test.cpp',
345                     'redfish-core/ut/lock_test.cpp',
346                     'redfish-core/ut/configfile_test.cpp',
347                     'redfish-core/ut/time_utils_test.cpp',
348                     'http/ut/utility_test.cpp']
349
350# Gather the Configuration data
351
352conf_data = configuration_data()
353conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB', get_option('http-body-limit'))
354xss_enabled = get_option('insecure-disable-xss')
355conf_data.set10('BMCWEB_INSECURE_DISABLE_XSS_PREVENTION', xss_enabled.enabled())
356conf_data.set('MESON_INSTALL_PREFIX', get_option('prefix'))
357configure_file(input: 'bmcweb_config.h.in',
358               output: 'bmcweb_config.h',
359               configuration: conf_data)
360
361# Configure and install systemd unit files
362
363systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
364
365bindir = get_option('prefix') + '/' +get_option('bindir')
366
367summary({
368          'prefix' : get_option('prefix'),
369          'bindir' : bindir,
370          'systemd unit directory' : systemd_system_unit_dir
371        }, section : 'Directories')
372
373configure_file(input : 'bmcweb.socket',
374               output : 'bmcweb.socket',
375               copy : true,
376               install_dir: systemd_system_unit_dir,
377               install : true)
378
379configure_file(input : 'bmcweb.service.in',
380               output : 'bmcweb.service',
381               install_dir: systemd_system_unit_dir,
382               configuration: conf_data,
383               install : true)
384
385# Copy pam-webserver to etc/pam.d
386configure_file(input : 'pam-webserver',
387               output : 'webserver',
388               copy : true,
389               install_dir: '/etc/pam.d',
390               install : true)
391
392install_subdir('static', install_dir : 'share/www', strip_directory : true)
393
394# Generate the bmcweb executable and the test binary
395
396executable('bmcweb',srcfiles_bmcweb,
397            include_directories : incdir,
398            dependencies: bmcweb_dependencies,
399            link_args: '-Wl,--gc-sections',
400            install: true,
401            install_dir:bindir)
402
403if(get_option('tests').enabled())
404  foreach src_test : srcfiles_unittest
405    testname = src_test.split('/')[-1].split('.')[0]
406    test(testname,executable(testname,src_test,
407                include_directories : incdir,
408                install_dir: bindir,
409                dependencies: [
410                                boost, boost_url, gtest,openssl,gmock,nlohmann_json,sdbusplus,pam
411                              ]))
412  endforeach
413endif
414