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