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