1project('bmcweb', 'cpp', 2 version : '1.0', 3 meson_version: '>=0.57.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 44# Disable lto when compiling with no optimization 45if(get_option('optimization') == '0') 46 add_project_arguments('-fno-lto', language: 'cpp') 47 message('Disabling lto & its supported features as optimization is disabled') 48endif 49 50# Include Directories 51 52incdir = include_directories( 53 'include', 54 'redfish-core/include', 55 'redfish-core/lib', 56 'http' 57) 58 59# Get the options and enable the respective features 60## create a MAP of "options : feature_flag" 61 62feature_map = { 63 'basic-auth' : '-DBMCWEB_ENABLE_BASIC_AUTHENTICATION', 64 'cookie-auth' : '-DBMCWEB_ENABLE_COOKIE_AUTHENTICATION', 65 'google-api' : '-DBMCWEB_ENABLE_GOOGLE_API', 66 'host-serial-socket' : '-DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET', 67 'ibm-management-console' : '-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE', 68 'insecure-disable-auth' : '-DBMCWEB_INSECURE_DISABLE_AUTHX', 69 'insecure-disable-csrf' : '-DBMCWEB_INSECURE_DISABLE_CSRF_PREVENTION', 70 'insecure-disable-ssl' : '-DBMCWEB_INSECURE_DISABLE_SSL', 71 'insecure-push-style-notification' : '-DBMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING', 72 'insecure-tftp-update' : '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE', 73 'kvm' : '-DBMCWEB_ENABLE_KVM' , 74 'mutual-tls-auth' : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION', 75 'redfish-aggregation' : '-DBMCWEB_ENABLE_REDFISH_AGGREGATION', 76 'redfish-allow-deprecated-power-thermal' : '-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL', 77 'redfish-bmc-journal' : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL', 78 'redfish-cpu-log' : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG', 79 'redfish-dbus-log' : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES', 80 'redfish-dump-log' : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG', 81 'redfish-host-logger' : '-DBMCWEB_ENABLE_REDFISH_HOST_LOGGER', 82 'redfish-new-powersubsystem-thermalsubsystem' : '-DBMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM', 83 'redfish-provisioning-feature' : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE', 84 'redfish-post-to-old-updateservice' : '-DBMCWEB_ENABLE_REDFISH_UPDATESERVICE_OLD_POST_URL', 85 'redfish' : '-DBMCWEB_ENABLE_REDFISH', 86 'rest' : '-DBMCWEB_ENABLE_DBUS_REST', 87 'session-auth' : '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION', 88 'static-hosting' : '-DBMCWEB_ENABLE_STATIC_HOSTING', 89 'vm-websocket' : '-DBMCWEB_ENABLE_VM_WEBSOCKET', 90 'xtoken-auth' : '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION', 91 #'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY', 92} 93 94# Get the options status and build a project summary to show which flags are 95# being enabled during the configuration time. 96 97foreach option_key,option_value : feature_map 98 if(get_option(option_key).enabled()) 99 if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl') 100 if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled()) 101 add_project_arguments(option_value,language:'cpp') 102 summary(option_key,option_value, section : 'Enabled Features') 103 endif 104 else 105 summary(option_key,option_value, section : 'Enabled Features') 106 add_project_arguments(option_value,language:'cpp') 107 endif 108 else 109 if(option_key == 'insecure-disable-ssl') 110 summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features') 111 add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp') 112 endif 113 endif 114endforeach 115 116if(get_option('tests').enabled()) 117 summary('unittest','NA', section : 'Enabled Features') 118endif 119 120# Add compiler arguments 121 122# -Wpedantic, -Wextra comes by default with warning level 123add_project_arguments( 124 cxx.get_supported_arguments([ 125 '-Wcast-align', 126 '-Wconversion', 127 '-Wformat=2', 128 '-Wold-style-cast', 129 '-Woverloaded-virtual', 130 '-Wsign-conversion', 131 '-Wunused', 132 '-Wno-attributes', 133 ]), 134 language: 'cpp' 135) 136 137if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0')) 138add_project_arguments( 139 cxx.get_supported_arguments([ 140 '-Weverything', 141 '-Wno-c++98-compat-pedantic', 142 '-Wno-c++98-compat', 143 '-Wno-documentation-unknown-command', 144 '-Wno-documentation', 145 '-Wno-exit-time-destructors', 146 '-Wno-global-constructors', 147 '-Wno-newline-eof', 148 '-Wno-padded', 149 '-Wno-shadow', 150 '-Wno-used-but-marked-unused', 151 '-Wno-weak-vtables', 152 ]), 153 language:'cpp') 154endif 155 156# if compiler is gnu-gcc , and version is > 8.0 then we add few more 157# compiler arguments , we know that will pass 158 159if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0')) 160 add_project_arguments( 161 cxx.get_supported_arguments([ 162 '-Wduplicated-cond', 163 '-Wduplicated-branches', 164 '-Wlogical-op', 165 '-Wunused-parameter', 166 '-Wnull-dereference', 167 '-Wdouble-promotion', 168 '-Wshadow', 169 '-Wno-psabi', 170 ]), 171 language:'cpp') 172endif 173 174if (get_option('buildtype') != 'plain') 175 if (get_option('b_lto') == true and get_option('optimization')!='0') 176 # Reduce the binary size by removing unnecessary 177 # dynamic symbol table entries 178 179 add_project_arguments( 180 cxx.get_supported_arguments([ 181 '-fno-fat-lto-objects', 182 '-fvisibility=hidden', 183 '-fvisibility-inlines-hidden' 184 ]), 185 language: 'cpp') 186 187 if cxx.has_link_argument('-Wl,--exclude-libs,ALL') 188 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp') 189 endif 190 endif 191endif 192 193if( get_option('bmcweb-logging').enabled() or \ 194 get_option('buildtype').startswith('debug')) 195 add_project_arguments([ 196 '-DBMCWEB_ENABLE_LOGGING', 197 '-DBMCWEB_ENABLE_DEBUG' 198 ], 199 language : 'cpp') 200 201 summary({'debug' :'-DBMCWEB_ENABLE_DEBUG', 202 'logging' : '-DBMCWEB_ENABLE_LOGGING', 203 204 },section : 'Enabled Features') 205endif 206 207# Set Compiler Security flags 208 209security_flags = [ 210 '-fstack-protector-strong', 211 '-fPIE', 212 '-fPIC', 213 '-D_FORTIFY_SOURCE=2', 214 '-Wformat', 215 '-Wformat-security' 216] 217 218## Add security flags for builds of type 'release','debugoptimized' and 'minsize' 219 220if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug')) 221 add_project_arguments( 222 cxx.get_supported_arguments([ 223 security_flags 224 ]), 225 language: 'cpp') 226endif 227 228# Boost dependency configuration 229 230add_project_arguments( 231cxx.get_supported_arguments([ 232 '-DBOOST_ALL_NO_LIB', 233 '-DBOOST_ALLOW_DEPRECATED_HEADERS', 234 '-DBOOST_ASIO_DISABLE_THREADS', 235 '-DBOOST_ASIO_NO_DEPRECATED', 236 '-DBOOST_ASIO_SEPARATE_COMPILATION', 237 '-DBOOST_BEAST_SEPARATE_COMPILATION', 238 '-DBOOST_BEAST_USE_STD_STRING_VIEW', 239 '-DBOOST_EXCEPTION_DISABLE', 240 '-DJSON_NOEXCEPTION', 241]), 242language : 'cpp') 243 244# Find the dependency modules, if not found use meson wrap to get them 245# automatically during the configure step 246bmcweb_dependencies = [] 247 248pam = cxx.find_library('pam', required: true) 249atomic = cxx.find_library('atomic', required: true) 250openssl = dependency('openssl', required : true) 251bmcweb_dependencies += [pam, atomic, openssl] 252 253sdbusplus = dependency('sdbusplus', required : false, include_type: 'system') 254if not sdbusplus.found() 255 sdbusplus_proj = subproject('sdbusplus', required: true) 256 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep') 257 sdbusplus = sdbusplus.as_system('system') 258endif 259bmcweb_dependencies += sdbusplus 260 261tinyxml = dependency('tinyxml2', 262 default_options: ['tests=false'], 263 include_type: 'system', 264) 265bmcweb_dependencies += tinyxml 266 267systemd = dependency('systemd') 268zlib = dependency('zlib') 269bmcweb_dependencies += [systemd, zlib] 270 271if cxx.has_header('nlohmann/json.hpp') 272 nlohmann_json = declare_dependency() 273else 274 nlohmann_json_proj = subproject('nlohmann', required: true) 275 nlohmann_json = nlohmann_json_proj.get_variable('nlohmann_json_dep') 276 nlohmann_json = nlohmann_json.as_system('system') 277endif 278bmcweb_dependencies += nlohmann_json 279 280boost = dependency('boost',version : '>=1.78.0', required : false, include_type: 'system') 281if not boost.found() 282 subproject('boost', required: false) 283 boost_inc = include_directories('subprojects/boost_1_78_0/', is_system:true) 284 boost = declare_dependency(include_directories : boost_inc) 285 boost = boost.as_system('system') 286endif 287bmcweb_dependencies += boost 288 289if cxx.has_header('boost/url/url_view.hpp') 290 boost_url = declare_dependency() 291else 292 subproject('boost-url', required: false) 293 boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true) 294 boost_url= declare_dependency(include_directories : boost_url_inc) 295 boost_url = boost_url.as_system('system') 296endif 297bmcweb_dependencies += boost_url 298 299if get_option('tests').enabled() 300 gtest = dependency('gtest', main: true,disabler: true, required : false) 301 gmock = dependency('gmock', required : false) 302 if not gtest.found() and get_option('tests').enabled() 303 gtest_proj = subproject('gtest', required: true) 304 gtest = gtest_proj.get_variable('gtest_main_dep') 305 gmock = gtest_proj.get_variable('gmock_dep') 306 endif 307 gtest = gtest.as_system('system') 308 gmock = gmock.as_system('system') 309endif 310 311# Gather the Configuration data 312 313conf_data = configuration_data() 314conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB', get_option('http-body-limit')) 315xss_enabled = get_option('insecure-disable-xss') 316conf_data.set10('BMCWEB_INSECURE_DISABLE_XSS_PREVENTION', xss_enabled.enabled()) 317enable_redfish_query = get_option('insecure-enable-redfish-query') 318conf_data.set10('BMCWEB_INSECURE_ENABLE_QUERY_PARAMS', enable_redfish_query.enabled()) 319# enable_redfish_aggregation = get_option('redfish-aggregation') 320# conf_data.set10('BMCWEB_ENABLE_REDFISH_AGGREGATION', enable_redfish_aggregation.enabled()) 321insecure_push_style_notification = get_option('insecure-push-style-notification') 322conf_data.set10('BMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING', insecure_push_style_notification.enabled()) 323conf_data.set('MESON_INSTALL_PREFIX', get_option('prefix')) 324conf_data.set('HTTPS_PORT', get_option('https_port')) 325configure_file(input: 'bmcweb_config.h.in', 326 output: 'bmcweb_config.h', 327 configuration: conf_data) 328 329# Configure and install systemd unit files 330 331systemd_system_unit_dir = systemd.get_variable(pkgconfig: 'systemdsystemunitdir') 332 333bindir = get_option('prefix') + '/' +get_option('bindir') 334 335summary({ 336 'prefix' : get_option('prefix'), 337 'bindir' : bindir, 338 'systemd unit directory' : systemd_system_unit_dir 339 }, section : 'Directories') 340 341configure_file(input : 'bmcweb.socket.in', 342 output : 'bmcweb.socket', 343 install_dir: systemd_system_unit_dir, 344 configuration: conf_data, 345 install : true) 346 347configure_file(input : 'bmcweb.service.in', 348 output : 'bmcweb.service', 349 install_dir: systemd_system_unit_dir, 350 configuration: conf_data, 351 install : true) 352 353# Copy pam-webserver to etc/pam.d 354configure_file(input : 'pam-webserver', 355 output : 'webserver', 356 copy : true, 357 install_dir: '/etc/pam.d', 358 install : true) 359 360install_subdir('static', install_dir : 'share/www', strip_directory : true) 361 362# Source files 363 364srcfiles_bmcweb = [ 365 'redfish-core/src/error_messages.cpp', 366 'redfish-core/src/utils/json_utils.cpp', 367 'src/boost_asio_ssl.cpp', 368 'src/boost_asio.cpp', 369 'src/boost_beast.cpp', 370 'src/boost_url.cpp', 371] 372 373# Generate the bmcweb executable 374executable( 375 'bmcweb', 376 srcfiles_bmcweb + ['src/webserver_main.cpp'], 377 include_directories : incdir, 378 dependencies: bmcweb_dependencies, 379 link_args: '-Wl,--gc-sections', 380 install: true, 381 install_dir:bindir 382) 383 384srcfiles_unittest = [ 385 'http/ut/utility_test.cpp', 386 'http/ut/router_test.cpp', 387 'include/ut/dbus_utility_test.cpp', 388 'include/ut/http_utility_test.cpp', 389 'include/ut/human_sort_test.cpp', 390 'include/ut/multipart_test.cpp', 391 'include/ut/openbmc_dbus_rest_test.cpp', 392 'redfish-core/include/utils/query_param_test.cpp', 393 'redfish-core/lib/ut/service_root_test.cpp', 394 'redfish-core/ut/configfile_test.cpp', 395 'redfish-core/ut/hex_utils_test.cpp', 396 'redfish-core/ut/ip_utils_test.cpp', 397 'redfish-core/ut/json_utils_test.cpp', 398 'redfish-core/ut/lock_test.cpp', 399 'redfish-core/ut/privileges_test.cpp', 400 'redfish-core/ut/registries_test.cpp', 401 'redfish-core/ut/stl_utils_test.cpp', 402 'redfish-core/ut/time_utils_test.cpp', 403 'src/crow_getroutes_test.cpp', 404] 405 406if(get_option('tests').enabled()) 407 # generate the test executable 408 ut_bin = executable( 409 'bmcweb_unit_test', 410 srcfiles_unittest + srcfiles_bmcweb, 411 include_directories : incdir, 412 install_dir: bindir, 413 dependencies: bmcweb_dependencies + [ 414 gtest, 415 gmock, 416 ] 417 ) 418 test('bmcweb_unit_test', ut_bin) 419endif 420