From d13b62c4f652b83426cf81cb8e867851f7bb3d07 Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Mon, 3 Mar 2025 17:01:09 +0200 Subject: [PATCH] [#3731] Add Meson build options --- fuzz/meson.build | 4 +- meson.build | 199 +++++++++++++++++++++++++++++------ meson.format | 2 + meson.options | 26 +++++ src/bin/perfdhcp/meson.build | 4 + src/bin/shell/meson.build | 2 +- 6 files changed, 199 insertions(+), 38 deletions(-) create mode 100644 meson.format create mode 100644 meson.options diff --git a/fuzz/meson.build b/fuzz/meson.build index dd32bfc1af..8336636a56 100644 --- a/fuzz/meson.build +++ b/fuzz/meson.build @@ -1,4 +1,4 @@ -if not gtest.found() +if FUZZ_OPT != 'enabled' subdir_done() endif @@ -10,7 +10,7 @@ cpp_flags = [ f'-DKEA_LFC_SOURCES="@KEA_LFC@"', f'-DKEA_LFC_INSTALLATION="@PREFIX@/sbin/kea-lfc"', ] -if FUZZING_IN_CI +if FUZZ_OPT == 'clusterfuzzlite' cpp_flags = ['-fsanitize=fuzzer', '-gdwarf-4'] else fuzz_sources += ['main.cc'] diff --git a/meson.build b/meson.build index 7af094d624..9d00eae4c6 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,6 @@ # Require meson >= 0.64.0 for preserve_path arg in install_data. -project('kea', 'cpp', version: '2.7.7-git', meson_version: '>=0.64.0') +# Require meson >= 1.1.0 for meson.options file. +project('kea', 'cpp', version: '2.7.7-git', meson_version: '>=1.1.0') cpp = meson.get_compiler('cpp') PROJECT_VERSION = meson.project_version() @@ -25,9 +26,6 @@ TEST_CA_DIR = f'@TOP_SOURCE_DIR@/src/lib/asiolink/testutils/ca' DATABASE_SCRIPTS_DIR = f'@TOP_BUILD_DIR@/src/share/database/scripts' LEGAL_LOG_DIR = f'@PREFIX@/@RUN_STATE_DIR@/lib/kea' -# TODO: Control it via a build option. -FUZZING_IN_CI = false - #### Configuration Data conf_data = configuration_data( @@ -36,7 +34,6 @@ conf_data = configuration_data( # 'ENABLE_DEBUG': false, # 'ENABLE_LOGGER_CHECKS': false, 'EXTENDED_VERSION': '"tarball"', - 'FUZZING': true, # 'HAS_UNDEFINED_PTHREAD_BEHAVIOR': false, # 'HAVE_AFL': false, # 'HAVE_BOOST_ASIO_COROUTINE_HPP': false, @@ -143,7 +140,7 @@ elif SYSTEM == 'darwin' conf_data.set('OS_OSX', true) OS_TYPE = 'BSD' else - error(f'Build failed: Unsupported system "@SYSTEM@".') + error(f'Unsupported system "@SYSTEM@".') endif message(f'Detected system "@SYSTEM@".') @@ -188,20 +185,6 @@ foreach dep : ['botan-2', 'botan'] endif endforeach openssl = dependency('openssl', required: false) -if openssl.found() - crypto = openssl - conf_data.set('WITH_OPENSSL', true) - message('Using OpenSSL.') -elif botan.found() - crypto = botan - conf_data.set('WITH_BOTAN', true) - message('Using Botan.') - message('Checking Botan Boost support.') - cpp.has_header('botan/asio_stream.h', dependencies: [botan], required: true) -endif -if not crypto.found() - error('Build failed: Could not find neither botan nor openssl libraries.') -endif # Kerberos krb5 = disabler() @@ -253,9 +236,6 @@ foreach mysql_config_file : ['mariadb_config', 'mysql_config'] break endif endforeach -if mysql.found() - conf_data.set('HAVE_MYSQL', true) -endif # PostgreSQL postgresql = dependency('libpq', required: false) @@ -278,9 +258,6 @@ if pg_config.found() ) endif endif -if postgresql.found() - conf_data.set('HAVE_PGSQL', true) -endif # NETCONF netconf_deps = {} @@ -334,6 +311,153 @@ foreach dep : ['yang', 'yang-cpp', 'sysrepo', 'sysrepo-cpp'] endif endforeach +#### Build Options + +all_opt = get_option('all') +crypto_opt = get_option('crypto') +gtest_opt = get_option('gtest') +krb5_opt = get_option('krb5') +mysql_opt = get_option('mysql') +netconf_opt = get_option('netconf') +postgresql_opt = get_option('postgresql') + +# docs_opt = get_option('docs') +# parser_opt = get_option('parser') + +FUZZ_OPT = get_option('fuzz') +PERFDHCP_OPT = get_option('perfdhcp') +SHELL_OPT = get_option('shell') +if SHELL_OPT == 'enabled' and not PYTHON.found() + error('kea-shell requires python. Python not found.') +endif + +if crypto_opt == 'auto' + if openssl.found() + crypto = openssl + elif botan.found() + crypto = botan + endif +elif crypto_opt == 'botan' + if botan.found() + crypto = botan + endif +elif crypto_opt == 'openssl' + if openssl.found() + crypto = openssl + endif +endif + +if crypto.name() == botan.name() + message('Checking Botan Boost support.') + cpp.has_header('botan/asio_stream.h', dependencies: [botan], required: true) + conf_data.set('WITH_BOTAN', true) + message('Using Botan.') +elif crypto.name() == openssl.name() + conf_data.set('WITH_OPENSSL', true) + message('Using OpenSSL.') +else + error('Dependency not found: neither Botan nor OpenSSL.') +endif + +if all_opt.enabled() + if gtest_opt == 'disabled' + gtest = disabler() + elif not gtest.found() + error('Dependency not found: GTest.') + endif + if krb5_opt == 'disabled' + krb5 = disabler() + elif not krb5.found() + error('Dependency not found: Kerberos 5 with GSSAPI.') + endif + if mysql_opt == 'disabled' + mysql = disabler() + elif not mysql.found() + error('Dependency not found: MySQL.') + endif + if netconf_opt == 'disabled' + NETCONF_DEPS_FOUND = false + elif not NETCONF_DEPS_FOUND + error('Dependency not found: NETCONF.') + endif + if postgresql_opt == 'disabled' + postgresql = disabler() + elif not postgresql.found() + error('Dependency not found: PostgreSQL.') + endif + if FUZZ_OPT != 'disabled' + FUZZ_OPT = 'enabled' + endif + if PERFDHCP_OPT != 'disabled' + PERFDHCP_OPT = 'enabled' + endif + if SHELL_OPT != 'disabled' + SHELL_OPT = 'enabled' + endif +elif all_opt.disabled() + if gtest_opt != 'enabled' + gtest = disabler() + endif + if krb5_opt != 'enabled' + krb5 = disabler() + endif + if mysql_opt != 'enabled' + mysql = disabler() + endif + if netconf_opt != 'enabled' + NETCONF_DEPS_FOUND = false + endif + if postgresql_opt != 'enabled' + postgresql = disabler() + endif + if FUZZ_OPT != 'enabled' + FUZZ_OPT = 'disabled' + endif + if PERFDHCP_OPT != 'enabled' + PERFDHCP_OPT = 'disabled' + endif + if SHELL_OPT != 'enabled' + SHELL_OPT = 'disabled' + endif +elif all_opt.auto() + if gtest_opt == 'enabled' and not gtest.found() + error('Dependency not found: GTest.') + endif + + if krb5_opt == 'enabled' and not krb5.found() + error('Dependency not found: Kerberos 5 with GSSAPI.') + endif + + if mysql_opt == 'enabled' and not mysql.found() + error('Dependency not found: MySQL.') + endif + + if netconf_opt == 'enabled' and not NETCONF_DEPS_FOUND + error('Dependency not found: NETCONF.') + endif + + if postgresql_opt == 'enabled' and not postgresql.found() + error('Dependency not found: PostgreSQL.') + endif +else + error('Unknown value for -Dall') +endif + +if FUZZ_OPT == 'enabled' + if not gtest.found() + error('Fuzzing requires gtest. Gtest not found.') + endif + conf_data.set('FUZZING', true) +endif + +if mysql.found() + conf_data.set('HAVE_MYSQL', true) +endif + +if postgresql.found() + conf_data.set('HAVE_PGSQL', true) +endif + #### Compiler Checks result = cpp.run( @@ -379,7 +503,6 @@ result = cpp.run( ) conf_data.set('LOG4CPLUS_INITIALIZER_H', result.returncode() == 0) - if mysql.found() result = cpp.run( fs.read('compiler-checks/mysql-my-bool.cc'), @@ -437,6 +560,7 @@ INCLUDES = [ #### Build report report_conf_data = configuration_data() +report_conf_data.merge_from(conf_data) report_conf_data.set('TOP_BUILD_DIR', TOP_BUILD_DIR) report_conf_data.set('PACKAGE_NAME', 'kea') report_conf_data.set('PACKAGE_VERSION', PROJECT_VERSION) @@ -450,11 +574,7 @@ if have_premium else report_conf_data.set('PREMIUM', 'no') endif -if meson.version().version_compare('>=1.1.0') - report_conf_data.set('BUILD_OPTIONS', meson.build_options()) -else - report_conf_data.set('BUILD_OPTIONS', 'unknown') -endif +report_conf_data.set('BUILD_OPTIONS', meson.build_options()) report_conf_data.set('MESON_VERSION', meson.version()) report_conf_data.set('CXX', ' '.join(cpp.cmd_array())) report_conf_data.set('CXX_ID', cpp.get_id()) @@ -574,7 +694,6 @@ else report_conf_data.set('BISON', 'unknown') endif if mysql.found() - report_conf_data.set('HAVE_MYSQL', 'yes') if not mysql_config.found() report_conf_data.set('MYSQL_VERSION', mysql.version()) report_conf_data.set( @@ -746,8 +865,18 @@ endif #### More Custom Targets -alias_target('messages', TARGETS_GEN_MESSAGES) -alias_target('parser', TARGETS_GEN_PARSER) +if TARGETS_GEN_MESSAGES.length() > 0 + alias_target('messages', TARGETS_GEN_MESSAGES) +else + error( + 'No messages to generate. This is probably an error in the ' + 'meson.build files.', + ) +endif +if TARGETS_GEN_PARSER.length() > 0 + alias_target('parser', TARGETS_GEN_PARSER) +else + run_target('parser', command: 'echo Parser generation is disabled.'.split()) +endif #### Installation diff --git a/meson.format b/meson.format new file mode 100644 index 0000000000..79dccec817 --- /dev/null +++ b/meson.format @@ -0,0 +1,2 @@ +simplify_string_literals: false +sort_files: true diff --git a/meson.options b/meson.options new file mode 100644 index 0000000000..3e76be4942 --- /dev/null +++ b/meson.options @@ -0,0 +1,26 @@ +# all +option( + 'all', + type: 'feature', + value: 'disabled', + description: 'Requires that all C++ dependencies be enabled: crypto (either botan or openssl), krb5 with gssapi, mysql, netconf, postgresql. Also enables generation of docs and parser which requires bison, flex, and sphinx. Also enables all parts of code: debug, fuzzing, logger-checks, perfdhcp, shell. Overrides the other options.', +) + +# Dependency-related options +option('crypto', type: 'combo', choices: ['auto', 'botan', 'openssl'], value: 'auto', description: 'Backend for cryptographical operations. Mandatory.') +option('krb5', type: 'combo', choices: ['', 'auto', 'enabled', 'disabled'], value: '', description: 'Support for GSS-TSIG. Requires krb5 with gssapi.') +option('gtest', type: 'combo', choices: ['', 'auto', 'enabled', 'disabled'], value: '', description: 'Support for unit tests with GTest.') +option('mysql', type: 'combo', choices: ['', 'auto', 'enabled', 'disabled'], value: '', description: 'Support for MySQL backends.') +option('netconf', type: 'combo', choices: ['', 'auto', 'enabled', 'disabled'], value: '', description: 'Support for kea-netconf.') +option('postgresql', type: 'combo', choices: ['', 'auto', 'enabled', 'disabled'], value: '', description: 'Support for PostgreSQL backends.') + +# Used for development. +# option('docs', type: 'feature', choices: ['', 'auto', 'enabled', 'disabled'], value: '', description: 'Support for doc generation.') +# option('parser', type: 'feature', choices: ['', 'auto', 'enabled', 'disabled'], value: '', description: 'Support for parser generation.') + +# Options for enabling various parts of code. +# debug? +# logger-checks? +option('fuzz', type: 'combo', choices: ['', 'auto', 'clusterfuzzlite', 'disabled', 'enabled'], value: '', description: 'Support for fuzz testing.') +option('perfdhcp', type: 'combo', choices: ['', 'auto', 'disabled', 'enabled'], value: '', description: 'Builds perfdhcp.') +option('shell', type: 'combo', choices: ['', 'auto', 'disabled', 'enabled'], value: '', description: 'Builds kea-shell.') diff --git a/src/bin/perfdhcp/meson.build b/src/bin/perfdhcp/meson.build index 36c8353d9e..0df78a5901 100644 --- a/src/bin/perfdhcp/meson.build +++ b/src/bin/perfdhcp/meson.build @@ -1,3 +1,7 @@ +if PERFDHCP_OPT != 'enabled' + subdir_done() +endif + perfdhcp_lib = static_library( 'perfdhcp', 'avalanche_scen.cc', diff --git a/src/bin/shell/meson.build b/src/bin/shell/meson.build index 0cd9c865aa..294819cbd1 100644 --- a/src/bin/shell/meson.build +++ b/src/bin/shell/meson.build @@ -1,4 +1,4 @@ -if not PYTHON.found() +if SHELL_OPT != 'enabled' subdir_done() endif