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