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