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