b7fdfb73578de684da5afbd3d75707fb6af3f390
[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                'raw',     # depends on common and bus.
13                'net',     # depends on common, bus, mempool and raw.
14                'crypto',  # depends on common, bus and mempool (net in future).
15                'compress', # depends on common, bus, mempool.
16                'event',   # depends on common, bus, mempool and net.
17                'baseband'] # depends on common and bus.
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                 # skip disabled drivers. For meson 0.49 change this to use
65                 # "in" keyword
66                 foreach disable_path: disabled_drivers
67                         if drv_path == disable_path
68                                 build = false
69                                 reason = 'Explicitly disabled via build config'
70                         endif
71                 endforeach
72                 if build
73                         # get dependency objs from strings
74                         shared_deps = ext_deps
75                         static_deps = ext_deps
76                         foreach d:deps
77                                 if not is_variable('shared_rte_' + d)
78                                         build = false
79                                         reason = 'Missing internal dependency, "@0@"'.format(d)
80                                         message('Disabling @1@ [@2@]: missing internal dependency "@0@"'
81                                                         .format(d, name, 'drivers/' + drv_path))
82                                 else
83                                         shared_deps += [get_variable('shared_rte_' + d)]
84                                         static_deps += [get_variable('static_rte_' + d)]
85                                 endif
86                         endforeach
87                 endif
88
89                 if not build
90                         # some driver directories are placeholders which
91                         # are never built, so we allow suppression of the
92                         # component disable printout in those cases
93                         if reason != ''
94                                 dpdk_drvs_disabled += drv_path
95                                 set_variable(drv_path.underscorify() +
96                                                 '_disable_reason', reason)
97                         endif
98                 else
99                         class_drivers += name
100
101                         dpdk_conf.set(config_flag_fmt.format(name.to_upper()),1)
102                         lib_name = driver_name_fmt.format(name)
103
104                         if allow_experimental_apis
105                                 cflags += '-DALLOW_EXPERIMENTAL_API'
106                         endif
107
108                         dpdk_extra_ldflags += pkgconfig_extra_libs
109
110                         # generate pmdinfo sources by building a temporary
111                         # lib and then running pmdinfogen on the contents of
112                         # that lib. The final lib reuses the object files and
113                         # adds in the new source file.
114                         out_filename = lib_name + '.pmd.c'
115                         tmp_lib = static_library('tmp_' + lib_name,
116                                         sources,
117                                         include_directories: includes,
118                                         dependencies: static_deps,
119                                         c_args: cflags)
120                         objs += tmp_lib.extract_all_objects()
121                         sources = custom_target(out_filename,
122                                         command: [pmdinfo, tmp_lib.full_path(),
123                                                 '@OUTPUT@', pmdinfogen],
124                                         output: out_filename,
125                                         depends: [pmdinfogen, tmp_lib])
126
127                         if get_option('per_library_versions')
128                                 lib_version = '@0@.1'.format(version)
129                                 so_version = '@0@'.format(version)
130                         else
131                                 lib_version = major_version
132                                 so_version = major_version
133                         endif
134
135                         # now build the static driver
136                         static_lib = static_library(lib_name,
137                                 sources,
138                                 objects: objs,
139                                 include_directories: includes,
140                                 dependencies: static_deps,
141                                 c_args: cflags,
142                                 install: true)
143
144                         # now build the shared driver
145                         version_map = '@0@/@1@/@2@_version.map'.format(
146                                         meson.current_source_dir(),
147                                         drv_path, lib_name)
148                         implib = dir_name + '.dll.a'
149
150                         def_file = custom_target(lib_name + '_def',
151                                 command: [map_to_def_cmd, '@INPUT@', '@OUTPUT@'],
152                                 input: version_map,
153                                 output: '@0@_exports.def'.format(lib_name))
154                         lk_deps = [version_map, def_file]
155                         if is_windows
156                                 lk_args = ['-Wl,/def:' + def_file.full_path(),
157                                         '-Wl,/implib:lib\\' + implib]
158                         else
159                                 lk_args = ['-Wl,--version-script=' + version_map]
160                                 # on unix systems check the output of the
161                                 # experimental syms script, using it as a
162                                 # dependency of the .so build
163                                 lk_deps += custom_target(lib_name + '.exp_chk',
164                                         command: [check_experimental_syms,
165                                                 version_map, '@INPUT@'],
166                                         capture: true,
167                                         input: static_lib,
168                                         output: lib_name + '.exp_chk')
169                         endif
170
171                         shared_lib = shared_library(lib_name,
172                                 sources,
173                                 objects: objs,
174                                 include_directories: includes,
175                                 dependencies: shared_deps,
176                                 c_args: cflags,
177                                 link_args: lk_args,
178                                 link_depends: lk_deps,
179                                 version: lib_version,
180                                 soversion: so_version,
181                                 install: true,
182                                 install_dir: driver_install_path)
183
184                         # create a dependency object and add it to the global dictionary so
185                         # testpmd or other built-in apps can find it if necessary
186                         shared_dep = declare_dependency(link_with: shared_lib,
187                                         include_directories: includes,
188                                         dependencies: shared_deps)
189                         static_dep = declare_dependency(link_with: static_lib,
190                                         include_directories: includes,
191                                         dependencies: static_deps)
192
193                         dpdk_drivers += static_lib
194
195                         set_variable('shared_@0@'.format(lib_name), shared_dep)
196                         set_variable('static_@0@'.format(lib_name), static_dep)
197                         dependency_name = ''.join(lib_name.split('rte_'))
198                         message('drivers/@0@: Defining dependency "@1@"'.format(
199                                         drv_path, dependency_name))
200                 endif # build
201         endforeach
202
203         set_variable(class + '_drivers', class_drivers)
204 endforeach