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