xref: /openbmc/bmcweb/meson.build (revision 0183e476)
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
74
75if (cxx.get_id() == 'clang')
76    if (cxx.version().version_compare('<17.0'))
77        error('This project requires clang-17 or higher')
78    endif
79    add_project_arguments(
80        '-Weverything',
81        '-Wformat=2',
82        '-Wno-c++98-compat-pedantic',
83        '-Wno-c++98-compat',
84        '-Wno-c++20-extensions',
85        '-Wno-documentation-unknown-command',
86        '-Wno-documentation',
87        '-Wno-exit-time-destructors',
88        '-Wno-global-constructors',
89        '-Wno-newline-eof',
90        '-Wno-padded',
91        '-Wno-shadow',
92        '-Wno-used-but-marked-unused',
93        '-Wno-weak-vtables',
94        '-Wno-switch-enum',
95        '-Wno-unused-macros',
96        '-Wno-covered-switch-default',
97        '-Wno-disabled-macro-expansion',
98        '-Wno-unneeded-internal-declaration',
99        language: 'cpp',
100    )
101endif
102
103if (cxx.get_id() == 'gcc')
104    if (cxx.version().version_compare('<13.0'))
105        error('This project requires gcc-13 or higher')
106    endif
107
108    add_project_arguments(
109        '-Wformat=2',
110        '-Wcast-align',
111        '-Wconversion',
112        '-Woverloaded-virtual',
113        '-Wsign-conversion',
114        '-Wunused',
115        '-Wduplicated-cond',
116        '-Wduplicated-branches',
117        '-Wlogical-op',
118        '-Wnull-dereference',
119        '-Wunused-parameter',
120        '-Wdouble-promotion',
121        '-Wshadow',
122        '-Wno-psabi',
123        '-Wno-attributes',
124        language: 'cpp',
125    )
126endif
127
128if (get_option('buildtype') != 'plain')
129    if (get_option('b_lto') == true and get_option('optimization') != '0')
130        # Reduce the binary size by removing unnecessary
131        # dynamic symbol table entries
132
133        add_project_arguments(
134            cxx.get_supported_arguments(
135                [
136                    '-fno-fat-lto-objects',
137                    '-fvisibility=hidden',
138                    '-fvisibility-inlines-hidden',
139                ],
140            ),
141            language: 'cpp',
142        )
143
144        if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
145            add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
146        endif
147    endif
148endif
149# Set Compiler Security flags
150
151security_flags = [
152    '-fstack-protector-strong',
153    '-fPIE',
154    '-fPIC',
155    '-D_FORTIFY_SOURCE=2',
156    '-Wformat',
157    '-Wformat-security',
158]
159
160## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
161
162if not (get_option('buildtype') == 'plain'
163or get_option('buildtype').startswith('debug')
164)
165    add_project_arguments(
166        cxx.get_supported_arguments([security_flags]),
167        language: 'cpp',
168    )
169endif
170
171# Boost dependency configuration
172
173add_project_arguments(
174    cxx.get_supported_arguments(
175        [
176            '-DBOOST_ALL_NO_LIB',
177            '-DBOOST_ALLOW_DEPRECATED_HEADERS',
178            '-DBOOST_ASIO_DISABLE_THREADS',
179            '-DBOOST_ASIO_NO_DEPRECATED',
180            '-DBOOST_ASIO_SEPARATE_COMPILATION',
181            '-DBOOST_BEAST_SEPARATE_COMPILATION',
182            '-DBOOST_EXCEPTION_DISABLE',
183            '-DBOOST_NO_EXCEPTIONS',
184            '-DBOOST_URL_NO_SOURCE_LOCATION',
185            '-DBOOST_SPIRIT_X3_NO_RTTI',
186            '-DJSON_NOEXCEPTION',
187            '-DOPENSSL_NO_FILENAMES',
188            '-DSDBUSPLUS_DISABLE_BOOST_COROUTINES',
189        ],
190    ),
191    language: 'cpp',
192)
193
194# Find the dependency modules, if not found use meson wrap to get them
195# automatically during the configure step
196bmcweb_dependencies = []
197bmcweb_cli_dependencies = []
198
199pam = cxx.find_library('pam', required: true)
200atomic = cxx.find_library('atomic', required: true)
201bmcweb_dependencies += [pam, atomic]
202
203openssl = dependency('openssl', required: false, version: '>=3.0.0')
204if not openssl.found() or get_option('b_sanitize') != 'none'
205    openssl_proj = subproject(
206        'openssl',
207        required: true,
208        default_options: ['warning_level=0', 'werror=false'],
209    )
210    openssl = openssl_proj.get_variable('openssl_dep')
211    openssl = openssl.as_system('system')
212endif
213bmcweb_dependencies += [openssl]
214
215nghttp2 = dependency('libnghttp2', version: '>=1.52.0', required: false)
216if not nghttp2.found()
217    cmake = import('cmake')
218    opt_var = cmake.subproject_options()
219    opt_var.add_cmake_defines(
220        {'ENABLE_LIB_ONLY': true, 'ENABLE_STATIC_LIB': true},
221    )
222    nghttp2_ex = cmake.subproject('nghttp2', options: opt_var)
223    nghttp2 = nghttp2_ex.dependency('nghttp2')
224endif
225bmcweb_dependencies += nghttp2
226
227sdbusplus = dependency('sdbusplus', required: false, include_type: 'system')
228if not sdbusplus.found()
229    sdbusplus_proj = subproject('sdbusplus', required: true)
230    sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
231    sdbusplus = sdbusplus.as_system('system')
232endif
233bmcweb_dependencies += sdbusplus
234bmcweb_cli_dependencies += sdbusplus
235
236cli11 = dependency('CLI11', required: false, include_type: 'system')
237if not cli11.found()
238    cli11_proj = subproject('cli11', required: true)
239    cli11 = cli11_proj.get_variable('CLI11_dep')
240    cli11 = cli11.as_system('system')
241endif
242bmcweb_cli_dependencies += cli11
243
244
245tinyxml = dependency(
246    'tinyxml2',
247    include_type: 'system',
248    version: '>=9.0.0',
249    default_options: ['tests=false'],
250)
251if not tinyxml.found()
252    tinyxml_proj = subproject('tinyxml2', required: true)
253    tinyxml = tinyxml_proj.get_variable('tinyxml_dep')
254    tinyxml = tinyxml.as_system('system')
255endif
256bmcweb_dependencies += tinyxml
257
258systemd = dependency('systemd')
259libsystemd = dependency('libsystemd')
260add_project_arguments(
261    '-DLIBSYSTEMD_VERSION=' + libsystemd.version(),
262    language: 'cpp',
263)
264
265zlib = dependency('zlib')
266bmcweb_dependencies += [libsystemd, zlib]
267
268nlohmann_json_dep = dependency(
269    'nlohmann_json',
270    version: '>=3.11.3',
271    include_type: 'system',
272)
273bmcweb_dependencies += nlohmann_json_dep
274
275boost = dependency(
276    'boost',
277    modules: ['url'],
278    version: '>=1.84.0',
279    required: false,
280    include_type: 'system',
281)
282if boost.found()
283    bmcweb_dependencies += [boost]
284    bmcweb_cli_dependencies += [boost]
285else
286    cmake = import('cmake')
287    opt = cmake.subproject_options()
288    boost_libs = [
289        'asio',
290        'beast',
291        'circular_buffer',
292        'callable_traits',
293        'headers',
294        'process',
295        'type_index',
296        'url',
297        'uuid',
298        'spirit',
299    ]
300    opt.add_cmake_defines(
301        {
302            # 1.86.0 fails this.  Hopefully fixed in 1.86.1
303            'CMAKE_CXX_FLAGS': '-Wno-unused-parameter',
304            'BOOST_INCLUDE_LIBRARIES': ';'.join(boost_libs),
305            'BUILD_SHARED_LIBS': 'OFF',
306        },
307    )
308
309    boost = cmake.subproject('boost', required: true, options: opt)
310    foreach boost_lib : boost_libs
311        boost_lib_instance = boost.dependency('boost_' + boost_lib).as_system()
312        bmcweb_dependencies += [boost_lib_instance]
313        bmcweb_cli_dependencies += [boost_lib_instance]
314    endforeach
315endif
316
317systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir')
318
319bindir = get_option('prefix') + '/' + get_option('bindir')
320libexec = get_option('prefix') + '/' + get_option('libexecdir')
321
322summary(
323    {
324        'prefix': get_option('prefix'),
325        'bindir': bindir,
326        'systemd unit directory': systemd_system_unit_dir,
327    },
328    section: 'Directories',
329)
330
331subdir('static')
332subdir('redfish-core')
333
334# Config subdirectory
335subdir('config')
336bmcweb_dependencies += conf_h_dep
337bmcweb_cli_dependencies += conf_h_dep
338
339# Source files
340fs = import('fs')
341
342srcfiles_bmcweb = files(
343    'http/mutual_tls.cpp',
344    'redfish-core/src/error_messages.cpp',
345    'redfish-core/src/filter_expr_executor.cpp',
346    'redfish-core/src/filter_expr_printer.cpp',
347    'redfish-core/src/redfish.cpp',
348    'redfish-core/src/registries.cpp',
349    'redfish-core/src/utils/dbus_utils.cpp',
350    'redfish-core/src/utils/json_utils.cpp',
351    'redfish-core/src/utils/time_utils.cpp',
352    'src/boost_asio.cpp',
353    'src/boost_asio_ssl.cpp',
354    'src/boost_beast.cpp',
355    'src/dbus_singleton.cpp',
356    'src/json_html_serializer.cpp',
357    'src/ossl_random.cpp',
358    'src/ssl_key_handler.cpp',
359    'src/webserver_run.cpp',
360)
361
362bmcweblib = static_library(
363    'bmcweblib',
364    srcfiles_bmcweb,
365    include_directories: incdir,
366    dependencies: bmcweb_dependencies,
367)
368
369# Generate the bmcwebd daemon
370executable(
371    'bmcwebd',
372    'src/webserver_main.cpp',
373    include_directories: incdir,
374    dependencies: bmcweb_dependencies,
375    link_with: bmcweblib,
376    link_args: '-Wl,--gc-sections',
377    install: true,
378    install_dir: libexec,
379)
380
381# Generate the bmcweb CLI application
382executable(
383    'bmcweb',
384    ['src/webserver_cli.cpp', 'src/boost_asio.cpp'],
385    include_directories: incdir_cli,
386    dependencies: bmcweb_cli_dependencies,
387    install: true,
388    install_dir: bindir,
389)
390
391srcfiles_unittest = files(
392    'test/http/crow_getroutes_test.cpp',
393    'test/http/http2_connection_test.cpp',
394    'test/http/http_body_test.cpp',
395    'test/http/http_connection_test.cpp',
396    'test/http/http_response_test.cpp',
397    'test/http/mutual_tls.cpp',
398    'test/http/mutual_tls_meta.cpp',
399    'test/http/parsing_test.cpp',
400    'test/http/router_test.cpp',
401    'test/http/server_sent_event_test.cpp',
402    'test/http/utility_test.cpp',
403    'test/http/verb_test.cpp',
404    'test/include/async_resolve_test.cpp',
405    'test/include/credential_pipe_test.cpp',
406    'test/include/dbus_utility_test.cpp',
407    'test/include/google/google_service_root_test.cpp',
408    'test/include/http_utility_test.cpp',
409    'test/include/human_sort_test.cpp',
410    'test/include/ibm/configfile_test.cpp',
411    'test/include/json_html_serializer.cpp',
412    'test/include/multipart_test.cpp',
413    'test/include/openbmc_dbus_rest_test.cpp',
414    'test/include/ossl_random.cpp',
415    'test/include/ssl_key_handler_test.cpp',
416    'test/include/str_utility_test.cpp',
417    'test/redfish-core/include/event_matches_filter_test.cpp',
418    'test/redfish-core/include/filter_expr_executor_test.cpp',
419    'test/redfish-core/include/filter_expr_parser_test.cpp',
420    'test/redfish-core/include/privileges_test.cpp',
421    'test/redfish-core/include/redfish_aggregator_test.cpp',
422    'test/redfish-core/include/registries_test.cpp',
423    'test/redfish-core/include/utils/dbus_utils.cpp',
424    'test/redfish-core/include/utils/hex_utils_test.cpp',
425    'test/redfish-core/include/utils/ip_utils_test.cpp',
426    'test/redfish-core/include/utils/json_utils_test.cpp',
427    'test/redfish-core/include/redfish_test.cpp',
428    'test/redfish-core/include/utils/query_param_test.cpp',
429    'test/redfish-core/include/utils/sensor_utils_test.cpp',
430    'test/redfish-core/include/utils/stl_utils_test.cpp',
431    'test/redfish-core/include/utils/time_utils_test.cpp',
432    'test/redfish-core/lib/chassis_test.cpp',
433    'test/redfish-core/lib/log_services_dump_test.cpp',
434    'test/redfish-core/lib/manager_diagnostic_data_test.cpp',
435    'test/redfish-core/lib/manager_logservices_journal_test.cpp',
436    'test/redfish-core/lib/metadata_test.cpp',
437    'test/redfish-core/lib/power_subsystem_test.cpp',
438    'test/redfish-core/lib/service_root_test.cpp',
439    'test/redfish-core/lib/system_test.cpp',
440    'test/redfish-core/lib/systems_logservices_postcode.cpp',
441    'test/redfish-core/lib/thermal_subsystem_test.cpp',
442    'test/redfish-core/lib/update_service_test.cpp',
443)
444
445if (get_option('tests').allowed())
446    gtest = dependency(
447        'gtest_main',
448        main: true,
449        version: '>=1.15.0',
450        required: true,
451    )
452    gmock = dependency('gmock', required: true)
453    gtestlib = static_library('gtestlib', dependencies: [gtest, gmock])
454    gtestdep = declare_dependency(
455        link_with: gtestlib,
456        dependencies: [
457            gtest.partial_dependency(includes: true),
458            gmock.partial_dependency(includes: true),
459        ],
460    )
461    # generate the test executable
462    foreach test_src : srcfiles_unittest
463        test_bin = executable(
464            fs.stem(test_src),
465            test_src,
466            link_with: bmcweblib,
467            include_directories: incdir,
468            install_dir: bindir,
469            dependencies: bmcweb_dependencies + [gtestdep],
470        )
471        test(fs.stem(test_src), test_bin, protocol: 'gtest')
472    endforeach
473endif
474