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