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++20', 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++20' 29 error('This project requires c++20 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(['-fdata-sections', '-ffunction-sections'], language: 'cpp') 43 add_project_arguments('-DNDEBUG', language: 'cpp') 44endif 45 46if (get_option('dns-resolver') == 'systemd-dbus') 47 add_project_arguments('-DBMCWEB_DBUS_DNS_RESOLVER', language: 'cpp') 48endif 49 50# Disable lto when compiling with no optimization 51if (get_option('optimization') == '0') 52 add_project_arguments('-fno-lto', language: 'cpp') 53 message('Disabling lto & its supported features as optimization is disabled') 54endif 55 56# Include Directories 57 58incdir = include_directories('include', 'redfish-core/include', 'redfish-core/lib', 'http') 59 60if (get_option('tests').allowed()) 61 summary('unittest', 'NA', section: 'Features') 62endif 63 64# Add compiler arguments 65 66if (cxx.get_id() == 'clang') 67 if (cxx.version().version_compare('<17.0')) 68 error('This project requires clang-17 or higher') 69 endif 70 add_project_arguments( 71 '-Weverything', 72 '-Wformat=2', 73 '-Wno-c++98-compat-pedantic', 74 '-Wno-c++98-compat', 75 '-Wno-c++20-extensions', 76 '-Wno-documentation-unknown-command', 77 '-Wno-documentation', 78 '-Wno-exit-time-destructors', 79 '-Wno-global-constructors', 80 '-Wno-newline-eof', 81 '-Wno-padded', 82 '-Wno-shadow', 83 '-Wno-used-but-marked-unused', 84 '-Wno-weak-vtables', 85 '-Wno-switch-enum', 86 '-Wno-unused-macros', 87 '-Wno-covered-switch-default', 88 '-Wno-disabled-macro-expansion', 89 language: 'cpp', 90 ) 91endif 92 93if (cxx.get_id() == 'gcc') 94 if (cxx.version().version_compare('<13.0')) 95 error('This project requires gcc-13 or higher') 96 endif 97 98 add_project_arguments( 99 '-Wformat=2', 100 '-Wcast-align', 101 '-Wconversion', 102 '-Woverloaded-virtual', 103 '-Wsign-conversion', 104 '-Wunused', 105 '-Wduplicated-cond', 106 '-Wduplicated-branches', 107 '-Wlogical-op', 108 '-Wnull-dereference', 109 '-Wunused-parameter', 110 '-Wdouble-promotion', 111 '-Wshadow', 112 '-Wno-psabi', 113 '-Wno-attributes', 114 language: 'cpp', 115 ) 116endif 117 118if (get_option('buildtype') != 'plain') 119 if (get_option('b_lto') == true and get_option('optimization') != '0') 120 # Reduce the binary size by removing unnecessary 121 # dynamic symbol table entries 122 123 add_project_arguments( 124 cxx.get_supported_arguments( 125 [ 126 '-fno-fat-lto-objects', 127 '-fvisibility=hidden', 128 '-fvisibility-inlines-hidden', 129 ], 130 ), 131 language: 'cpp', 132 ) 133 134 if cxx.has_link_argument('-Wl,--exclude-libs,ALL') 135 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp') 136 endif 137 endif 138endif 139# Set Compiler Security flags 140 141security_flags = [ 142 '-fstack-protector-strong', 143 '-fPIE', 144 '-fPIC', 145 '-D_FORTIFY_SOURCE=2', 146 '-Wformat', 147 '-Wformat-security', 148] 149 150## Add security flags for builds of type 'release','debugoptimized' and 'minsize' 151 152if not ( 153 get_option('buildtype') == 'plain' 154 or get_option('buildtype').startswith('debug') 155) 156 add_project_arguments(cxx.get_supported_arguments([security_flags]), language: 'cpp') 157endif 158 159# Boost dependency configuration 160 161add_project_arguments( 162 cxx.get_supported_arguments( 163 [ 164 '-DBOOST_ASIO_DISABLE_CONCEPTS', 165 '-DBOOST_ALL_NO_LIB', 166 '-DBOOST_ALLOW_DEPRECATED_HEADERS', 167 '-DBOOST_ASIO_DISABLE_THREADS', 168 '-DBOOST_ASIO_NO_DEPRECATED', 169 '-DBOOST_ASIO_SEPARATE_COMPILATION', 170 '-DBOOST_BEAST_SEPARATE_COMPILATION', 171 '-DBOOST_EXCEPTION_DISABLE', 172 '-DBOOST_NO_EXCEPTIONS', 173 '-DBOOST_URL_NO_SOURCE_LOCATION', 174 '-DBOOST_SPIRIT_X3_NO_RTTI', 175 '-DJSON_NOEXCEPTION', 176 '-DOPENSSL_NO_FILENAMES', 177 '-DSDBUSPLUS_DISABLE_BOOST_COROUTINES', 178 ], 179 ), 180 language: 'cpp', 181) 182 183# Find the dependency modules, if not found use meson wrap to get them 184# automatically during the configure step 185bmcweb_dependencies = [] 186 187pam = cxx.find_library('pam', required: true) 188atomic = cxx.find_library('atomic', required: true) 189bmcweb_dependencies += [pam, atomic] 190 191openssl = dependency('openssl', required: false, version: '>=3.0.0') 192if not openssl.found() or get_option('b_sanitize') != 'none' 193 openssl_proj = subproject( 194 'openssl', 195 required: true, 196 default_options: ['warning_level=0', 'werror=false'], 197 ) 198 openssl = openssl_proj.get_variable('openssl_dep') 199 openssl = openssl.as_system('system') 200endif 201bmcweb_dependencies += [openssl] 202 203nghttp2 = dependency('libnghttp2', version: '>=1.52.0', required: false) 204if not nghttp2.found() 205 cmake = import('cmake') 206 opt_var = cmake.subproject_options() 207 opt_var.add_cmake_defines( 208 { 209 'ENABLE_LIB_ONLY': true, 210 'ENABLE_STATIC_LIB': true, 211 }, 212 ) 213 nghttp2_ex = cmake.subproject('nghttp2', options: opt_var) 214 nghttp2 = nghttp2_ex.dependency('nghttp2') 215endif 216bmcweb_dependencies += nghttp2 217 218sdbusplus = dependency('sdbusplus', required: false, include_type: 'system') 219if not sdbusplus.found() 220 sdbusplus_proj = subproject('sdbusplus', required: true) 221 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep') 222 sdbusplus = sdbusplus.as_system('system') 223endif 224bmcweb_dependencies += sdbusplus 225 226tinyxml = dependency( 227 'tinyxml2', 228 include_type: 'system', 229 version: '>=9.0.0', 230 default_options: ['tests=false'], 231) 232if not tinyxml.found() 233 tinyxml_proj = subproject('tinyxml2', required: true) 234 tinyxml = tinyxml_proj.get_variable('tinyxml_dep') 235 tinyxml = tinyxml.as_system('system') 236endif 237bmcweb_dependencies += tinyxml 238 239systemd = dependency('systemd') 240add_project_arguments('-DSYSTEMD_VERSION=' + systemd.version(), language: 'cpp') 241 242zlib = dependency('zlib') 243bmcweb_dependencies += [systemd, zlib] 244 245nlohmann_json_dep = dependency('nlohmann_json', version: '>=3.11.2', include_type: 'system') 246bmcweb_dependencies += nlohmann_json_dep 247 248boost = dependency( 249 'boost', 250 modules: [ 251 'url', 252 ], 253 version: '>=1.84.0', 254 required: false, 255 include_type: 'system', 256) 257if boost.found() 258 bmcweb_dependencies += [boost] 259else 260 cmake = import('cmake') 261 opt = cmake.subproject_options() 262 opt.add_cmake_defines( 263 { 264 'BOOST_INCLUDE_LIBRARIES': 'asio;beast;callable_traits;headers;process;type_index;url;uuid;spirit', 265 'BUILD_SHARED_LIBS': 'OFF', 266 }, 267 ) 268 269 boost = cmake.subproject('boost', required: true, options: opt) 270 boost_asio = boost.dependency('boost_asio').as_system() 271 boost_beast = boost.dependency('boost_beast').as_system() 272 boost_callable_traits = boost.dependency('boost_callable_traits').as_system() 273 boost_headers = boost.dependency('boost_headers').as_system() 274 boost_process = boost.dependency('boost_process').as_system() 275 boost_type_index = boost.dependency('boost_type_index').as_system() 276 boost_url = boost.dependency('boost_url').as_system() 277 boost_uuid = boost.dependency('boost_uuid').as_system() 278 boost_spirit = boost.dependency('boost_spirit').as_system() 279 bmcweb_dependencies += [ 280 boost_asio, 281 boost_beast, 282 boost_callable_traits, 283 boost_headers, 284 boost_process, 285 boost_type_index, 286 boost_url, 287 boost_uuid, 288 boost_spirit, 289 ] 290endif 291 292if get_option('tests').allowed() 293 gtest = dependency( 294 'gtest', 295 main: true, 296 version: '>=1.14.0', 297 disabler: true, 298 required: false, 299 ) 300 gmock = dependency('gmock', required: false) 301 if not gtest.found() and get_option('tests').allowed() 302 gtest_proj = subproject('gtest', required: true) 303 gtest = gtest_proj.get_variable('gtest_main_dep') 304 gmock = gtest_proj.get_variable('gmock_dep') 305 endif 306 gtest = gtest.as_system('system') 307 gmock = gmock.as_system('system') 308endif 309 310systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir') 311 312bindir = get_option('prefix') + '/' + get_option('bindir') 313 314summary( 315 { 316 'prefix': get_option('prefix'), 317 'bindir': bindir, 318 'systemd unit directory': systemd_system_unit_dir, 319 }, 320 section: 'Directories', 321) 322 323subdir('static') 324subdir('redfish-core') 325 326# Config subdirectory 327subdir('config') 328bmcweb_dependencies += conf_h_dep 329 330# Source files 331fs = import('fs') 332 333srcfiles_bmcweb = files( 334 # end large files 335 336 'redfish-core/src/error_messages.cpp', 337 # Begin large files, should be at the beginning 338 'redfish-core/src/filter_expr_executor.cpp', 339 'redfish-core/src/filter_expr_printer.cpp', 340 'redfish-core/src/redfish.cpp', 341 'redfish-core/src/registries.cpp', 342 'redfish-core/src/utils/dbus_utils.cpp', 343 'redfish-core/src/utils/json_utils.cpp', 344 'redfish-core/src/utils/time_utils.cpp', 345 'src/boost_asio.cpp', 346 'src/boost_asio_ssl.cpp', 347 'src/boost_beast.cpp', 348 'src/dbus_singleton.cpp', 349 'src/json_html_serializer.cpp', 350 'src/ossl_random.cpp', 351 'src/webserver_run.cpp', 352) 353 354bmcweblib = static_library( 355 'bmcweblib', 356 srcfiles_bmcweb, 357 include_directories: incdir, 358 dependencies: bmcweb_dependencies, 359) 360 361# Generate the bmcweb executable 362executable( 363 'bmcweb', 364 'src/webserver_main.cpp', 365 include_directories: incdir, 366 dependencies: bmcweb_dependencies, 367 link_with: bmcweblib, 368 link_args: '-Wl,--gc-sections', 369 install: true, 370 install_dir: bindir, 371) 372 373srcfiles_unittest = files( 374 'test/http/crow_getroutes_test.cpp', 375 'test/http/http2_connection_test.cpp', 376 'test/http/http_body_test.cpp', 377 'test/http/http_connection_test.cpp', 378 'test/http/http_response_test.cpp', 379 'test/http/mutual_tls.cpp', 380 'test/http/mutual_tls_meta.cpp', 381 'test/http/parsing_test.cpp', 382 'test/http/router_test.cpp', 383 'test/http/server_sent_event_test.cpp', 384 'test/http/utility_test.cpp', 385 'test/http/verb_test.cpp', 386 'test/include/async_resolve_test.cpp', 387 'test/include/credential_pipe_test.cpp', 388 'test/include/dbus_utility_test.cpp', 389 'test/include/google/google_service_root_test.cpp', 390 'test/include/http_utility_test.cpp', 391 'test/include/human_sort_test.cpp', 392 'test/include/ibm/configfile_test.cpp', 393 'test/include/json_html_serializer.cpp', 394 'test/include/multipart_test.cpp', 395 'test/include/openbmc_dbus_rest_test.cpp', 396 'test/include/ossl_random.cpp', 397 'test/include/ssl_key_handler_test.cpp', 398 'test/include/str_utility_test.cpp', 399 'test/redfish-core/include/privileges_test.cpp', 400 'test/redfish-core/include/filter_expr_executor_test.cpp', 401 'test/redfish-core/include/filter_expr_parser_test.cpp', 402 'test/redfish-core/include/redfish_aggregator_test.cpp', 403 'test/redfish-core/include/registries_test.cpp', 404 'test/redfish-core/include/utils/dbus_utils.cpp', 405 'test/redfish-core/include/utils/hex_utils_test.cpp', 406 'test/redfish-core/include/utils/ip_utils_test.cpp', 407 'test/redfish-core/include/utils/json_utils_test.cpp', 408 'test/redfish-core/include/utils/query_param_test.cpp', 409 'test/redfish-core/include/utils/stl_utils_test.cpp', 410 'test/redfish-core/include/utils/time_utils_test.cpp', 411 'test/redfish-core/lib/chassis_test.cpp', 412 'test/redfish-core/lib/log_services_dump_test.cpp', 413 'test/redfish-core/lib/log_services_test.cpp', 414 'test/redfish-core/lib/manager_diagnostic_data_test.cpp', 415 'test/redfish-core/lib/metadata_test.cpp', 416 'test/redfish-core/lib/power_subsystem_test.cpp', 417 'test/redfish-core/lib/sensors_test.cpp', 418 'test/redfish-core/lib/service_root_test.cpp', 419 'test/redfish-core/lib/system_test.cpp', 420 'test/redfish-core/lib/thermal_subsystem_test.cpp', 421 'test/redfish-core/lib/update_service_test.cpp', 422) 423 424if (get_option('tests').allowed()) 425 # generate the test executable 426 foreach test_src : srcfiles_unittest 427 test_bin = executable( 428 fs.stem(test_src), 429 test_src, 430 link_with: bmcweblib, 431 include_directories: incdir, 432 install_dir: bindir, 433 dependencies: bmcweb_dependencies 434 + [ 435 gtest, 436 gmock, 437 ], 438 ) 439 test(fs.stem(test_src), test_bin) 440 endforeach 441endif 442