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