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