xref: /openbmc/bmcweb/meson.build (revision d033fd17ae806365d12bb12bee7663c71e3f3512)
1project(
2    'bmcweb',
3    'cpp',
4    version: '1.0',
5    meson_version: '>=1.3.0',
6    default_options: [
7        'b_lto_mode=default',
8        'b_lto_threads=0',
9        'b_lto=true',
10        'b_ndebug=if-release',
11        'buildtype=debugoptimized',
12        'cpp_rtti=false',
13        'cpp_std=c++23',
14        'warning_level=3',
15        'werror=true',
16    ],
17)
18
19# Project related links
20
21project_pretty_name = 'bmcweb'
22project_url = 'https://github.com/openbmc/' + project_pretty_name
23project_issues_url = project_url + '/issues/new'
24summary('Issues', project_issues_url, section: 'Report Issues')
25
26# Validate the c++ Standard
27
28if get_option('cpp_std') != 'c++23'
29    error('This project requires c++23 support')
30endif
31
32# Get compiler and default build type
33
34cxx = meson.get_compiler('cpp')
35build = get_option('buildtype')
36optimization = get_option('optimization')
37summary('Build Type', build, section: 'Build Info')
38summary('Optimization', optimization, section: 'Build Info')
39
40# remove debug information for minsize buildtype
41if (get_option('buildtype') == 'minsize')
42    add_project_arguments(
43        ['-fdata-sections', '-ffunction-sections'],
44        language: 'cpp',
45    )
46    add_project_arguments('-DNDEBUG', language: 'cpp')
47endif
48
49if (get_option('dns-resolver') == 'systemd-dbus')
50    add_project_arguments('-DBMCWEB_DBUS_DNS_RESOLVER', language: 'cpp')
51endif
52
53# Disable lto when compiling with no optimization
54if (get_option('optimization') == '0')
55    add_project_arguments('-fno-lto', language: 'cpp')
56    message('Disabling lto & its supported features as optimization is disabled')
57endif
58
59# Include Directories
60
61incdir = include_directories(
62    'include',
63    'redfish-core/include',
64    'redfish-core/lib',
65    'http',
66)
67incdir_cli = include_directories('http', 'include')
68
69if (get_option('tests').allowed())
70    summary('unittest', 'NA', section: 'Features')
71endif
72
73# Add compiler arguments
74boost_flags = ['-Wno-unused-parameter']
75nghttp2_flags = []
76if (cxx.get_id() == 'clang')
77    if (cxx.version().version_compare('<17.0'))
78        error('This project requires clang-17 or higher')
79    endif
80    add_project_arguments(
81        '-Weverything',
82        '-Wformat=2',
83        '-Wno-c++20-extensions',
84        '-Wno-c++23-extensions',
85        '-Wno-c++26-extensions',
86        '-Wno-c++98-compat',
87        '-Wno-c++98-compat-pedantic',
88        '-Wno-covered-switch-default',
89        '-Wno-disabled-macro-expansion',
90        '-Wno-documentation',
91        '-Wno-documentation-unknown-command',
92        '-Wno-exit-time-destructors',
93        '-Wno-global-constructors',
94        '-Wno-missing-include-dirs',
95        '-Wno-newline-eof',
96        '-Wno-padded',
97        '-Wno-shadow',
98        '-Wno-switch-enum',
99        '-Wno-unneeded-internal-declaration',
100        '-Wno-unsafe-buffer-usage-in-container',
101        '-Wno-unused-macros',
102        '-Wno-used-but-marked-unused',
103        '-Wno-weak-vtables',
104        language: 'cpp',
105    )
106    boost_flags += ['-Wno-strict-prototypes', '-Wno-unused-but-set-variable']
107    nghttp2_flags += ['-Wno-extra-semi']
108endif
109
110if (cxx.get_id() == 'gcc')
111    if (cxx.version().version_compare('<13.0'))
112        error('This project requires gcc-13 or higher')
113    endif
114
115    add_project_arguments(
116        '-Wformat=2',
117        '-Wcast-align',
118        '-Wconversion',
119        '-Woverloaded-virtual',
120        '-Wsign-conversion',
121        '-Wunused',
122        '-Wduplicated-cond',
123        '-Wduplicated-branches',
124        '-Wlogical-op',
125        '-Wnull-dereference',
126        '-Wunused-parameter',
127        '-Wdouble-promotion',
128        '-Wshadow',
129        '-Wno-psabi',
130        '-Wno-attributes',
131        language: 'cpp',
132    )
133endif
134
135if (get_option('buildtype') != 'plain')
136    if (get_option('b_lto') == true and get_option('optimization') != '0')
137        # Reduce the binary size by removing unnecessary
138        # dynamic symbol table entries
139
140        add_project_arguments(
141            cxx.get_supported_arguments(
142                [
143                    '-fno-fat-lto-objects',
144                    '-fvisibility=hidden',
145                    '-fvisibility-inlines-hidden',
146                ],
147            ),
148            language: 'cpp',
149        )
150
151        if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
152            add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
153        endif
154    endif
155endif
156# Set Compiler Security flags
157
158security_flags = [
159    '-fstack-protector-strong',
160    '-fPIE',
161    '-fPIC',
162    '-D_FORTIFY_SOURCE=2',
163    '-Wformat',
164    '-Wformat-security',
165]
166
167## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
168
169if not (get_option('buildtype') == 'plain'
170or get_option('buildtype').startswith('debug')
171)
172    add_project_arguments(
173        cxx.get_supported_arguments([security_flags]),
174        language: 'cpp',
175    )
176endif
177
178# Boost dependency configuration
179
180add_project_arguments(
181    cxx.get_supported_arguments(
182        [
183            '-DBOOST_ALL_NO_LIB',
184            '-DBOOST_ALLOW_DEPRECATED_HEADERS',
185            '-DBOOST_ASIO_DISABLE_THREADS',
186            '-DBOOST_ASIO_NO_DEPRECATED',
187            '-DBOOST_ASIO_SEPARATE_COMPILATION',
188            '-DBOOST_BEAST_SEPARATE_COMPILATION',
189            '-DBOOST_EXCEPTION_DISABLE',
190            '-DBOOST_NO_EXCEPTIONS',
191            '-DBOOST_URL_NO_SOURCE_LOCATION',
192            '-DBOOST_SPIRIT_X3_NO_RTTI',
193            '-DJSON_NOEXCEPTION',
194            '-DOPENSSL_NO_FILENAMES',
195            '-DSDBUSPLUS_DISABLE_BOOST_COROUTINES',
196        ],
197    ),
198    language: 'cpp',
199)
200
201# Find the dependency modules, if not found use meson wrap to get them
202# automatically during the configure step
203bmcweb_dependencies = []
204bmcweb_cli_dependencies = []
205
206pam = cxx.find_library('pam', required: true)
207atomic = cxx.find_library('atomic', required: true)
208bmcweb_dependencies += [pam, atomic]
209
210openssl = dependency('openssl', required: false, version: '>=3.0.0')
211if not openssl.found()
212    openssl_proj = subproject(
213        'openssl',
214        required: true,
215        default_options: ['warning_level=0', 'werror=false'],
216    )
217    openssl = openssl_proj.get_variable('openssl_dep')
218    openssl = openssl.as_system('system')
219endif
220bmcweb_dependencies += [openssl]
221
222nghttp2 = dependency('libnghttp2', version: '>=1.52.0', required: false)
223if not nghttp2.found()
224    cmake = import('cmake')
225    opt_var = cmake.subproject_options()
226    opt_var.add_cmake_defines(
227        {
228            'CMAKE_C_FLAGS': ' '.join(nghttp2_flags),
229            'CMAKE_CXX_FLAGS': ' '.join(nghttp2_flags),
230            'ENABLE_LIB_ONLY': true,
231            'ENABLE_STATIC_LIB': true,
232        },
233    )
234    nghttp2_ex = cmake.subproject('nghttp2', options: opt_var)
235    nghttp2 = nghttp2_ex.dependency('nghttp2')
236endif
237bmcweb_dependencies += nghttp2
238
239sdbusplus = dependency('sdbusplus', required: false, include_type: 'system')
240if not sdbusplus.found()
241    sdbusplus_proj = subproject('sdbusplus', required: true)
242    sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
243    sdbusplus = sdbusplus.as_system('system')
244endif
245bmcweb_dependencies += sdbusplus
246bmcweb_cli_dependencies += sdbusplus
247
248cli11 = dependency('CLI11', required: false, include_type: 'system')
249if not cli11.found()
250    cli11_proj = subproject('cli11', required: true)
251    cli11 = cli11_proj.get_variable('CLI11_dep')
252    cli11 = cli11.as_system('system')
253endif
254bmcweb_cli_dependencies += cli11
255
256
257tinyxml = dependency(
258    'tinyxml2',
259    include_type: 'system',
260    version: '>=9.0.0',
261    default_options: ['tests=false'],
262)
263if not tinyxml.found()
264    tinyxml_proj = subproject('tinyxml2', required: true)
265    tinyxml = tinyxml_proj.get_variable('tinyxml_dep')
266    tinyxml = tinyxml.as_system('system')
267endif
268bmcweb_dependencies += tinyxml
269
270systemd = dependency('systemd')
271libsystemd = dependency('libsystemd')
272add_project_arguments(
273    '-DLIBSYSTEMD_VERSION=' + libsystemd.version(),
274    language: 'cpp',
275)
276
277zlib = dependency('zlib')
278bmcweb_dependencies += [libsystemd, zlib]
279
280nlohmann_json_dep = dependency(
281    'nlohmann_json',
282    version: '>=3.11.3',
283    include_type: 'system',
284)
285bmcweb_dependencies += nlohmann_json_dep
286
287boost = dependency(
288    'boost',
289    modules: ['url'],
290    version: '>=1.84.0',
291    required: false,
292    static: true,
293    include_type: 'system',
294)
295
296# Boost version is 1.86 or higher to include the 'process' module
297if boost.version().version_compare('>=1.86.0')
298    boost = dependency(
299        'boost',
300        modules: ['url', 'process'],
301        version: '>=1.86.0',
302        static: true,
303        required: false,
304        include_type: 'system',
305    )
306endif
307
308if boost.found()
309    bmcweb_dependencies += [boost]
310    bmcweb_cli_dependencies += [boost]
311else
312    cmake = import('cmake')
313    opt = cmake.subproject_options()
314    boost_libs = [
315        'asio',
316        'beast',
317        'circular_buffer',
318        'callable_traits',
319        'headers',
320        'process',
321        'type_index',
322        'url',
323        'uuid',
324        'spirit',
325    ]
326    opt.add_cmake_defines(
327        {
328            'CMAKE_CXX_FLAGS': ' '.join(boost_flags),
329            'CMAKE_C_FLAGS': ' '.join(boost_flags),
330            'BOOST_INCLUDE_LIBRARIES': ';'.join(boost_libs),
331            'BUILD_SHARED_LIBS': 'OFF',
332        },
333    )
334
335    boost = cmake.subproject('boost', required: true, options: opt)
336    foreach boost_lib : boost_libs
337        boost_lib_instance = boost.dependency('boost_' + boost_lib).as_system()
338        bmcweb_dependencies += [boost_lib_instance]
339        bmcweb_cli_dependencies += [boost_lib_instance]
340    endforeach
341endif
342
343systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir')
344
345bindir = get_option('prefix') + '/' + get_option('bindir')
346libexec = get_option('prefix') + '/' + get_option('libexecdir')
347
348summary(
349    {
350        'prefix': get_option('prefix'),
351        'bindir': bindir,
352        'systemd unit directory': systemd_system_unit_dir,
353    },
354    section: 'Directories',
355)
356
357subdir('static')
358subdir('redfish-core')
359
360# Config subdirectory
361subdir('config')
362bmcweb_dependencies += conf_h_dep
363bmcweb_cli_dependencies += conf_h_dep
364
365# Source files
366fs = import('fs')
367
368srcfiles_bmcweb = files(
369    'http/mutual_tls.cpp',
370    'http/routing/sserule.cpp',
371    'http/routing/websocketrule.cpp',
372    'redfish-core/src/dbus_log_watcher.cpp',
373    'redfish-core/src/error_message_utils.cpp',
374    'redfish-core/src/error_messages.cpp',
375    'redfish-core/src/event_log.cpp',
376    'redfish-core/src/filesystem_log_watcher.cpp',
377    'redfish-core/src/filter_expr_executor.cpp',
378    'redfish-core/src/filter_expr_printer.cpp',
379    'redfish-core/src/heartbeat_messages.cpp',
380    'redfish-core/src/redfish.cpp',
381    'redfish-core/src/registries.cpp',
382    'redfish-core/src/resource_messages.cpp',
383    'redfish-core/src/subscription.cpp',
384    'redfish-core/src/task_messages.cpp',
385    'redfish-core/src/utils/dbus_utils.cpp',
386    'redfish-core/src/utils/json_utils.cpp',
387    'redfish-core/src/utils/time_utils.cpp',
388    'src/boost_asio.cpp',
389    'src/boost_asio_ssl.cpp',
390    'src/boost_beast.cpp',
391    'src/dbus_singleton.cpp',
392    'src/dbus_utility.cpp',
393    'src/json_html_serializer.cpp',
394    'src/ossl_random.cpp',
395    'src/ssl_key_handler.cpp',
396    'src/webserver_run.cpp',
397)
398
399bmcweblib = static_library(
400    'bmcweblib',
401    srcfiles_bmcweb,
402    include_directories: incdir,
403    dependencies: bmcweb_dependencies,
404)
405
406# Generate the bmcwebd daemon
407executable(
408    'bmcwebd',
409    'src/webserver_main.cpp',
410    include_directories: incdir,
411    dependencies: bmcweb_dependencies,
412    link_with: bmcweblib,
413    link_args: '-Wl,--gc-sections',
414    install: true,
415    install_dir: libexec,
416)
417
418# Generate the bmcweb CLI application
419executable(
420    'bmcweb',
421    ['src/webserver_cli.cpp', 'src/boost_asio.cpp'],
422    include_directories: incdir_cli,
423    dependencies: bmcweb_cli_dependencies,
424    install: true,
425    install_dir: bindir,
426)
427
428srcfiles_unittest = files(
429    'test/http/crow_getroutes_test.cpp',
430    'test/http/http2_connection_test.cpp',
431    'test/http/http_body_test.cpp',
432    'test/http/http_connection_test.cpp',
433    'test/http/http_response_test.cpp',
434    'test/http/mutual_tls.cpp',
435    'test/http/mutual_tls_meta.cpp',
436    'test/http/parsing_test.cpp',
437    'test/http/router_test.cpp',
438    'test/http/server_sent_event_test.cpp',
439    'test/http/utility_test.cpp',
440    'test/http/verb_test.cpp',
441    'test/include/async_resolve_test.cpp',
442    'test/include/credential_pipe_test.cpp',
443    'test/include/dbus_utility_test.cpp',
444    'test/include/google/google_service_root_test.cpp',
445    'test/include/http_utility_test.cpp',
446    'test/include/human_sort_test.cpp',
447    'test/include/ibm/configfile_test.cpp',
448    'test/include/json_html_serializer.cpp',
449    'test/include/multipart_test.cpp',
450    'test/include/openbmc_dbus_rest_test.cpp',
451    'test/include/ossl_random.cpp',
452    'test/include/ssl_key_handler_test.cpp',
453    'test/include/str_utility_test.cpp',
454    'test/redfish-core/include/dbus_log_watcher_test.cpp',
455    'test/redfish-core/include/event_log_test.cpp',
456    'test/redfish-core/include/event_matches_filter_test.cpp',
457    'test/redfish-core/include/filter_expr_executor_test.cpp',
458    'test/redfish-core/include/filter_expr_parser_test.cpp',
459    'test/redfish-core/include/privileges_test.cpp',
460    'test/redfish-core/include/redfish_aggregator_test.cpp',
461    'test/redfish-core/include/redfish_test.cpp',
462    'test/redfish-core/include/registries_test.cpp',
463    'test/redfish-core/include/submit_test_event_test.cpp',
464    'test/redfish-core/include/utils/dbus_utils.cpp',
465    'test/redfish-core/include/utils/error_code_test.cpp',
466    'test/redfish-core/include/utils/hex_utils_test.cpp',
467    'test/redfish-core/include/utils/ip_utils_test.cpp',
468    'test/redfish-core/include/utils/json_utils_test.cpp',
469    'test/redfish-core/include/utils/query_param_test.cpp',
470    'test/redfish-core/include/utils/sensor_utils_test.cpp',
471    'test/redfish-core/include/utils/stl_utils_test.cpp',
472    'test/redfish-core/include/utils/time_utils_test.cpp',
473    'test/redfish-core/lib/chassis_test.cpp',
474    'test/redfish-core/lib/ethernet_test.cpp',
475    'test/redfish-core/lib/log_services_dump_test.cpp',
476    'test/redfish-core/lib/manager_diagnostic_data_test.cpp',
477    'test/redfish-core/lib/metadata_test.cpp',
478    'test/redfish-core/lib/power_subsystem_test.cpp',
479    'test/redfish-core/lib/service_root_test.cpp',
480    'test/redfish-core/lib/system_test.cpp',
481    'test/redfish-core/lib/systems_logservices_postcode.cpp',
482    'test/redfish-core/lib/thermal_subsystem_test.cpp',
483    'test/redfish-core/lib/update_service_test.cpp',
484)
485
486if (get_option('tests').allowed())
487    gtest = dependency(
488        'gtest_main',
489        main: true,
490        version: '>=1.15.0',
491        required: true,
492    )
493    gmock = dependency('gmock', required: true)
494    gtestlib = static_library('gtestlib', dependencies: [gtest, gmock])
495    gtestdep = declare_dependency(
496        link_with: gtestlib,
497        dependencies: [
498            gtest.partial_dependency(includes: true),
499            gmock.partial_dependency(includes: true),
500        ],
501    )
502    # generate the test executable
503    foreach test_src : srcfiles_unittest
504        test_bin = executable(
505            fs.stem(test_src),
506            test_src,
507            link_with: bmcweblib,
508            include_directories: incdir,
509            install_dir: bindir,
510            dependencies: bmcweb_dependencies + [gtestdep],
511        )
512        test(fs.stem(test_src), test_bin, protocol: 'gtest')
513    endforeach
514endif
515