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