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_NO_IO', 201 '-DJSON_USE_IMPLICIT_CONVERSIONS=0', 202 '-DOPENSSL_NO_FILENAMES', 203 '-DSDBUSPLUS_DISABLE_BOOST_COROUTINES', 204 ], 205 ), 206 language: 'cpp', 207) 208 209# Find the dependency modules, if not found use meson wrap to get them 210# automatically during the configure step 211bmcweb_dependencies = [] 212 213pam = cxx.find_library('pam', required: true) 214atomic = cxx.find_library('atomic', required: true) 215bmcweb_dependencies += [pam, atomic] 216 217openssl = dependency('openssl', required: false, version: '>=3.0.0') 218if not openssl.found() 219 openssl_proj = subproject( 220 'openssl', 221 required: true, 222 default_options: ['warning_level=0', 'werror=false'], 223 ) 224 openssl = openssl_proj.get_variable('openssl_dep') 225 openssl = openssl.as_system('system') 226endif 227bmcweb_dependencies += [openssl] 228 229zstd = dependency('libzstd', required: get_option('http-zstd').allowed()) 230if zstd.found() 231 add_project_arguments('-DHAVE_ZSTD', language: 'cpp') 232 bmcweb_dependencies += [zstd] 233endif 234nghttp2 = dependency('libnghttp2', version: '>=1.52.0', required: false) 235if not nghttp2.found() 236 cmake = import('cmake') 237 opt_var = cmake.subproject_options() 238 opt_var.add_cmake_defines( 239 { 240 'CMAKE_C_FLAGS': ' '.join(nghttp2_flags), 241 'CMAKE_CXX_FLAGS': ' '.join(nghttp2_flags), 242 'ENABLE_LIB_ONLY': true, 243 'ENABLE_STATIC_LIB': true, 244 }, 245 ) 246 nghttp2_ex = cmake.subproject('nghttp2', options: opt_var) 247 nghttp2 = nghttp2_ex.dependency('nghttp2') 248endif 249bmcweb_dependencies += nghttp2 250 251sdbusplus = dependency('sdbusplus') 252bmcweb_dependencies += sdbusplus 253 254cli11 = dependency('CLI11', required: false, include_type: 'system') 255if not cli11.found() 256 cli11_proj = subproject('cli11', required: true) 257 cli11 = cli11_proj.get_variable('CLI11_dep') 258 cli11 = cli11.as_system('system') 259endif 260bmcweb_dependencies += cli11 261 262tinyxml = dependency( 263 'tinyxml2', 264 include_type: 'system', 265 version: '>=9.0.0', 266 default_options: ['tests=false'], 267) 268if not tinyxml.found() 269 tinyxml_proj = subproject('tinyxml2', required: true) 270 tinyxml = tinyxml_proj.get_variable('tinyxml_dep') 271 tinyxml = tinyxml.as_system('system') 272endif 273bmcweb_dependencies += tinyxml 274 275systemd = dependency('systemd') 276libsystemd = dependency('libsystemd') 277add_project_arguments( 278 '-DLIBSYSTEMD_VERSION=' + libsystemd.version(), 279 language: 'cpp', 280) 281 282zlib = dependency('zlib') 283bmcweb_dependencies += [libsystemd, zlib] 284 285nlohmann_json_dep = dependency( 286 'nlohmann_json', 287 version: '>=3.11.3', 288 include_type: 'system', 289) 290bmcweb_dependencies += nlohmann_json_dep 291 292boost = dependency( 293 'boost', 294 modules: ['url'], 295 version: '>=1.84.0', 296 required: false, 297 static: true, 298 include_type: 'system', 299) 300 301# Boost version is 1.86 or higher to include the 'process' module 302if boost.version().version_compare('>=1.86.0') 303 boost = dependency( 304 'boost', 305 modules: ['url', 'process'], 306 version: '>=1.86.0', 307 static: true, 308 required: false, 309 include_type: 'system', 310 ) 311endif 312 313if boost.found() 314 bmcweb_dependencies += [boost] 315else 316 cmake = import('cmake') 317 opt = cmake.subproject_options() 318 boost_libs = [ 319 'asio', 320 'beast', 321 'circular_buffer', 322 'callable_traits', 323 'headers', 324 'process', 325 'type_index', 326 'url', 327 'uuid', 328 'spirit', 329 ] 330 opt.add_cmake_defines( 331 { 332 'CMAKE_CXX_FLAGS': ' '.join(boost_flags), 333 'CMAKE_C_FLAGS': ' '.join(boost_flags), 334 'BOOST_INCLUDE_LIBRARIES': ';'.join(boost_libs), 335 'BUILD_SHARED_LIBS': 'OFF', 336 }, 337 ) 338 339 boost = cmake.subproject('boost', required: true, options: opt) 340 foreach boost_lib : boost_libs 341 boost_lib_instance = boost.dependency('boost_' + boost_lib).as_system() 342 bmcweb_dependencies += [boost_lib_instance] 343 endforeach 344endif 345 346systemd_system_unit_dir = systemd.get_variable('systemd_system_unit_dir') 347 348bindir = get_option('prefix') + '/' + get_option('bindir') 349 350summary( 351 { 352 'prefix': get_option('prefix'), 353 'bindir': bindir, 354 'systemd unit directory': systemd_system_unit_dir, 355 }, 356 section: 'Directories', 357) 358 359subdir('static') 360subdir('redfish-core') 361 362# Config subdirectory 363subdir('config') 364bmcweb_dependencies += conf_h_dep 365 366test_sources = [] 367subdir('features') 368 369# Source files 370fs = import('fs') 371 372srcfiles_bmcweb = files( 373 'http/mutual_tls.cpp', 374 'http/routing/sserule.cpp', 375 'http/routing/websocketrule.cpp', 376 'http/zstd_decompressor.cpp', 377 'redfish-core/src/dbus_log_watcher.cpp', 378 'redfish-core/src/error_message_utils.cpp', 379 'redfish-core/src/error_messages.cpp', 380 'redfish-core/src/event_log.cpp', 381 'redfish-core/src/filesystem_log_watcher.cpp', 382 'redfish-core/src/filter_expr_executor.cpp', 383 'redfish-core/src/filter_expr_printer.cpp', 384 'redfish-core/src/heartbeat_messages.cpp', 385 'redfish-core/src/redfish.cpp', 386 'redfish-core/src/registries.cpp', 387 'redfish-core/src/resource_messages.cpp', 388 'redfish-core/src/subscription.cpp', 389 'redfish-core/src/task_messages.cpp', 390 'redfish-core/src/update_messages.cpp', 391 'redfish-core/src/utils/dbus_utils.cpp', 392 'redfish-core/src/utils/json_utils.cpp', 393 'redfish-core/src/utils/time_utils.cpp', 394 'src/boost_asio.cpp', 395 'src/boost_asio_ssl.cpp', 396 'src/boost_beast.cpp', 397 'src/dbus_singleton.cpp', 398 'src/dbus_utility.cpp', 399 'src/json_html_serializer.cpp', 400 'src/ossl_random.cpp', 401 'src/ssl_key_handler.cpp', 402 'src/webserver_cli.cpp', 403 'src/webserver_run.cpp', 404) 405 406bmcweblib = static_library( 407 'bmcweblib', 408 srcfiles_bmcweb, 409 include_directories: incdir, 410 dependencies: bmcweb_dependencies, 411) 412 413# Generate the bmcweb daemon 414executable( 415 'bmcweb', 416 'src/webserver_main.cpp', 417 include_directories: incdir, 418 dependencies: bmcweb_dependencies, 419 link_with: bmcweblib, 420 link_args: '-Wl,--gc-sections', 421 install: true, 422 install_dir: bindir, 423) 424 425subdir('test') 426