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