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