1project('bmcweb', 'cpp', 2 version : '1.0', 3 meson_version: '>=0.63.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 'insecure-ignore-content-type' : '-DBMCWEB_INSECURE_IGNORE_CONTENT_TYPE', 74 'kvm' : '-DBMCWEB_ENABLE_KVM' , 75 'mutual-tls-auth' : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION', 76 'redfish-aggregation' : '-DBMCWEB_ENABLE_REDFISH_AGGREGATION', 77 'redfish-allow-deprecated-power-thermal' : '-DBMCWEB_ALLOW_DEPRECATED_POWER_THERMAL', 78 'redfish-bmc-journal' : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL', 79 'redfish-cpu-log' : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG', 80 'redfish-dbus-log' : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES', 81 'redfish-dump-log' : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG', 82 'redfish-host-logger' : '-DBMCWEB_ENABLE_REDFISH_HOST_LOGGER', 83 'redfish-new-powersubsystem-thermalsubsystem' : '-DBMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM', 84 'redfish-oem-manager-fan-data' : '-DBMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA', 85 'redfish-provisioning-feature' : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE', 86 'redfish' : '-DBMCWEB_ENABLE_REDFISH', 87 'rest' : '-DBMCWEB_ENABLE_DBUS_REST', 88 'session-auth' : '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION', 89 'static-hosting' : '-DBMCWEB_ENABLE_STATIC_HOSTING', 90 'vm-websocket' : '-DBMCWEB_ENABLE_VM_WEBSOCKET', 91 'xtoken-auth' : '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION', 92 #'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY', 93} 94 95# Get the options status and build a project summary to show which flags are 96# being enabled during the configuration time. 97 98foreach option_key,option_value : feature_map 99 if(get_option(option_key).enabled()) 100 if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl') 101 if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled()) 102 add_project_arguments(option_value,language:'cpp') 103 summary(option_key,option_value, section : 'Enabled Features') 104 endif 105 elif (option_key in ['basic-auth', 'cookie-auth', 'session-auth', 'xtoken-auth', 'mutual-tls-auth']) 106 if (get_option('insecure-disable-auth').disabled()) 107 add_project_arguments(option_value, language:'cpp') 108 summary(option_key,option_value, section : 'Enabled Features') 109 endif 110 else 111 summary(option_key,option_value, section : 'Enabled Features') 112 add_project_arguments(option_value,language:'cpp') 113 endif 114 else 115 if(option_key == 'insecure-disable-ssl') 116 summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features') 117 add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp') 118 endif 119 endif 120endforeach 121 122if(get_option('tests').enabled()) 123 summary('unittest','NA', section : 'Enabled Features') 124endif 125 126# Add compiler arguments 127 128# -Wpedantic, -Wextra comes by default with warning level 129add_project_arguments( 130 cxx.get_supported_arguments([ 131 '-Wcast-align', 132 '-Wconversion', 133 '-Wformat=2', 134 '-Wold-style-cast', 135 '-Woverloaded-virtual', 136 '-Wsign-conversion', 137 '-Wunused', 138 '-Wno-attributes', 139 ]), 140 language: 'cpp' 141) 142 143if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0')) 144add_project_arguments( 145 cxx.get_supported_arguments([ 146 '-Weverything', 147 '-Wno-c++98-compat-pedantic', 148 '-Wno-c++98-compat', 149 '-Wno-documentation-unknown-command', 150 '-Wno-documentation', 151 '-Wno-exit-time-destructors', 152 '-Wno-global-constructors', 153 '-Wno-newline-eof', 154 '-Wno-padded', 155 '-Wno-shadow', 156 '-Wno-used-but-marked-unused', 157 '-Wno-weak-vtables', 158 '-Wno-switch-enum', 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 add_project_arguments( 168 cxx.get_supported_arguments([ 169 '-Wduplicated-cond', 170 '-Wduplicated-branches', 171 '-Wlogical-op', 172 '-Wnull-dereference', 173 '-Wunused-parameter', 174 '-Wdouble-promotion', 175 '-Wshadow', 176 '-Wno-psabi', 177 ]), 178 language:'cpp') 179endif 180 181if (get_option('buildtype') != 'plain') 182 if (get_option('b_lto') == true and get_option('optimization')!='0') 183 # Reduce the binary size by removing unnecessary 184 # dynamic symbol table entries 185 186 add_project_arguments( 187 cxx.get_supported_arguments([ 188 '-fno-fat-lto-objects', 189 '-fvisibility=hidden', 190 '-fvisibility-inlines-hidden' 191 ]), 192 language: 'cpp') 193 194 if cxx.has_link_argument('-Wl,--exclude-libs,ALL') 195 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp') 196 endif 197 endif 198endif 199 200if( get_option('bmcweb-logging') != 'disabled' or \ 201 get_option('buildtype').startswith('debug')) 202 add_project_arguments([ 203 '-DBMCWEB_ENABLE_DEBUG' 204 ], 205 language : 'cpp') 206 207 summary('debug', '-DBMCWEB_ENABLE_DEBUG', section : 'Enabled Features') 208endif 209 210# Set Compiler Security flags 211 212security_flags = [ 213 '-fstack-protector-strong', 214 '-fPIE', 215 '-fPIC', 216 '-D_FORTIFY_SOURCE=2', 217 '-Wformat', 218 '-Wformat-security' 219] 220 221## Add security flags for builds of type 'release','debugoptimized' and 'minsize' 222 223if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug')) 224 add_project_arguments( 225 cxx.get_supported_arguments([ 226 security_flags 227 ]), 228 language: 'cpp') 229endif 230 231# Boost dependency configuration 232 233add_project_arguments( 234cxx.get_supported_arguments([ 235 '-DBOOST_ALL_NO_LIB', 236 '-DBOOST_ALLOW_DEPRECATED_HEADERS', 237 '-DBOOST_ASIO_DISABLE_THREADS', 238 '-DBOOST_ASIO_NO_DEPRECATED', 239 '-DBOOST_ASIO_SEPARATE_COMPILATION', 240 '-DBOOST_BEAST_SEPARATE_COMPILATION', 241 '-DBOOST_EXCEPTION_DISABLE', 242 '-DBOOST_URL_NO_SOURCE_LOCATION', 243 '-DJSON_NOEXCEPTION', 244 '-DOPENSSL_NO_FILENAMES', 245]), 246language : 'cpp') 247 248# Find the dependency modules, if not found use meson wrap to get them 249# automatically during the configure step 250bmcweb_dependencies = [] 251 252pam = cxx.find_library('pam', required: true) 253atomic = cxx.find_library('atomic', required: true) 254openssl = dependency('openssl', required : true) 255bmcweb_dependencies += [pam, atomic, openssl] 256 257sdbusplus = dependency('sdbusplus', required : false, include_type: 'system') 258if not sdbusplus.found() 259 sdbusplus_proj = subproject('sdbusplus', required: true) 260 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep') 261 sdbusplus = sdbusplus.as_system('system') 262endif 263bmcweb_dependencies += sdbusplus 264 265tinyxml = dependency('tinyxml2', 266 default_options: ['tests=false'], 267 include_type: 'system', 268) 269bmcweb_dependencies += tinyxml 270 271systemd = dependency('systemd') 272zlib = dependency('zlib') 273bmcweb_dependencies += [systemd, zlib] 274 275if cxx.has_header('nlohmann/json.hpp') 276 nlohmann_json = declare_dependency() 277else 278 nlohmann_json_proj = subproject('nlohmann', required: true) 279 nlohmann_json = nlohmann_json_proj.get_variable('nlohmann_json_dep') 280 nlohmann_json = nlohmann_json.as_system('system') 281endif 282bmcweb_dependencies += nlohmann_json 283 284boost = dependency('boost',version : '>=1.81.0', required : false, include_type: 'system') 285if not boost.found() 286 boost = subproject('boost', required: true).get_variable('boost_dep') 287 boost = boost.as_system('system') 288endif 289bmcweb_dependencies += boost 290 291if get_option('tests').enabled() 292 gtest = dependency('gtest', main: true,disabler: true, required : false) 293 gmock = dependency('gmock', required : false) 294 if not gtest.found() and get_option('tests').enabled() 295 gtest_proj = subproject('gtest', required: true) 296 gtest = gtest_proj.get_variable('gtest_main_dep') 297 gmock = gtest_proj.get_variable('gmock_dep') 298 endif 299 gtest = gtest.as_system('system') 300 gmock = gmock.as_system('system') 301endif 302 303systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir') 304 305bindir = get_option('prefix') + '/' +get_option('bindir') 306 307summary({ 308 'prefix' : get_option('prefix'), 309 'bindir' : bindir, 310 'systemd unit directory' : systemd_system_unit_dir 311 }, section : 'Directories') 312 313install_subdir('static', install_dir : 'share/www', strip_directory : true) 314 315# Config subdirectory 316 317subdir('config') 318bmcweb_dependencies += conf_h_dep 319 320# Source files 321fs = import('fs') 322 323srcfiles_bmcweb = files( 324 'redfish-core/src/error_messages.cpp', 325 'redfish-core/src/registries.cpp', 326 'redfish-core/src/utils/json_utils.cpp', 327 'src/boost_asio_ssl.cpp', 328 'src/boost_asio.cpp', 329 'src/boost_beast.cpp', 330 'src/boost_url.cpp', 331 'src/dbus_singleton.cpp', 332) 333 334bmcweblib = static_library( 335 'bmcweblib', 336 srcfiles_bmcweb, 337 include_directories : incdir, 338 dependencies: bmcweb_dependencies, 339) 340 341# Generate the bmcweb executable 342executable( 343 'bmcweb', 344 'src/webserver_main.cpp', 345 include_directories : incdir, 346 dependencies: bmcweb_dependencies, 347 link_with: bmcweblib, 348 link_args: '-Wl,--gc-sections', 349 install: true, 350 install_dir:bindir 351) 352 353srcfiles_unittest = files( 354 'test/http/crow_getroutes_test.cpp', 355 'test/http/router_test.cpp', 356 'test/http/utility_test.cpp', 357 'test/http/verb_test.cpp', 358 'test/include/dbus_utility_test.cpp', 359 'test/include/google/google_service_root_test.cpp', 360 'test/include/json_html_serializer.cpp', 361 'test/include/http_utility_test.cpp', 362 'test/include/human_sort_test.cpp', 363 'test/include/ibm/configfile_test.cpp', 364 'test/include/ibm/lock_test.cpp', 365 'test/include/multipart_test.cpp', 366 'test/include/openbmc_dbus_rest_test.cpp', 367 'test/include/str_utility_test.cpp', 368 'test/redfish-core/include/privileges_test.cpp', 369 'test/redfish-core/include/redfish_aggregator_test.cpp', 370 'test/redfish-core/include/registries_test.cpp', 371 'test/redfish-core/include/utils/hex_utils_test.cpp', 372 'test/redfish-core/include/utils/ip_utils_test.cpp', 373 'test/redfish-core/include/utils/json_utils_test.cpp', 374 'test/redfish-core/include/utils/query_param_test.cpp', 375 'test/redfish-core/include/utils/stl_utils_test.cpp', 376 'test/redfish-core/include/utils/time_utils_test.cpp', 377 'test/redfish-core/lib/chassis_test.cpp', 378 'test/redfish-core/lib/sensors_test.cpp', 379 'test/redfish-core/lib/log_services_dump_test.cpp', 380 'test/redfish-core/lib/service_root_test.cpp', 381 'test/redfish-core/lib/thermal_subsystem_test.cpp', 382 'test/redfish-core/lib/power_subsystem_test.cpp', 383) 384 385if(get_option('tests').enabled()) 386 # generate the test executable 387 foreach test_src : srcfiles_unittest 388 test_bin = executable( 389 fs.stem(test_src), 390 test_src, 391 link_with: bmcweblib, 392 include_directories : incdir, 393 install_dir: bindir, 394 dependencies: bmcweb_dependencies + [ 395 gtest, 396 gmock, 397 ] 398 ) 399 test(fs.stem(test_src), test_bin) 400 endforeach 401endif 402