xref: /openbmc/bmcweb/meson.build (revision 7da1c588)
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
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(
53  'include',
54  'redfish-core/include',
55  'redfish-core/lib',
56  'http'
57)
58
59# Get the options and enable the respective features
60## create a MAP of  "options : feature_flag"
61
62feature_map = {
63  '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_AUTHX',
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  'insecure-ignore-content-type'                : '-DBMCWEB_INSECURE_IGNORE_CONTENT_TYPE',
74  'kvm'                                         : '-DBMCWEB_ENABLE_KVM' ,
75  'mutual-tls-auth'                             : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION',
76  'redfish-aggregation'                         : '-DBMCWEB_ENABLE_REDFISH_AGGREGATION',
77  'redfish-allow-deprecated-power-thermal'      : '-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL',
78  'redfish-bmc-journal'                         : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL',
79  'redfish-cpu-log'                             : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG',
80  'redfish-dbus-log'                            : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES',
81  'redfish-dump-log'                            : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG',
82  'redfish-host-logger'                         : '-DBMCWEB_ENABLE_REDFISH_HOST_LOGGER',
83  'redfish-new-powersubsystem-thermalsubsystem' : '-DBMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM',
84  'redfish-oem-manager-fan-data'                : '-DBMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA',
85  'redfish-provisioning-feature'                : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE',
86  'redfish-post-to-old-updateservice'           : '-DBMCWEB_ENABLE_REDFISH_UPDATESERVICE_OLD_POST_URL',
87  'redfish'                                     : '-DBMCWEB_ENABLE_REDFISH',
88  'rest'                                        : '-DBMCWEB_ENABLE_DBUS_REST',
89  'session-auth'                                : '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION',
90  'static-hosting'                              : '-DBMCWEB_ENABLE_STATIC_HOSTING',
91  'vm-websocket'                                : '-DBMCWEB_ENABLE_VM_WEBSOCKET',
92  'xtoken-auth'                                 : '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION',
93  #'vm-nbdproxy'                                : '-DBMCWEB_ENABLE_VM_NBDPROXY',
94}
95
96# Get the options status and build a project summary to show which flags are
97# being enabled during the configuration time.
98
99foreach option_key,option_value : feature_map
100  if(get_option(option_key).enabled())
101    if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl')
102      if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled())
103        add_project_arguments(option_value,language:'cpp')
104        summary(option_key,option_value, section : 'Enabled Features')
105      endif
106    elif (option_key in ['basic-auth', 'cookie-auth', 'session-auth', 'xtoken-auth', 'mutual-tls-auth'])
107      if (get_option('insecure-disable-auth').disabled())
108        add_project_arguments(option_value, language:'cpp')
109        summary(option_key,option_value, section : 'Enabled Features')
110      endif
111    else
112      summary(option_key,option_value, section : 'Enabled Features')
113      add_project_arguments(option_value,language:'cpp')
114    endif
115  else
116      if(option_key == 'insecure-disable-ssl')
117        summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features')
118        add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp')
119      endif
120  endif
121endforeach
122
123if(get_option('tests').enabled())
124  summary('unittest','NA', section : 'Enabled Features')
125endif
126
127# Add compiler arguments
128
129# -Wpedantic, -Wextra comes by default with warning level
130add_project_arguments(
131  cxx.get_supported_arguments([
132  '-Wcast-align',
133  '-Wconversion',
134  '-Wformat=2',
135  '-Wold-style-cast',
136  '-Woverloaded-virtual',
137  '-Wsign-conversion',
138  '-Wunused',
139  '-Wno-attributes',
140  ]),
141  language: 'cpp'
142)
143
144if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
145add_project_arguments(
146  cxx.get_supported_arguments([
147    '-Weverything',
148    '-Wno-c++98-compat-pedantic',
149    '-Wno-c++98-compat',
150    '-Wno-documentation-unknown-command',
151    '-Wno-documentation',
152    '-Wno-exit-time-destructors',
153    '-Wno-global-constructors',
154    '-Wno-newline-eof',
155    '-Wno-padded',
156    '-Wno-shadow',
157    '-Wno-used-but-marked-unused',
158    '-Wno-weak-vtables',
159    '-Wno-switch-enum',
160  ]),
161  language:'cpp')
162endif
163
164# if compiler is gnu-gcc , and version is > 8.0 then we add few more
165# compiler arguments , we know that will pass
166
167if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
168  add_project_arguments(
169    cxx.get_supported_arguments([
170     '-Wduplicated-cond',
171     '-Wduplicated-branches',
172     '-Wlogical-op',
173     '-Wnull-dereference',
174     '-Wunused-parameter',
175     '-Wdouble-promotion',
176     '-Wshadow',
177     '-Wno-psabi',
178     ]),
179    language:'cpp')
180endif
181
182if (get_option('buildtype') != 'plain')
183  if (get_option('b_lto') == true and get_option('optimization')!='0')
184    # Reduce the binary size by removing unnecessary
185    # dynamic symbol table entries
186
187    add_project_arguments(
188     cxx.get_supported_arguments([
189     '-fno-fat-lto-objects',
190     '-fvisibility=hidden',
191     '-fvisibility-inlines-hidden'
192     ]),
193     language: 'cpp')
194
195    if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
196      add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
197    endif
198  endif
199endif
200
201if( get_option('bmcweb-logging').enabled() or \
202    get_option('buildtype').startswith('debug'))
203 add_project_arguments([
204   '-DBMCWEB_ENABLE_LOGGING',
205   '-DBMCWEB_ENABLE_DEBUG'
206   ],
207  language : 'cpp')
208
209  summary({'debug' :'-DBMCWEB_ENABLE_DEBUG',
210     'logging' : '-DBMCWEB_ENABLE_LOGGING',
211
212    },section : 'Enabled Features')
213endif
214
215# Set Compiler Security flags
216
217security_flags = [
218  '-fstack-protector-strong',
219  '-fPIE',
220  '-fPIC',
221  '-D_FORTIFY_SOURCE=2',
222  '-Wformat',
223  '-Wformat-security'
224]
225
226## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
227
228if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
229  add_project_arguments(
230   cxx.get_supported_arguments([
231    security_flags
232  ]),
233  language: 'cpp')
234endif
235
236# Boost dependency configuration
237
238add_project_arguments(
239cxx.get_supported_arguments([
240  '-DBOOST_ALL_NO_LIB',
241  '-DBOOST_ALLOW_DEPRECATED_HEADERS',
242  '-DBOOST_ASIO_DISABLE_THREADS',
243  '-DBOOST_ASIO_NO_DEPRECATED',
244  '-DBOOST_ASIO_SEPARATE_COMPILATION',
245  '-DBOOST_BEAST_SEPARATE_COMPILATION',
246  '-DBOOST_EXCEPTION_DISABLE',
247  '-DBOOST_URL_NO_SOURCE_LOCATION',
248  '-DJSON_NOEXCEPTION',
249  '-DOPENSSL_NO_FILENAMES',
250]),
251language : 'cpp')
252
253# Find the dependency modules, if not found use meson wrap to get them
254# automatically during the configure step
255bmcweb_dependencies = []
256
257pam = cxx.find_library('pam', required: true)
258atomic =  cxx.find_library('atomic', required: true)
259openssl = dependency('openssl', required : true)
260bmcweb_dependencies += [pam, atomic, openssl]
261
262sdbusplus = dependency('sdbusplus', required : false, include_type: 'system')
263if not sdbusplus.found()
264  sdbusplus_proj = subproject('sdbusplus', required: true)
265  sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
266  sdbusplus = sdbusplus.as_system('system')
267endif
268bmcweb_dependencies += sdbusplus
269
270tinyxml = dependency('tinyxml2',
271    default_options: ['tests=false'],
272    include_type: 'system',
273)
274bmcweb_dependencies += tinyxml
275
276systemd = dependency('systemd')
277zlib = dependency('zlib')
278bmcweb_dependencies += [systemd, zlib]
279
280if cxx.has_header('nlohmann/json.hpp')
281    nlohmann_json = declare_dependency()
282else
283    nlohmann_json_proj = subproject('nlohmann', required: true)
284    nlohmann_json = nlohmann_json_proj.get_variable('nlohmann_json_dep')
285    nlohmann_json = nlohmann_json.as_system('system')
286endif
287bmcweb_dependencies += nlohmann_json
288
289boost = dependency('boost',version : '>=1.81.0', required : false, include_type: 'system')
290if not boost.found()
291  boost = subproject('boost', required: true).get_variable('boost_dep')
292  boost = boost.as_system('system')
293endif
294bmcweb_dependencies += boost
295
296if get_option('tests').enabled()
297  gtest = dependency('gtest', main: true,disabler: true, required : false)
298  gmock = dependency('gmock', required : false)
299  if not gtest.found() and get_option('tests').enabled()
300    gtest_proj = subproject('gtest', required: true)
301    gtest = gtest_proj.get_variable('gtest_main_dep')
302    gmock = gtest_proj.get_variable('gmock_dep')
303  endif
304  gtest = gtest.as_system('system')
305  gmock = gmock.as_system('system')
306endif
307
308systemd_system_unit_dir = systemd.get_variable(pkgconfig: 'systemdsystemunitdir')
309
310bindir = get_option('prefix') + '/' +get_option('bindir')
311
312summary({
313          'prefix' : get_option('prefix'),
314          'bindir' : bindir,
315          'systemd unit directory' : systemd_system_unit_dir
316        }, section : 'Directories')
317
318install_subdir('static', install_dir : 'share/www', strip_directory : true)
319
320# Config subdirectory
321
322subdir('config')
323bmcweb_dependencies += conf_h_dep
324
325# Source files
326fs = import('fs')
327
328srcfiles_bmcweb = files(
329  'redfish-core/src/error_messages.cpp',
330  'redfish-core/src/utils/json_utils.cpp',
331  'src/boost_asio_ssl.cpp',
332  'src/boost_asio.cpp',
333  'src/boost_beast.cpp',
334  'src/boost_url.cpp',
335  'src/dbus_singleton.cpp',
336)
337
338bmcweblib = static_library(
339  'bmcweblib',
340  srcfiles_bmcweb,
341  include_directories : incdir,
342  dependencies: bmcweb_dependencies,
343)
344
345# Generate the bmcweb executable
346executable(
347  'bmcweb',
348  'src/webserver_main.cpp',
349  include_directories : incdir,
350  dependencies: bmcweb_dependencies,
351  link_with: bmcweblib,
352  link_args: '-Wl,--gc-sections',
353  install: true,
354  install_dir:bindir
355)
356
357srcfiles_unittest = files(
358  'test/http/crow_getroutes_test.cpp',
359  'test/http/router_test.cpp',
360  'test/http/utility_test.cpp',
361  'test/http/verb_test.cpp',
362  'test/include/dbus_utility_test.cpp',
363  'test/include/google/google_service_root_test.cpp',
364  'test/include/http_utility_test.cpp',
365  'test/include/human_sort_test.cpp',
366  'test/include/ibm/configfile_test.cpp',
367  'test/include/ibm/lock_test.cpp',
368  'test/include/multipart_test.cpp',
369  'test/include/openbmc_dbus_rest_test.cpp',
370  'test/include/str_utility_test.cpp',
371  'test/redfish-core/include/privileges_test.cpp',
372  'test/redfish-core/include/redfish_aggregator_test.cpp',
373  'test/redfish-core/include/registries_test.cpp',
374  'test/redfish-core/include/utils/hex_utils_test.cpp',
375  'test/redfish-core/include/utils/ip_utils_test.cpp',
376  'test/redfish-core/include/utils/json_utils_test.cpp',
377  'test/redfish-core/include/utils/query_param_test.cpp',
378  'test/redfish-core/include/utils/stl_utils_test.cpp',
379  'test/redfish-core/include/utils/time_utils_test.cpp',
380  'test/redfish-core/lib/chassis_test.cpp',
381  'test/redfish-core/lib/sensors_test.cpp',
382  'test/redfish-core/lib/log_services_dump_test.cpp',
383  'test/redfish-core/lib/service_root_test.cpp',
384  'test/redfish-core/lib/thermal_subsystem_test.cpp',
385  'test/redfish-core/lib/power_subsystem_test.cpp',
386)
387
388if(get_option('tests').enabled())
389    # generate the test executable
390    foreach test_src : srcfiles_unittest
391      test_bin = executable(
392        fs.stem(test_src),
393        test_src,
394        link_with: bmcweblib,
395        include_directories : incdir,
396        install_dir: bindir,
397        dependencies: bmcweb_dependencies + [
398          gtest,
399          gmock,
400        ]
401      )
402      test(fs.stem(test_src), test_bin)
403    endforeach
404endif
405