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