xref: /openbmc/bmcweb/meson.build (revision 549bed29)
1project('bmcweb', 'cpp',
2        version : '1.0',
3        meson_version: '>=0.63.0',
4        default_options: [
5            'b_lto_mode=default',
6            'b_lto_threads=0',
7            'b_lto=true',
8            'b_ndebug=if-release',
9            'buildtype=debugoptimized',
10            'cpp_rtti=false',
11            'cpp_std=c++20',
12            'warning_level=3',
13            'werror=true',
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++20'
26    error('This project requires c++20 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
44if(get_option('dns-resolver') == 'systemd-dbus')
45  add_project_arguments('-DBMCWEB_DBUS_DNS_RESOLVER', language : 'cpp')
46endif
47
48# Disable lto when compiling with no optimization
49if(get_option('optimization') == '0')
50  add_project_arguments('-fno-lto', language: 'cpp')
51  message('Disabling lto & its supported features as optimization is disabled')
52endif
53
54# Include Directories
55
56incdir = include_directories(
57  'include',
58  'redfish-core/include',
59  'redfish-core/lib',
60  'http'
61)
62
63# Get the options and enable the respective features
64## create a MAP of  "options : feature_flag"
65
66feature_map = {
67  'basic-auth'                                  : '-DBMCWEB_ENABLE_BASIC_AUTHENTICATION',
68  'cookie-auth'                                 : '-DBMCWEB_ENABLE_COOKIE_AUTHENTICATION',
69  'google-api'                                  : '-DBMCWEB_ENABLE_GOOGLE_API',
70  'host-serial-socket'                          : '-DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET',
71  'ibm-management-console'                      : '-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE',
72  'insecure-disable-auth'                       : '-DBMCWEB_INSECURE_DISABLE_AUTHX',
73  'insecure-disable-csrf'                       : '-DBMCWEB_INSECURE_DISABLE_CSRF_PREVENTION',
74  'insecure-disable-ssl'                        : '-DBMCWEB_INSECURE_DISABLE_SSL',
75  'insecure-push-style-notification'            : '-DBMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING',
76  'insecure-tftp-update'                        : '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE',
77  'insecure-ignore-content-type'                : '-DBMCWEB_INSECURE_IGNORE_CONTENT_TYPE',
78  'kvm'                                         : '-DBMCWEB_ENABLE_KVM' ,
79  'mutual-tls-auth'                             : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION',
80  'redfish-aggregation'                         : '-DBMCWEB_ENABLE_REDFISH_AGGREGATION',
81  'redfish-allow-deprecated-power-thermal'      : '-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL',
82  'redfish-bmc-journal'                         : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL',
83  'redfish-cpu-log'                             : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG',
84  'redfish-dbus-log'                            : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES',
85  'redfish-dump-log'                            : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG',
86  'redfish-host-logger'                         : '-DBMCWEB_ENABLE_REDFISH_HOST_LOGGER',
87  'redfish-new-powersubsystem-thermalsubsystem' : '-DBMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM',
88  'redfish-oem-manager-fan-data'                : '-DBMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA',
89  'redfish-provisioning-feature'                : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE',
90  'redfish'                                     : '-DBMCWEB_ENABLE_REDFISH',
91  'rest'                                        : '-DBMCWEB_ENABLE_DBUS_REST',
92  'session-auth'                                : '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION',
93  'static-hosting'                              : '-DBMCWEB_ENABLE_STATIC_HOSTING',
94  'experimental-redfish-multi-computer-system'  : '-DBMCWEB_ENABLE_MULTI_COMPUTERSYSTEM',
95  'vm-websocket'                                : '-DBMCWEB_ENABLE_VM_WEBSOCKET',
96  'xtoken-auth'                                 : '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION',
97  #'vm-nbdproxy'                                : '-DBMCWEB_ENABLE_VM_NBDPROXY',
98}
99
100# Get the options status and build a project summary to show which flags are
101# being enabled during the configuration time.
102
103foreach option_key,option_value : feature_map
104  if(get_option(option_key).allowed())
105    if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl')
106      if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled())
107        add_project_arguments(option_value,language:'cpp')
108        summary(option_key,option_value, section : 'Enabled Features')
109      endif
110    elif (option_key in ['basic-auth', 'cookie-auth', 'session-auth', 'xtoken-auth', 'mutual-tls-auth'])
111      if (get_option('insecure-disable-auth').disabled())
112        add_project_arguments(option_value, language:'cpp')
113        summary(option_key,option_value, section : 'Enabled Features')
114      endif
115    else
116      summary(option_key,option_value, section : 'Enabled Features')
117      add_project_arguments(option_value,language:'cpp')
118    endif
119  else
120      if(option_key == 'insecure-disable-ssl')
121        summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features')
122        add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp')
123      endif
124  endif
125endforeach
126
127if(get_option('tests').allowed())
128  summary('unittest','NA', section : 'Enabled Features')
129endif
130
131# Add compiler arguments
132
133# -Wpedantic, -Wextra comes by default with warning level
134add_project_arguments(
135  cxx.get_supported_arguments([
136  '-Wcast-align',
137  '-Wconversion',
138  '-Wformat=2',
139  '-Wold-style-cast',
140  '-Woverloaded-virtual',
141  '-Wsign-conversion',
142  '-Wunused',
143  '-Wno-attributes',
144  ]),
145  language: 'cpp'
146)
147
148if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
149add_project_arguments(
150  cxx.get_supported_arguments([
151    '-Weverything',
152    '-Wno-c++98-compat-pedantic',
153    '-Wno-c++98-compat',
154    '-Wno-documentation-unknown-command',
155    '-Wno-documentation',
156    '-Wno-exit-time-destructors',
157    '-Wno-global-constructors',
158    '-Wno-newline-eof',
159    '-Wno-padded',
160    '-Wno-shadow',
161    '-Wno-used-but-marked-unused',
162    '-Wno-weak-vtables',
163    '-Wno-switch-enum',
164    '-Wno-unused-macros',
165  ]),
166  language:'cpp')
167endif
168
169# if compiler is gnu-gcc , and version is > 8.0 then we add few more
170# compiler arguments , we know that will pass
171
172if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
173  add_project_arguments(
174    cxx.get_supported_arguments([
175     '-Wduplicated-cond',
176     '-Wduplicated-branches',
177     '-Wlogical-op',
178     '-Wnull-dereference',
179     '-Wunused-parameter',
180     '-Wdouble-promotion',
181     '-Wshadow',
182     '-Wno-psabi',
183     ]),
184    language:'cpp')
185endif
186
187if (get_option('buildtype') != 'plain')
188  if (get_option('b_lto') == true and get_option('optimization')!='0')
189    # Reduce the binary size by removing unnecessary
190    # dynamic symbol table entries
191
192    add_project_arguments(
193     cxx.get_supported_arguments([
194     '-fno-fat-lto-objects',
195     '-fvisibility=hidden',
196     '-fvisibility-inlines-hidden'
197     ]),
198     language: 'cpp')
199
200    if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
201      add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
202    endif
203  endif
204endif
205
206if( get_option('bmcweb-logging') != 'disabled' or \
207    get_option('buildtype').startswith('debug'))
208 add_project_arguments([
209   '-DBMCWEB_ENABLE_DEBUG'
210   ],
211  language : 'cpp')
212
213  summary('debug', '-DBMCWEB_ENABLE_DEBUG', section : 'Enabled Features')
214endif
215
216# Set Compiler Security flags
217
218security_flags = [
219  '-fstack-protector-strong',
220  '-fPIE',
221  '-fPIC',
222  '-D_FORTIFY_SOURCE=2',
223  '-Wformat',
224  '-Wformat-security'
225]
226
227## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
228
229if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
230  add_project_arguments(
231   cxx.get_supported_arguments([
232    security_flags
233  ]),
234  language: 'cpp')
235endif
236
237# Boost dependency configuration
238
239add_project_arguments(
240cxx.get_supported_arguments([
241  '-DBOOST_ASIO_DISABLE_CONCEPTS',
242  '-DBOOST_ALL_NO_LIB',
243  '-DBOOST_ALLOW_DEPRECATED_HEADERS',
244  '-DBOOST_ASIO_DISABLE_THREADS',
245  '-DBOOST_ASIO_NO_DEPRECATED',
246  '-DBOOST_ASIO_SEPARATE_COMPILATION',
247  '-DBOOST_BEAST_SEPARATE_COMPILATION',
248  '-DBOOST_EXCEPTION_DISABLE',
249  '-DBOOST_NO_EXCEPTIONS',
250  '-DBOOST_URL_NO_SOURCE_LOCATION',
251  '-DJSON_NOEXCEPTION',
252  '-DOPENSSL_NO_FILENAMES',
253  '-DSDBUSPLUS_DISABLE_BOOST_COROUTINES',
254]),
255language : 'cpp')
256
257# Find the dependency modules, if not found use meson wrap to get them
258# automatically during the configure step
259bmcweb_dependencies = []
260
261pam = cxx.find_library('pam', required: true)
262atomic =  cxx.find_library('atomic', required: true)
263openssl = dependency('openssl', required : true)
264bmcweb_dependencies += [pam, atomic, openssl]
265
266nghttp2 = dependency('libnghttp2', version: '>=1.52.0', required : false)
267if not nghttp2.found()
268  cmake = import('cmake')
269  opt_var = cmake.subproject_options()
270  opt_var.add_cmake_defines({
271    'ENABLE_LIB_ONLY': true,
272    'ENABLE_STATIC_LIB': true
273  })
274  nghttp2_ex = cmake.subproject('nghttp2', options: opt_var)
275  nghttp2 = nghttp2_ex.dependency('nghttp2')
276endif
277bmcweb_dependencies += nghttp2
278
279sdbusplus = dependency('sdbusplus', required : false, include_type: 'system')
280if not sdbusplus.found()
281  sdbusplus_proj = subproject('sdbusplus', required: true)
282  sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
283  sdbusplus = sdbusplus.as_system('system')
284endif
285bmcweb_dependencies += sdbusplus
286
287tinyxml = dependency(
288    'tinyxml2',
289    include_type: 'system',
290    version: '>=9.0.0',
291)
292if not tinyxml.found()
293    tinyxml_proj = subproject('tinyxml2', required: true)
294    tinyxml = tinyxml_proj.get_variable('tinyxml_dep')
295    tinyxml = tinyxml.as_system('system')
296endif
297bmcweb_dependencies += tinyxml
298
299systemd = dependency('systemd')
300zlib = dependency('zlib')
301bmcweb_dependencies += [systemd, zlib]
302
303nlohmann_json = dependency('nlohmann_json', version: '>=3.9.2', required: false, include_type: 'system')
304if not nlohmann_json.found()
305    nlohmann_json_proj = subproject('nlohmann_json', required: true)
306    nlohmann_json = nlohmann_json_proj.get_variable('nlohmann_json_dep')
307    nlohmann_json = nlohmann_json.as_system('system')
308endif
309bmcweb_dependencies += nlohmann_json
310
311boost = dependency(
312  'boost',
313  modules: [
314    'url',
315    ],
316  version : '>=1.83.0',
317  required : false,
318  include_type: 'system'
319)
320if boost.found()
321  bmcweb_dependencies += [boost]
322else
323  cmake = import('cmake')
324  opt = cmake.subproject_options()
325  opt.add_cmake_defines({
326    'BOOST_INCLUDE_LIBRARIES': 'asio;beast;callable_traits;headers;process;type_index;url;uuid'
327  })
328  boost = cmake.subproject('boost', required: true, options: opt)
329  boost_asio = boost.dependency('boost_asio').as_system()
330  boost_beast = boost.dependency('boost_beast').as_system()
331  boost_callable_traits = boost.dependency('boost_callable_traits').as_system()
332  boost_headers = boost.dependency('boost_headers').as_system()
333  boost_process = boost.dependency('boost_process').as_system()
334  boost_type_index = boost.dependency('boost_type_index').as_system()
335  boost_url = boost.dependency('boost_url').as_system()
336  boost_uuid = boost.dependency('boost_uuid').as_system()
337  bmcweb_dependencies += [
338    boost_asio,
339    boost_beast,
340    boost_callable_traits,
341    boost_headers,
342    boost_process,
343    boost_type_index,
344    boost_url,
345    boost_uuid
346  ]
347endif
348
349if get_option('tests').allowed()
350  gtest = dependency('gtest', main: true, disabler: true, required : false)
351  gmock = dependency('gmock', required : false)
352  if not gtest.found() and get_option('tests').allowed()
353    gtest_proj = subproject('gtest', required: true)
354    gtest = gtest_proj.get_variable('gtest_main_dep')
355    gmock = gtest_proj.get_variable('gmock_dep')
356  endif
357  gtest = gtest.as_system('system')
358  gmock = gmock.as_system('system')
359endif
360
361systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir')
362
363bindir = get_option('prefix') + '/' +get_option('bindir')
364
365summary({
366          'prefix' : get_option('prefix'),
367          'bindir' : bindir,
368          'systemd unit directory' : systemd_system_unit_dir
369        }, section : 'Directories')
370
371install_subdir('static', install_dir : 'share/www', strip_directory : true)
372
373# Config subdirectory
374
375subdir('config')
376bmcweb_dependencies += conf_h_dep
377
378# Source files
379fs = import('fs')
380
381srcfiles_bmcweb = files(
382  'redfish-core/src/error_messages.cpp',
383  'redfish-core/src/registries.cpp',
384  'redfish-core/src/utils/time_utils.cpp',
385  'redfish-core/src/utils/json_utils.cpp',
386  'src/boost_asio_ssl.cpp',
387  'src/boost_asio.cpp',
388  'src/boost_beast.cpp',
389  'src/dbus_singleton.cpp',
390  'src/json_html_serializer.cpp',
391  'src/ossl_random.cpp',
392)
393
394bmcweblib = static_library(
395  'bmcweblib',
396  srcfiles_bmcweb,
397  include_directories : incdir,
398  dependencies: bmcweb_dependencies,
399)
400
401# Generate the bmcweb executable
402executable(
403  'bmcweb',
404  'src/webserver_main.cpp',
405  include_directories : incdir,
406  dependencies: bmcweb_dependencies,
407  link_with: bmcweblib,
408  link_args: '-Wl,--gc-sections',
409  install: true,
410  install_dir:bindir
411)
412
413srcfiles_unittest = files(
414  'test/http/crow_getroutes_test.cpp',
415  'test/http/router_test.cpp',
416  'test/http/utility_test.cpp',
417  'test/http/verb_test.cpp',
418  'test/include/dbus_utility_test.cpp',
419  'test/include/google/google_service_root_test.cpp',
420  'test/include/json_html_serializer.cpp',
421  'test/include/http_utility_test.cpp',
422  'test/include/human_sort_test.cpp',
423  'test/include/async_resolve_test.cpp',
424  'test/include/credential_pipe_test.cpp',
425  'test/include/ibm/configfile_test.cpp',
426  'test/include/ibm/lock_test.cpp',
427  'test/include/multipart_test.cpp',
428  'test/include/openbmc_dbus_rest_test.cpp',
429  'test/include/str_utility_test.cpp',
430  'test/include/ossl_random.cpp',
431  'test/redfish-core/include/privileges_test.cpp',
432  'test/redfish-core/include/redfish_aggregator_test.cpp',
433  'test/redfish-core/include/registries_test.cpp',
434  'test/redfish-core/include/utils/hex_utils_test.cpp',
435  'test/redfish-core/include/utils/ip_utils_test.cpp',
436  'test/redfish-core/include/utils/json_utils_test.cpp',
437  'test/redfish-core/include/utils/query_param_test.cpp',
438  'test/redfish-core/include/utils/stl_utils_test.cpp',
439  'test/redfish-core/include/utils/time_utils_test.cpp',
440  'test/redfish-core/lib/chassis_test.cpp',
441  'test/redfish-core/lib/sensors_test.cpp',
442  'test/redfish-core/lib/log_services_dump_test.cpp',
443  'test/redfish-core/lib/service_root_test.cpp',
444  'test/redfish-core/lib/thermal_subsystem_test.cpp',
445  'test/redfish-core/lib/power_subsystem_test.cpp',
446)
447
448if(get_option('tests').allowed())
449    # generate the test executable
450    foreach test_src : srcfiles_unittest
451      test_bin = executable(
452        fs.stem(test_src),
453        test_src,
454        link_with: bmcweblib,
455        include_directories : incdir,
456        install_dir: bindir,
457        dependencies: bmcweb_dependencies + [
458          gtest,
459          gmock,
460        ]
461      )
462      test(fs.stem(test_src), test_bin)
463    endforeach
464endif
465