# SPDX-License-Identifier: LGPL-2.1-or-later # # This file is part of libnvme. # Copyright (c) 2021 Dell Inc. # # Authors: Martin Belanger # project( 'libnvme', ['c'], meson_version: '>= 0.48.0', version: '1.2', license: 'LGPL-2.1-or-later', default_options: [ 'c_std=gnu99', 'warning_level=1', 'buildtype=release', 'prefix=/usr', ] ) maj_min = meson.project_version().split('-rc')[0] library_version = maj_min + '.0' ################################################################################ cc = meson.get_compiler('c') cxx_available = add_languages('cpp', required: false) prefixdir = get_option('prefix') libdir = join_paths(prefixdir, get_option('libdir')) includedir = join_paths(prefixdir, get_option('includedir')) datadir = join_paths(prefixdir, get_option('datadir')) mandir = join_paths(prefixdir, get_option('mandir')) bindir = join_paths(prefixdir, get_option('bindir')) sysconfdir = join_paths(prefixdir, get_option('sysconfdir')) pkgconfiglibdir = get_option('pkgconfiglibdir') == '' ? join_paths(libdir, 'pkgconfig') : get_option('pkgconfiglibdir') ################################################################################ conf = configuration_data() version_tag = get_option('version-tag') if version_tag != '' conf.set('GIT_VERSION', '"@0@"'.format(version_tag)) else r = run_command('meson-vcs-tag.sh', meson.current_source_dir(), meson.project_version(), check: true) conf.set('GIT_VERSION', '"@0@"'.format(r.stdout().strip())) endif conf.set('PROJECT_VERSION', '"@0@"'.format(meson.project_version())) conf.set('SYSCONFDIR', '"@0@"'.format(sysconfdir)) # Check for json-c availability json_c_dep = dependency('json-c', version: '>=0.13', required: true, fallback : ['json-c', 'json_c_dep']) conf.set('CONFIG_JSONC', json_c_dep.found(), description: 'Is json-c required?') # Check for OpenSSL availability openssl_dep = dependency('openssl', version: '>=1.1.0', required: get_option('openssl'), fallback : ['openssl', 'libssl_dep']) if openssl_dep.found() conf.set('CONFIG_OPENSSL', true, description: 'Is OpenSSL/LibreSSL available?') if openssl_dep.version().version_compare('<2.0.0') api_version = 1 endif if openssl_dep.version().version_compare('>=3.0.0') api_version = 3 # Test for LibreSSL v3.x with incomplete OpenSSL v3 APIs is_libressl = cc.has_header_symbol('openssl/opensslv.h', 'LIBRESSL_VERSION_NUMBER', dependencies: openssl_dep) has_header = cc.has_header('openssl/core_names.h', dependencies: openssl_dep) if is_libressl and not has_header api_version = 1 endif endif conf.set('CONFIG_OPENSSL_@0@'.format(api_version), true, description: 'OpenSSL/LibreSSL API version @0@'.format(api_version)) endif # Check for libsystemd availability. Optional, only required for MCTP dbus scan libsystemd_dep = dependency('libsystemd', version: '>219', required: false) conf.set('CONFIG_LIBSYSTEMD', libsystemd_dep.found(), description: 'Is libsystemd(>219) available?') # local (cross-compilable) implementations of ccan configure steps conf.set10( 'HAVE_BUILTIN_TYPES_COMPATIBLE_P', cc.compiles( '''int main(void) { return __builtin_types_compatible_p(int, long); } ''', name: '__builtin_type_compatible_p' ), description: 'Is __builtin_types_compatible_p available?' ) conf.set10( 'HAVE_TYPEOF', cc.compiles( '''int main(void) { int a = 1; typeof(a) b; b = a; } ''', name: 'typeof' ), description: 'Is typeof available?' ) conf.set10( 'HAVE_BYTESWAP_H', cc.compiles( '''#include ''', name: 'byteswap.h' ), description: 'Is byteswap.h include-able?' ) conf.set10( 'HAVE_BSWAP_64', cc.links( '''#include int main(void) { return bswap_64(0); } ''', name: 'bswap64' ), description: 'Is bswap_64 available?' ) conf.set10( 'HAVE_LITTLE_ENDIAN', host_machine.endian() == 'little', description: 'Building for little-endian' ) conf.set10( 'HAVE_BIG_ENDIAN', host_machine.endian() == 'big', description: 'Building for big-endian' ) conf.set10( 'HAVE_STATEMENT_EXPR', cc.compiles( '''int main(int argc, char **argv) { return ({ int x = argc; x == 1; }); } ''', name: 'statement-expr' ), description: 'Can we use a statement as an expression?' ) conf.set10( 'HAVE_ISBLANK', cc.links( '''#include int main(int argc, char **argv) { return isblank(argv[0][0]); } ''', name: 'isblank' ), description: 'Is isblank() available?' ) conf.set10( 'HAVE_LINUX_MCTP_H', cc.compiles( '''#include ''', name: 'linux/mctp.h' ), description: 'Is linux/mctp.h include-able?' ) if meson.version().version_compare('>= 0.48') has_fallthrough = cc.has_function_attribute('fallthrough') else has_fallthrough = cc.compiles( '''int main(int argc, char **argv) { switch(argc) { case 0: __attribute__((__fallthrough__)); case 1: return 1; } return 0; } ''', name: 'has fallthrough') endif if has_fallthrough conf.set('fallthrough', '__attribute__((__fallthrough__))') else conf.set('fallthrough', 'do {} while (0) /* fallthrough */') endif ################################################################################ substs = configuration_data() substs.set('NAME', meson.project_name()) substs.set('VERSION', meson.project_version()) substs.set('LICENSE', meson.project_license()[0]) configure_file( input: 'libnvme.spec.in', output: 'libnvme.spec', configuration: substs, ) ################################################################################ add_project_arguments( [ '-fomit-frame-pointer', '-D_GNU_SOURCE', '-include', 'internal/config.h', ], language : 'c', ) incdir = include_directories(['.', 'ccan', 'src']) ################################################################################ subdir('internal') subdir('ccan') subdir('src') subdir('libnvme') subdir('test') subdir('examples') subdir('doc')