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