xref: /openbmc/bmcweb/meson.build (revision 8de054255f8758a7ed6af0a2594ba0b623e43b65)
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
60incdir = [
61    include_directories(
62        'include',
63        'redfish-core/include',
64        'redfish-core/lib',
65        'http',
66    ),
67]
68
69# Add compiler arguments
70boost_flags = ['-Wno-unused-parameter']
71nghttp2_flags = []
72if (cxx.get_id() == 'clang')
73    if (cxx.version().version_compare('<17.0'))
74        error('This project requires clang-17 or higher')
75    endif
76    add_project_arguments(
77        '-Weverything',
78        '-Wformat=2',
79        # https://github.com/llvm/llvm-project/issues/101614
80        '-fno-builtin-std-forward_like',
81        '-Wno-c++20-extensions',
82        '-Wno-c++26-extensions',
83        '-Wno-c++98-compat',
84        '-Wno-c++98-compat-pedantic',
85        '-Wno-covered-switch-default',
86        '-Wno-disabled-macro-expansion',
87        '-Wno-documentation',
88        '-Wno-documentation-unknown-command',
89        '-Wno-exit-time-destructors',
90        '-Wno-global-constructors',
91        '-Wno-missing-include-dirs',
92        '-Wno-newline-eof',
93        '-Wno-padded',
94        '-Wno-shadow',
95        '-Wno-switch-enum',
96        '-Wno-unneeded-internal-declaration',
97        '-Wno-unsafe-buffer-usage-in-container',
98        '-Wno-unsafe-buffer-usage-in-libc-call',
99        '-Wno-unused-macros',
100        '-Wno-used-but-marked-unused',
101        '-Wno-weak-vtables',
102        language: 'cpp',
103    )
104    if (cxx.version().version_compare('>=21.0'))
105        # TODO(Ed) These warnings look valid and need cleaned up.
106        add_project_arguments(
107            '-Wno-unique-object-duplication',
108            '-Wno-nrvo',
109            language: 'cpp',
110        )
111    endif
112
113    boost_flags += ['-Wno-strict-prototypes', '-Wno-unused-but-set-variable']
114    nghttp2_flags += ['-Wno-extra-semi']
115endif
116
117if (cxx.get_id() == 'gcc')
118    if (cxx.version().version_compare('<13.0'))
119        error('This project requires gcc-13 or higher')
120    endif
121
122    add_project_arguments(
123        '-Wformat=2',
124        '-Wcast-align',
125        '-Wconversion',
126        '-Woverloaded-virtual',
127        '-Wsign-conversion',
128        '-Wunused',
129        '-Wduplicated-cond',
130        '-Wduplicated-branches',
131        '-Wlogical-op',
132        '-Wnull-dereference',
133        '-Wunused-parameter',
134        '-Wdouble-promotion',
135        '-Wshadow',
136        '-Wno-psabi',
137        '-Wno-attributes',
138        language: 'cpp',
139    )
140endif
141
142if (get_option('buildtype') != 'plain')
143    if (get_option('b_lto') == true and get_option('optimization') != '0')
144        # Reduce the binary size by removing unnecessary
145        # dynamic symbol table entries
146
147        add_project_arguments(
148            cxx.get_supported_arguments(
149                [
150                    '-fno-fat-lto-objects',
151                    '-fvisibility=hidden',
152                    '-fvisibility-inlines-hidden',
153                ],
154            ),
155            language: 'cpp',
156        )
157
158        if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
159            add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
160        endif
161    endif
162endif
163# Set Compiler Security flags
164
165security_flags = [
166    '-fstack-protector-strong',
167    '-fPIE',
168    '-fPIC',
169    '-D_FORTIFY_SOURCE=2',
170    '-Wformat',
171    '-Wformat-security',
172]
173
174## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
175plain = get_option('buildtype') == 'plain'
176debug = get_option('buildtype').startswith('debug')
177if not (plain or debug)
178    add_project_arguments(
179        cxx.get_supported_arguments([security_flags]),
180        language: 'cpp',
181    )
182endif
183
184# Boost dependency configuration
185
186add_project_arguments(
187    cxx.get_supported_arguments(
188        [
189            '-DBOOST_ALL_NO_LIB',
190            '-DBOOST_ALLOW_DEPRECATED_HEADERS',
191            '-DBOOST_ASIO_DISABLE_THREADS',
192            '-DBOOST_ASIO_NO_DEPRECATED',
193            '-DBOOST_ASIO_SEPARATE_COMPILATION',
194            '-DBOOST_BEAST_SEPARATE_COMPILATION',
195            '-DBOOST_EXCEPTION_DISABLE',
196            '-DBOOST_NO_EXCEPTIONS',
197            '-DBOOST_URL_NO_SOURCE_LOCATION',
198            '-DBOOST_SPIRIT_X3_NO_RTTI',
199            '-DJSON_NOEXCEPTION',
200            '-DJSON_USE_IMPLICIT_CONVERSIONS=0',
201            '-DOPENSSL_NO_FILENAMES',
202            '-DSDBUSPLUS_DISABLE_BOOST_COROUTINES',
203        ],
204    ),
205    language: 'cpp',
206)
207
208# Find the dependency modules, if not found use meson wrap to get them
209# automatically during the configure step
210bmcweb_dependencies = []
211
212pam = cxx.find_library('pam', required: true)
213atomic = cxx.find_library('atomic', required: true)
214bmcweb_dependencies += [pam, atomic]
215
216openssl = dependency('openssl', required: false, version: '>=3.0.0')
217if not openssl.found()
218    openssl_proj = subproject(
219        'openssl',
220        required: true,
221        default_options: ['warning_level=0', 'werror=false'],
222    )
223    openssl = openssl_proj.get_variable('openssl_dep')
224    openssl = openssl.as_system('system')
225endif
226bmcweb_dependencies += [openssl]
227
228zstd = dependency('libzstd', required: get_option('http-zstd').allowed())
229if zstd.found()
230    add_project_arguments('-DHAVE_ZSTD', language: 'cpp')
231    bmcweb_dependencies += [zstd]
232endif
233nghttp2 = dependency('libnghttp2', version: '>=1.52.0', required: false)
234if not nghttp2.found()
235    cmake = import('cmake')
236    opt_var = cmake.subproject_options()
237    opt_var.add_cmake_defines(
238        {
239            'CMAKE_C_FLAGS': ' '.join(nghttp2_flags),
240            'CMAKE_CXX_FLAGS': ' '.join(nghttp2_flags),
241            'ENABLE_LIB_ONLY': true,
242            'ENABLE_STATIC_LIB': true,
243        },
244    )
245    nghttp2_ex = cmake.subproject('nghttp2', options: opt_var)
246    nghttp2 = nghttp2_ex.dependency('nghttp2')
247endif
248bmcweb_dependencies += nghttp2
249
250sdbusplus = dependency('sdbusplus')
251bmcweb_dependencies += sdbusplus
252
253cli11 = dependency('CLI11', required: false, include_type: 'system')
254if not cli11.found()
255    cli11_proj = subproject('cli11', required: true)
256    cli11 = cli11_proj.get_variable('CLI11_dep')
257    cli11 = cli11.as_system('system')
258endif
259bmcweb_dependencies += cli11
260
261tinyxml = dependency(
262    'tinyxml2',
263    include_type: 'system',
264    version: '>=9.0.0',
265    default_options: ['tests=false'],
266)
267if not tinyxml.found()
268    tinyxml_proj = subproject('tinyxml2', required: true)
269    tinyxml = tinyxml_proj.get_variable('tinyxml_dep')
270    tinyxml = tinyxml.as_system('system')
271endif
272bmcweb_dependencies += tinyxml
273
274systemd = dependency('systemd')
275libsystemd = dependency('libsystemd')
276add_project_arguments(
277    '-DLIBSYSTEMD_VERSION=' + libsystemd.version(),
278    language: 'cpp',
279)
280
281zlib = dependency('zlib')
282bmcweb_dependencies += [libsystemd, zlib]
283
284nlohmann_json_dep = dependency(
285    'nlohmann_json',
286    version: '>=3.11.3',
287    include_type: 'system',
288)
289bmcweb_dependencies += nlohmann_json_dep
290
291boost = dependency(
292    'boost',
293    modules: ['url'],
294    version: '>=1.84.0',
295    required: false,
296    static: true,
297    include_type: 'system',
298)
299
300# Boost version is 1.86 or higher to include the 'process' module
301if boost.version().version_compare('>=1.86.0')
302    boost = dependency(
303        'boost',
304        modules: ['url', 'process'],
305        version: '>=1.86.0',
306        static: true,
307        required: false,
308        include_type: 'system',
309    )
310endif
311
312if boost.found()
313    bmcweb_dependencies += [boost]
314else
315    cmake = import('cmake')
316    opt = cmake.subproject_options()
317    boost_libs = [
318        'asio',
319        'beast',
320        'circular_buffer',
321        'callable_traits',
322        'headers',
323        'process',
324        'type_index',
325        'url',
326        'uuid',
327        'spirit',
328    ]
329    opt.add_cmake_defines(
330        {
331            'CMAKE_CXX_FLAGS': ' '.join(boost_flags),
332            'CMAKE_C_FLAGS': ' '.join(boost_flags),
333            'BOOST_INCLUDE_LIBRARIES': ';'.join(boost_libs),
334            'BUILD_SHARED_LIBS': 'OFF',
335        },
336    )
337
338    boost = cmake.subproject('boost', required: true, options: opt)
339    foreach boost_lib : boost_libs
340        boost_lib_instance = boost.dependency('boost_' + boost_lib).as_system()
341        bmcweb_dependencies += [boost_lib_instance]
342    endforeach
343endif
344
345systemd_system_unit_dir = systemd.get_variable('systemd_system_unit_dir')
346
347bindir = get_option('prefix') + '/' + get_option('bindir')
348
349summary(
350    {
351        'prefix': get_option('prefix'),
352        'bindir': bindir,
353        'systemd unit directory': systemd_system_unit_dir,
354    },
355    section: 'Directories',
356)
357
358subdir('static')
359subdir('redfish-core')
360
361# Config subdirectory
362subdir('config')
363bmcweb_dependencies += conf_h_dep
364
365test_sources = []
366subdir('features')
367
368# Source files
369fs = import('fs')
370
371srcfiles_bmcweb = files(
372    'http/mutual_tls.cpp',
373    'http/routing/sserule.cpp',
374    'http/routing/websocketrule.cpp',
375    'http/zstd_decompressor.cpp',
376    'redfish-core/src/dbus_log_watcher.cpp',
377    'redfish-core/src/error_message_utils.cpp',
378    'redfish-core/src/error_messages.cpp',
379    'redfish-core/src/event_log.cpp',
380    'redfish-core/src/filesystem_log_watcher.cpp',
381    'redfish-core/src/filter_expr_executor.cpp',
382    'redfish-core/src/filter_expr_printer.cpp',
383    'redfish-core/src/heartbeat_messages.cpp',
384    'redfish-core/src/redfish.cpp',
385    'redfish-core/src/registries.cpp',
386    'redfish-core/src/resource_messages.cpp',
387    'redfish-core/src/subscription.cpp',
388    'redfish-core/src/task_messages.cpp',
389    'redfish-core/src/update_messages.cpp',
390    'redfish-core/src/utils/dbus_utils.cpp',
391    'redfish-core/src/utils/json_utils.cpp',
392    'redfish-core/src/utils/time_utils.cpp',
393    'src/boost_asio.cpp',
394    'src/boost_asio_ssl.cpp',
395    'src/boost_beast.cpp',
396    'src/dbus_singleton.cpp',
397    'src/dbus_utility.cpp',
398    'src/json_html_serializer.cpp',
399    'src/ossl_random.cpp',
400    'src/ssl_key_handler.cpp',
401    'src/webserver_cli.cpp',
402    'src/webserver_run.cpp',
403)
404
405bmcweblib = static_library(
406    'bmcweblib',
407    srcfiles_bmcweb,
408    include_directories: incdir,
409    dependencies: bmcweb_dependencies,
410)
411
412# Generate the bmcweb daemon
413executable(
414    'bmcweb',
415    'src/webserver_main.cpp',
416    include_directories: incdir,
417    dependencies: bmcweb_dependencies,
418    link_with: bmcweblib,
419    link_args: '-Wl,--gc-sections',
420    install: true,
421    install_dir: bindir,
422)
423
424subdir('test')
425