dpdk/drivers/meson.build
<<
>>
Prefs
   1# SPDX-License-Identifier: BSD-3-Clause
   2# Copyright(c) 2017-2019 Intel Corporation
   3
   4# Defines the order of dependencies evaluation
   5subdirs = [
   6        'common',
   7        'bus',
   8        'common/cnxk',    # depends on bus.
   9        'common/mlx5',    # depends on bus.
  10        'common/qat',     # depends on bus.
  11        'common/sfc_efx', # depends on bus.
  12        'mempool',        # depends on common and bus.
  13        'dma',            # depends on common and bus.
  14        'net',            # depends on common, bus, mempool
  15        'raw',            # depends on common, bus, dma and net.
  16        'crypto',         # depends on common, bus and mempool (net in future).
  17        'compress',       # depends on common, bus, mempool.
  18        'regex',          # depends on common, bus, regexdev.
  19        'vdpa',           # depends on common, bus and mempool.
  20        'event',          # depends on common, bus, mempool and net.
  21        'baseband',       # depends on common and bus.
  22        'gpu',            # depends on common and bus.
  23]
  24
  25if meson.is_cross_build()
  26    disable_drivers += ',' + meson.get_cross_property('disable_drivers', '')
  27    enable_drivers += ',' + meson.get_cross_property('enable_drivers', '')
  28endif
  29
  30# add cmdline disabled drivers and meson disabled drivers together
  31disable_drivers += ',' + get_option('disable_drivers')
  32disable_drivers = run_command(list_dir_globs, disable_drivers, check: true).stdout().split()
  33
  34# add cmdline enabled drivers and meson enabled drivers together
  35enable_drivers = ',' + get_option('enable_drivers')
  36enable_drivers = run_command(list_dir_globs, enable_drivers, check: true).stdout().split()
  37if enable_drivers.length() == 0
  38    enable_drivers = run_command(list_dir_globs, '*/*', check: true).stdout().split()
  39endif
  40
  41# these drivers must always be enabled, otherwise the build breaks
  42always_enable = ['bus/pci', 'bus/vdev']
  43# we always need a mempool driver, and ring is default, so make it mandatory
  44always_enable += ['mempool/ring']
  45enable_drivers += always_enable
  46
  47default_cflags = machine_args
  48default_cflags += ['-DALLOW_EXPERIMENTAL_API']
  49default_cflags += ['-DALLOW_INTERNAL_API']
  50
  51if cc.has_argument('-Wno-format-truncation')
  52    default_cflags += '-Wno-format-truncation'
  53endif
  54
  55foreach subpath:subdirs
  56    drivers = []
  57    std_deps = []
  58    log_prefix = ''
  59
  60    # subpath can be either "class" or "class/driver"
  61    if subpath.contains('/')
  62        driver_path = subpath.split('/')
  63        class = driver_path[0]
  64        drivers += driver_path[1]
  65    else
  66        class = subpath
  67        subdir(class)
  68    endif
  69
  70    # save class name on first occurrence
  71    if not dpdk_driver_classes.contains(class)
  72        dpdk_driver_classes += class
  73    endif
  74    # get already enabled drivers of the same class
  75    enabled_drivers = get_variable(class + '_drivers', [])
  76
  77    # default log prefix can be defined per class
  78    if log_prefix == ''
  79        # default log name is pmd.class.driver
  80        log_prefix = 'pmd.' + class
  81    endif
  82
  83    foreach drv:drivers
  84        drv_path = join_paths(class, drv)
  85
  86        # set up empty variables used for build
  87        build = true # set to false to disable, e.g. missing deps
  88        reason = '<unknown reason>' # set if build == false to explain
  89        name = drv
  90        sources = []
  91        headers = []
  92        objs = []
  93        cflags = default_cflags
  94        includes = [include_directories(drv_path)]
  95        # set up internal deps. Drivers can append/override as necessary
  96        deps = std_deps
  97        # ext_deps: Stores external library dependency got
  98        # using dependency() (preferred) or find_library().
  99        # For the find_library() case (but not with dependency()) we also
 100        # need to specify the "-l" flags in pkgconfig_extra_libs variable
 101        # too, so that it can be reflected in the pkgconfig output for
 102        # static builds.
 103        ext_deps = []
 104        pkgconfig_extra_libs = []
 105
 106        if not enable_drivers.contains(drv_path)
 107            build = false
 108            reason = 'not in enabled drivers build config'
 109        elif disable_drivers.contains(drv_path)
 110            if always_enable.contains(drv_path)
 111                message('Driver @0@ cannot be disabled, not disabling.'.format(drv_path))
 112            else
 113                build = false
 114                reason = 'explicitly disabled via build config'
 115            endif
 116        endif
 117
 118        if build
 119            # pull in driver directory which should update all the local variables
 120            subdir(drv_path)
 121
 122            # get dependency objs from strings
 123            shared_deps = ext_deps
 124            static_deps = ext_deps
 125            foreach d:deps
 126                if not build
 127                    break
 128                endif
 129                if not is_variable('shared_rte_' + d)
 130                    build = false
 131                    reason = 'missing internal dependency, "@0@"'.format(d)
 132                    message('Disabling @1@ [@2@]: missing internal dependency "@0@"'
 133                            .format(d, name, 'drivers/' + drv_path))
 134                else
 135                    shared_deps += [get_variable('shared_rte_' + d)]
 136                    static_deps += [get_variable('static_rte_' + d)]
 137                endif
 138            endforeach
 139        endif
 140
 141        if not build
 142            # some driver directories are placeholders which
 143            # are never built, so we allow suppression of the
 144            # component disable printout in those cases
 145            if reason != ''
 146                dpdk_drvs_disabled += drv_path
 147                set_variable(drv_path.underscorify() + '_disable_reason', reason)
 148            endif
 149            continue
 150        endif
 151
 152        enabled_drivers += name
 153        lib_name = '_'.join(['rte', class, name])
 154        cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=' + '.'.join([log_prefix, name])
 155        dpdk_conf.set(lib_name.to_upper(), 1)
 156
 157        dpdk_extra_ldflags += pkgconfig_extra_libs
 158
 159        install_headers(headers)
 160
 161        # generate pmdinfo sources by building a temporary
 162        # lib and then running pmdinfogen on the contents of
 163        # that lib. The final lib reuses the object files and
 164        # adds in the new source file.
 165        out_filename = lib_name + '.pmd.c'
 166        tmp_lib = static_library('tmp_' + lib_name, sources,
 167                include_directories: includes,
 168                dependencies: static_deps,
 169                c_args: cflags)
 170        objs += tmp_lib.extract_all_objects(recursive: true)
 171        sources = custom_target(out_filename,
 172                command: [pmdinfo, tmp_lib.full_path(), '@OUTPUT@', pmdinfogen],
 173                output: out_filename,
 174                depends: [tmp_lib])
 175
 176        # now build the static driver
 177        static_lib = static_library(lib_name,
 178                sources,
 179                objects: objs,
 180                include_directories: includes,
 181                dependencies: static_deps,
 182                c_args: cflags,
 183                install: true)
 184
 185        # now build the shared driver
 186        version_map = '@0@/@1@/version.map'.format(meson.current_source_dir(), drv_path)
 187        implib = 'lib' + lib_name + '.dll.a'
 188
 189        def_file = custom_target(lib_name + '_def',
 190                command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
 191                input: version_map,
 192                output: '@0@_exports.def'.format(lib_name))
 193
 194        mingw_map = custom_target(lib_name + '_mingw',
 195                command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
 196                input: version_map,
 197                output: '@0@_mingw.map'.format(lib_name))
 198
 199        lk_deps = [version_map, def_file, mingw_map]
 200        if is_windows
 201            if is_ms_linker
 202                lk_args = ['-Wl,/def:' + def_file.full_path()]
 203                if meson.version().version_compare('<0.54.0')
 204                    lk_args += ['-Wl,/implib:drivers\\' + implib]
 205                endif
 206            else
 207                lk_args = ['-Wl,--version-script=' + mingw_map.full_path()]
 208            endif
 209        else
 210            lk_args = ['-Wl,--version-script=' + version_map]
 211            if developer_mode
 212                # on unix systems check the output of the
 213                # check-symbols.sh script, using it as a
 214                # dependency of the .so build
 215                lk_deps += custom_target(lib_name + '.sym_chk',
 216                        command: [check_symbols, version_map, '@INPUT@'],
 217                        capture: true,
 218                        input: static_lib,
 219                        output: lib_name + '.sym_chk')
 220            endif
 221        endif
 222
 223        shared_lib = shared_library(lib_name, sources,
 224                objects: objs,
 225                include_directories: includes,
 226                dependencies: shared_deps,
 227                c_args: cflags,
 228                link_args: lk_args,
 229                link_depends: lk_deps,
 230                version: abi_version,
 231                soversion: so_version,
 232                install: true,
 233                install_dir: driver_install_path)
 234
 235        # create a dependency object and add it to the global dictionary so
 236        # testpmd or other built-in apps can find it if necessary
 237        shared_dep = declare_dependency(link_with: shared_lib,
 238                include_directories: includes,
 239                dependencies: shared_deps)
 240        static_dep = declare_dependency(
 241                include_directories: includes,
 242                dependencies: static_deps)
 243
 244        dpdk_drivers += static_lib
 245
 246        set_variable('shared_@0@'.format(lib_name), shared_dep)
 247        set_variable('static_@0@'.format(lib_name), static_dep)
 248        dependency_name = ''.join(lib_name.split('rte_'))
 249        if developer_mode
 250            message('drivers/@0@: Defining dependency "@1@"'.format(
 251                    drv_path, dependency_name))
 252        endif
 253    endforeach
 254
 255    set_variable(class + '_drivers', enabled_drivers)
 256endforeach
 257