build: support disabling drivers with meson
[dpdk.git] / drivers / meson.build
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2017-2019 Intel Corporation
3
4 if is_windows
5         subdir_done()
6 endif
7
8 # Defines the order in which the drivers are buit.
9 dpdk_driver_classes = ['common',
10                'bus',
11                'mempool', # depends on common and bus.
12                'net',     # depends on common, bus and mempool.
13                'crypto',  # depends on common, bus and mempool (net in future).
14                'compress', # depends on common, bus, mempool.
15                'event',   # depends on common, bus, mempool and net.
16                'baseband', # depends on common and bus.
17                'raw']     # depends on common, bus, mempool, net and event.
18
19 disabled_drivers = get_option('disable_drivers').split(',')
20
21 default_cflags = machine_args
22 if cc.has_argument('-Wno-format-truncation')
23         default_cflags += '-Wno-format-truncation'
24 endif
25
26 foreach class:dpdk_driver_classes
27         drivers = []
28         std_deps = []
29         config_flag_fmt = '' # format string used to set the value in dpdk_conf
30         driver_name_fmt = '' # format string for driver name, used to name
31                              # the library, the dependency and to find the
32                              # version file for linking
33
34         subdir(class)
35         class_drivers = []
36
37         foreach drv:drivers
38                 drv_path = join_paths(class, drv)
39
40                 # set up empty variables used for build
41                 build = true # set to false to disable, e.g. missing deps
42                 reason = '<unknown reason>' # set if build == false to explain
43                 name = drv
44                 version = 1
45                 allow_experimental_apis = false
46                 sources = []
47                 objs = []
48                 cflags = default_cflags
49                 includes = [include_directories(drv_path)]
50                 # set up internal deps. Drivers can append/override as necessary
51                 deps = std_deps
52                 # ext_deps: Stores external library dependency got
53                 # using dependency() (preferred) or find_library().
54                 # For the find_library() case (but not with dependency()) we also
55                 # need to specify the "-l" flags in pkgconfig_extra_libs variable
56                 # too, so that it can be reflected in the pkgconfig output for
57                 # static builds.
58                 ext_deps = []
59                 pkgconfig_extra_libs = []
60
61                 # pull in driver directory which should assign to each of the above
62                 subdir(drv_path)
63
64                 if drv_path in disabled_drivers
65                         build = false
66                         reason = 'Explicitly disabled via build config'
67                 elif build
68                         # get dependency objs from strings
69                         shared_deps = ext_deps
70                         static_deps = ext_deps
71                         foreach d:deps
72                                 if not is_variable('shared_rte_' + d)
73                                         build = false
74                                         reason = 'Missing internal dependency, "@0@"'.format(d)
75                                         message('Disabling @1@ [@2@]: missing internal dependency "@0@"'
76                                                         .format(d, name, 'drivers/' + drv_path))
77                                 else
78                                         shared_deps += [get_variable('shared_rte_' + d)]
79                                         static_deps += [get_variable('static_rte_' + d)]
80                                 endif
81                         endforeach
82                 endif
83
84                 if not build
85                         # some driver directories are placeholders which
86                         # are never built, so we allow suppression of the
87                         # component disable printout in those cases
88                         if reason != ''
89                                 dpdk_drvs_disabled += drv_path
90                                 set_variable(drv_path.underscorify() +
91                                                 '_disable_reason', reason)
92                         endif
93                 else
94                         class_drivers += name
95
96                         dpdk_conf.set(config_flag_fmt.format(name.to_upper()),1)
97                         lib_name = driver_name_fmt.format(name)
98
99                         if allow_experimental_apis
100                                 cflags += '-DALLOW_EXPERIMENTAL_API'
101                         endif
102
103                         dpdk_extra_ldflags += pkgconfig_extra_libs
104
105                         # generate pmdinfo sources by building a temporary
106                         # lib and then running pmdinfogen on the contents of
107                         # that lib. The final lib reuses the object files and
108                         # adds in the new source file.
109                         out_filename = lib_name + '.pmd.c'
110                         tmp_lib = static_library('tmp_' + lib_name,
111                                         sources,
112                                         include_directories: includes,
113                                         dependencies: static_deps,
114                                         c_args: cflags)
115                         objs += tmp_lib.extract_all_objects()
116                         sources = custom_target(out_filename,
117                                         command: [pmdinfo, tmp_lib.full_path(),
118                                                 '@OUTPUT@', pmdinfogen],
119                                         output: out_filename,
120                                         depends: [pmdinfogen, tmp_lib])
121
122                         if get_option('per_library_versions')
123                                 lib_version = '@0@.1'.format(version)
124                                 so_version = '@0@'.format(version)
125                         else
126                                 lib_version = major_version
127                                 so_version = major_version
128                         endif
129
130                         # now build the static driver
131                         static_lib = static_library(lib_name,
132                                 sources,
133                                 objects: objs,
134                                 include_directories: includes,
135                                 dependencies: static_deps,
136                                 c_args: cflags,
137                                 install: true)
138
139                         # now build the shared driver
140                         version_map = '@0@/@1@/@2@_version.map'.format(
141                                         meson.current_source_dir(),
142                                         drv_path, lib_name)
143                         shared_lib = shared_library(lib_name,
144                                 sources,
145                                 objects: objs,
146                                 include_directories: includes,
147                                 dependencies: shared_deps,
148                                 c_args: cflags,
149                                 link_args: '-Wl,--version-script=' + version_map,
150                                 link_depends: version_map,
151                                 version: lib_version,
152                                 soversion: so_version,
153                                 install: true,
154                                 install_dir: driver_install_path)
155
156                         # create a dependency object and add it to the global dictionary so
157                         # testpmd or other built-in apps can find it if necessary
158                         shared_dep = declare_dependency(link_with: shared_lib,
159                                         include_directories: includes,
160                                         dependencies: shared_deps)
161                         static_dep = declare_dependency(link_with: static_lib,
162                                         include_directories: includes,
163                                         dependencies: static_deps)
164
165                         dpdk_drivers += static_lib
166
167                         set_variable('shared_@0@'.format(lib_name), shared_dep)
168                         set_variable('static_@0@'.format(lib_name), static_dep)
169                         dependency_name = ''.join(lib_name.split('rte_'))
170                         message('drivers/@0@: Defining dependency "@1@"'.format(
171                                         drv_path, dependency_name))
172                 endif # build
173         endforeach
174
175         set_variable(class + '_drivers', class_drivers)
176 endforeach