1project('bmcweb', 'cpp', 2 version : '1.0', 3 meson_version: '>=0.63.0', 4 default_options: [ 5 'b_lto_mode=default', 6 'b_lto_threads=0', 7 'b_lto=true', 8 'b_ndebug=if-release', 9 'buildtype=debugoptimized', 10 'cpp_rtti=false', 11 'cpp_std=c++20', 12 'warning_level=3', 13 'werror=true', 14 ]) 15 16# Project related links 17 18project_pretty_name = 'bmcweb' 19project_url = 'https://github.com/openbmc/' + project_pretty_name 20project_issues_url = project_url + '/issues/new' 21summary('Issues',project_issues_url, section: 'Report Issues') 22 23# Validate the c++ Standard 24 25if get_option('cpp_std') != 'c++20' 26 error('This project requires c++20 support') 27endif 28 29# Get compiler and default build type 30 31cxx = meson.get_compiler('cpp') 32build = get_option('buildtype') 33optimization = get_option('optimization') 34summary('Build Type',build, section : 'Build Info') 35summary('Optimization',optimization, section : 'Build Info') 36 37 38# remove debug information for minsize buildtype 39if(get_option('buildtype') == 'minsize') 40 add_project_arguments(['-fdata-sections', '-ffunction-sections'], language : 'cpp') 41 add_project_arguments('-DNDEBUG', language : 'cpp') 42endif 43 44if(get_option('dns-resolver') == 'systemd-dbus') 45 add_project_arguments('-DBMCWEB_DBUS_DNS_RESOLVER', language : 'cpp') 46endif 47 48# Disable lto when compiling with no optimization 49if(get_option('optimization') == '0') 50 add_project_arguments('-fno-lto', language: 'cpp') 51 message('Disabling lto & its supported features as optimization is disabled') 52endif 53 54# Include Directories 55 56incdir = include_directories( 57 'include', 58 'redfish-core/include', 59 'redfish-core/lib', 60 'http' 61) 62 63# Get the options and enable the respective features 64## create a MAP of "options : feature_flag" 65 66feature_map = { 67 'basic-auth' : '-DBMCWEB_ENABLE_BASIC_AUTHENTICATION', 68 'cookie-auth' : '-DBMCWEB_ENABLE_COOKIE_AUTHENTICATION', 69 'google-api' : '-DBMCWEB_ENABLE_GOOGLE_API', 70 'host-serial-socket' : '-DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET', 71 'ibm-management-console' : '-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE', 72 'insecure-disable-auth' : '-DBMCWEB_INSECURE_DISABLE_AUTHX', 73 'insecure-disable-csrf' : '-DBMCWEB_INSECURE_DISABLE_CSRF_PREVENTION', 74 'insecure-disable-ssl' : '-DBMCWEB_INSECURE_DISABLE_SSL', 75 'insecure-push-style-notification' : '-DBMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING', 76 'insecure-tftp-update' : '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE', 77 'insecure-ignore-content-type' : '-DBMCWEB_INSECURE_IGNORE_CONTENT_TYPE', 78 'kvm' : '-DBMCWEB_ENABLE_KVM' , 79 'mutual-tls-auth' : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION', 80 'redfish-aggregation' : '-DBMCWEB_ENABLE_REDFISH_AGGREGATION', 81 'redfish-allow-deprecated-power-thermal' : '-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL', 82 'redfish-bmc-journal' : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL', 83 'redfish-cpu-log' : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG', 84 'redfish-dbus-log' : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES', 85 'redfish-dump-log' : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG', 86 'redfish-host-logger' : '-DBMCWEB_ENABLE_REDFISH_HOST_LOGGER', 87 'redfish-new-powersubsystem-thermalsubsystem' : '-DBMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM', 88 'redfish-oem-manager-fan-data' : '-DBMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA', 89 'redfish-provisioning-feature' : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE', 90 'redfish' : '-DBMCWEB_ENABLE_REDFISH', 91 'rest' : '-DBMCWEB_ENABLE_DBUS_REST', 92 'session-auth' : '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION', 93 'static-hosting' : '-DBMCWEB_ENABLE_STATIC_HOSTING', 94 'experimental-redfish-multi-computer-system' : '-DBMCWEB_ENABLE_MULTI_COMPUTERSYSTEM', 95 'vm-websocket' : '-DBMCWEB_ENABLE_VM_WEBSOCKET', 96 'xtoken-auth' : '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION', 97 #'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY', 98} 99 100# Get the options status and build a project summary to show which flags are 101# being enabled during the configuration time. 102 103foreach option_key,option_value : feature_map 104 if(get_option(option_key).allowed()) 105 if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl') 106 if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled()) 107 add_project_arguments(option_value,language:'cpp') 108 summary(option_key,option_value, section : 'Enabled Features') 109 endif 110 elif (option_key in ['basic-auth', 'cookie-auth', 'session-auth', 'xtoken-auth', 'mutual-tls-auth']) 111 if (get_option('insecure-disable-auth').disabled()) 112 add_project_arguments(option_value, language:'cpp') 113 summary(option_key,option_value, section : 'Enabled Features') 114 endif 115 else 116 summary(option_key,option_value, section : 'Enabled Features') 117 add_project_arguments(option_value,language:'cpp') 118 endif 119 else 120 if(option_key == 'insecure-disable-ssl') 121 summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features') 122 add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp') 123 endif 124 endif 125endforeach 126 127if(get_option('tests').allowed()) 128 summary('unittest','NA', section : 'Enabled Features') 129endif 130 131# Add compiler arguments 132 133if (cxx.get_id() == 'clang') 134 if (cxx.version().version_compare('<17.0')) 135 error('This project requires clang-17 or higher') 136 endif 137 add_project_arguments( 138 '-Weverything', 139 '-Wformat=2', 140 '-Wno-c++98-compat-pedantic', 141 '-Wno-c++98-compat', 142 '-Wno-documentation-unknown-command', 143 '-Wno-documentation', 144 '-Wno-exit-time-destructors', 145 '-Wno-global-constructors', 146 '-Wno-newline-eof', 147 '-Wno-padded', 148 '-Wno-shadow', 149 '-Wno-used-but-marked-unused', 150 '-Wno-weak-vtables', 151 '-Wno-switch-enum', 152 '-Wno-unused-macros', 153 '-Wno-covered-switch-default', 154 language:'cpp') 155endif 156 157if (cxx.get_id() == 'gcc') 158 if (cxx.version().version_compare('<13.0')) 159 error('This project requires gcc-13 or higher') 160 endif 161 162 add_project_arguments( 163 '-Wformat=2', 164 '-Wcast-align', 165 '-Wconversion', 166 '-Woverloaded-virtual', 167 '-Wsign-conversion', 168 '-Wunused', 169 '-Wduplicated-cond', 170 '-Wduplicated-branches', 171 '-Wlogical-op', 172 '-Wnull-dereference', 173 '-Wunused-parameter', 174 '-Wdouble-promotion', 175 '-Wshadow', 176 '-Wno-psabi', 177 '-Wno-attributes', 178 language:'cpp') 179endif 180 181if (get_option('buildtype') != 'plain') 182 if (get_option('b_lto') == true and get_option('optimization')!='0') 183 # Reduce the binary size by removing unnecessary 184 # dynamic symbol table entries 185 186 add_project_arguments( 187 cxx.get_supported_arguments([ 188 '-fno-fat-lto-objects', 189 '-fvisibility=hidden', 190 '-fvisibility-inlines-hidden' 191 ]), 192 language: 'cpp') 193 194 if cxx.has_link_argument('-Wl,--exclude-libs,ALL') 195 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp') 196 endif 197 endif 198endif 199 200if( get_option('bmcweb-logging') != 'disabled' or \ 201 get_option('buildtype').startswith('debug')) 202 add_project_arguments([ 203 '-DBMCWEB_ENABLE_DEBUG' 204 ], 205 language : 'cpp') 206 207 summary('debug', '-DBMCWEB_ENABLE_DEBUG', section : 'Enabled Features') 208endif 209 210# Set Compiler Security flags 211 212security_flags = [ 213 '-fstack-protector-strong', 214 '-fPIE', 215 '-fPIC', 216 '-D_FORTIFY_SOURCE=2', 217 '-Wformat', 218 '-Wformat-security' 219] 220 221## Add security flags for builds of type 'release','debugoptimized' and 'minsize' 222 223if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug')) 224 add_project_arguments( 225 cxx.get_supported_arguments([ 226 security_flags 227 ]), 228 language: 'cpp') 229endif 230 231# Boost dependency configuration 232 233add_project_arguments( 234cxx.get_supported_arguments([ 235 '-DBOOST_ASIO_DISABLE_CONCEPTS', 236 '-DBOOST_ALL_NO_LIB', 237 '-DBOOST_ALLOW_DEPRECATED_HEADERS', 238 '-DBOOST_ASIO_DISABLE_THREADS', 239 '-DBOOST_ASIO_NO_DEPRECATED', 240 '-DBOOST_ASIO_SEPARATE_COMPILATION', 241 '-DBOOST_BEAST_SEPARATE_COMPILATION', 242 '-DBOOST_EXCEPTION_DISABLE', 243 '-DBOOST_NO_EXCEPTIONS', 244 '-DBOOST_URL_NO_SOURCE_LOCATION', 245 '-DJSON_NOEXCEPTION', 246 '-DOPENSSL_NO_FILENAMES', 247 '-DSDBUSPLUS_DISABLE_BOOST_COROUTINES', 248]), 249language : 'cpp') 250 251# Find the dependency modules, if not found use meson wrap to get them 252# automatically during the configure step 253bmcweb_dependencies = [] 254 255pam = cxx.find_library('pam', required: true) 256atomic = cxx.find_library('atomic', required: true) 257bmcweb_dependencies += [pam, atomic] 258 259openssl = dependency('openssl', required : false, version: '>=3.0.0') 260if not openssl.found() or get_option('b_sanitize') != 'none' 261 openssl_proj = subproject( 262 'openssl', 263 required: true, 264 default_options: ['warning_level=0', 'werror=false'] 265 ) 266 openssl = openssl_proj.get_variable('openssl_dep') 267 openssl = openssl.as_system('system') 268else 269 # When we build openssl as a subproject, the warnings analyzer starts 270 # flagging all the C macros as old style casts, so only enable the 271 # warning for non subprojects. 272 add_project_arguments('-Wold-style-cast', language: 'cpp') 273endif 274bmcweb_dependencies += [openssl] 275 276nghttp2 = dependency('libnghttp2', version: '>=1.52.0', required : false) 277if not nghttp2.found() 278 cmake = import('cmake') 279 opt_var = cmake.subproject_options() 280 opt_var.add_cmake_defines({ 281 'ENABLE_LIB_ONLY': true, 282 'ENABLE_STATIC_LIB': true 283 }) 284 nghttp2_ex = cmake.subproject('nghttp2', options: opt_var) 285 nghttp2 = nghttp2_ex.dependency('nghttp2_static') 286endif 287bmcweb_dependencies += nghttp2 288 289sdbusplus = dependency('sdbusplus', required : false, include_type: 'system') 290if not sdbusplus.found() 291 sdbusplus_proj = subproject('sdbusplus', required: true) 292 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep') 293 sdbusplus = sdbusplus.as_system('system') 294endif 295bmcweb_dependencies += sdbusplus 296 297tinyxml = dependency( 298 'tinyxml2', 299 include_type: 'system', 300 version: '>=9.0.0', 301 default_options: ['tests=false'], 302) 303if not tinyxml.found() 304 tinyxml_proj = subproject('tinyxml2', required: true) 305 tinyxml = tinyxml_proj.get_variable('tinyxml_dep') 306 tinyxml = tinyxml.as_system('system') 307endif 308bmcweb_dependencies += tinyxml 309 310systemd = dependency('systemd') 311zlib = dependency('zlib') 312bmcweb_dependencies += [systemd, zlib] 313 314nlohmann_json_dep = dependency('nlohmann_json', version: '>=3.11.2', include_type: 'system') 315bmcweb_dependencies += nlohmann_json_dep 316 317boost = dependency( 318 'boost', 319 modules: [ 320 'url', 321 ], 322 version : '>=1.84.0', 323 required : false, 324 include_type: 'system' 325) 326if boost.found() 327 bmcweb_dependencies += [boost] 328else 329 cmake = import('cmake') 330 opt = cmake.subproject_options() 331 opt.add_cmake_defines({ 332 'BOOST_INCLUDE_LIBRARIES': 'asio;beast;callable_traits;headers;process;type_index;url;uuid', 333 'BUILD_SHARED_LIBS': 'OFF', 334 }) 335 336 boost = cmake.subproject('boost', required: true, options: opt) 337 boost_asio = boost.dependency('boost_asio').as_system() 338 boost_beast = boost.dependency('boost_beast').as_system() 339 boost_callable_traits = boost.dependency('boost_callable_traits').as_system() 340 boost_headers = boost.dependency('boost_headers').as_system() 341 boost_process = boost.dependency('boost_process').as_system() 342 boost_type_index = boost.dependency('boost_type_index').as_system() 343 boost_url = boost.dependency('boost_url').as_system() 344 boost_uuid = boost.dependency('boost_uuid').as_system() 345 bmcweb_dependencies += [ 346 boost_asio, 347 boost_beast, 348 boost_callable_traits, 349 boost_headers, 350 boost_process, 351 boost_type_index, 352 boost_url, 353 boost_uuid 354 ] 355endif 356 357if get_option('tests').allowed() 358 gtest = dependency('gtest', main: true, version: '>=1.14.0', disabler: true, required : false) 359 gmock = dependency('gmock', required : false) 360 if not gtest.found() and get_option('tests').allowed() 361 gtest_proj = subproject('gtest', required: true) 362 gtest = gtest_proj.get_variable('gtest_main_dep') 363 gmock = gtest_proj.get_variable('gmock_dep') 364 endif 365 gtest = gtest.as_system('system') 366 gmock = gmock.as_system('system') 367endif 368 369systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir') 370 371bindir = get_option('prefix') + '/' +get_option('bindir') 372 373summary({ 374 'prefix' : get_option('prefix'), 375 'bindir' : bindir, 376 'systemd unit directory' : systemd_system_unit_dir 377 }, section : 'Directories') 378 379install_subdir('static', install_dir : 'share/www', strip_directory : true) 380 381# Config subdirectory 382 383subdir('config') 384bmcweb_dependencies += conf_h_dep 385 386# Source files 387fs = import('fs') 388 389srcfiles_bmcweb = files( 390 'redfish-core/src/error_messages.cpp', 391 'redfish-core/src/registries.cpp', 392 'redfish-core/src/utils/dbus_utils.cpp', 393 'redfish-core/src/utils/time_utils.cpp', 394 'redfish-core/src/utils/json_utils.cpp', 395 'src/boost_asio_ssl.cpp', 396 'src/boost_asio.cpp', 397 'src/boost_beast.cpp', 398 'src/dbus_singleton.cpp', 399 'src/json_html_serializer.cpp', 400 'src/ossl_random.cpp', 401) 402 403bmcweblib = static_library( 404 'bmcweblib', 405 srcfiles_bmcweb, 406 include_directories : incdir, 407 dependencies: bmcweb_dependencies, 408) 409 410# Generate the bmcweb executable 411executable( 412 'bmcweb', 413 'src/webserver_main.cpp', 414 include_directories : incdir, 415 dependencies: bmcweb_dependencies, 416 link_with: bmcweblib, 417 link_args: '-Wl,--gc-sections', 418 install: true, 419 install_dir:bindir 420) 421 422srcfiles_unittest = files( 423 'test/http/crow_getroutes_test.cpp', 424 'test/http/http2_connection_test.cpp', 425 'test/http/http_connection_test.cpp', 426 'test/http/mutual_tls.cpp', 427 'test/http/router_test.cpp', 428 'test/http/parsing_test.cpp', 429 'test/http/http_response_test.cpp', 430 'test/http/utility_test.cpp', 431 'test/http/verb_test.cpp', 432 'test/http/server_sent_event_test.cpp', 433 'test/http/mutual_tls_meta.cpp', 434 'test/http/http_body_test.cpp', 435 'test/include/dbus_utility_test.cpp', 436 'test/include/google/google_service_root_test.cpp', 437 'test/include/json_html_serializer.cpp', 438 'test/include/http_utility_test.cpp', 439 'test/include/human_sort_test.cpp', 440 'test/include/async_resolve_test.cpp', 441 'test/include/credential_pipe_test.cpp', 442 'test/include/ibm/configfile_test.cpp', 443 'test/include/ibm/lock_test.cpp', 444 'test/include/multipart_test.cpp', 445 'test/include/openbmc_dbus_rest_test.cpp', 446 'test/include/str_utility_test.cpp', 447 'test/include/ossl_random.cpp', 448 'test/redfish-core/include/privileges_test.cpp', 449 'test/redfish-core/include/redfish_aggregator_test.cpp', 450 'test/redfish-core/include/registries_test.cpp', 451 'test/redfish-core/include/utils/hex_utils_test.cpp', 452 'test/redfish-core/include/utils/dbus_utils.cpp', 453 'test/redfish-core/include/utils/ip_utils_test.cpp', 454 'test/redfish-core/include/utils/json_utils_test.cpp', 455 'test/redfish-core/include/utils/query_param_test.cpp', 456 'test/redfish-core/include/utils/stl_utils_test.cpp', 457 'test/redfish-core/include/utils/time_utils_test.cpp', 458 'test/redfish-core/lib/chassis_test.cpp', 459 'test/redfish-core/lib/sensors_test.cpp', 460 'test/redfish-core/lib/system_test.cpp', 461 'test/redfish-core/lib/log_services_dump_test.cpp', 462 'test/redfish-core/lib/log_services_test.cpp', 463 'test/redfish-core/lib/update_service_test.cpp', 464 'test/redfish-core/lib/service_root_test.cpp', 465 'test/redfish-core/lib/thermal_subsystem_test.cpp', 466 'test/redfish-core/lib/power_subsystem_test.cpp', 467 'test/redfish-core/lib/manager_diagnostic_data_test.cpp', 468) 469 470 471if(get_option('tests').allowed()) 472 # generate the test executable 473 foreach test_src : srcfiles_unittest 474 test_bin = executable( 475 fs.stem(test_src), 476 test_src, 477 link_with: bmcweblib, 478 include_directories : incdir, 479 install_dir: bindir, 480 dependencies: bmcweb_dependencies + [ 481 gtest, 482 gmock, 483 ] 484 ) 485 test(fs.stem(test_src), test_bin) 486 endforeach 487endif 488