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