Skip to contentSkip to conversation

build: allow build DPDK as a meson submodule

RFC In review Stephen Hemminger 4 participants 12 messages Nov 3, 2021 – Jun 7, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 build: allow build DPDK as a meson submodule

Some other projects using meson may not be able to use DPDK using the standard distribution pkg-config mechanism. Meson supports a way to handle this via the subproject
https://mesonbuild.com/Subprojects.html

This patch adds the necessary depedency to follow the "Naming convention for depedency variables" from the documentation. It has no impact if subproject is not being used.

---
 meson.build | 10 ++++++++++
 1 file changed, 10 insertions(+)
meson.build +10 -0
index 12cb6e0e83f3..6ce5eda2779f 100644
@@ -97,6 +97,16 @@ configure_file(output: build_cfg,
 # build pkg-config files for dpdk
 subdir('buildtools/pkg-config')
 
+# If DPDK is being built as subproject then define
+# varialble with the dependency convention
+if meson.is_subproject()
+    libdpdk_dep = declare_dependency(
+        version: meson.project_version(),
+        compile_args : pkg_extra_cflags,
+        dependencies: shared_deps
+    )
+endif
+
 # final output, list all the libs and drivers to be built
 # this does not affect any part of the build, for information only.
 output_message = '\n=================\nLibraries Enabled\n=================\n'
Signature · 1 line
2.30.2
#1 lore raw
Quoted 10 lines · Stephen Hemminger

Some other projects using meson may not be able to use DPDK using the standard distribution pkg-config mechanism. Meson supports a way to handle this via the subproject
https://mesonbuild.com/Subprojects.html

This patch adds the necessary depedency to follow the "Naming convention for depedency variables" from the documentation. It has no impact if subproject is not being used.

Thanks for this Stephen. Couple of comments inline below.

/Bruce

Quoted 9 lines
---
 meson.build | 10 ++++++++++
 1 file changed, 10 insertions(+)
meson.build +0 -0
index 12cb6e0e83f3..6ce5eda2779f 100644

meson.build configure_file(output: build_cfg, · line 102

Quoted 6 lines
meson.build +3 -0
@@ -97,6 +97,16 @@ configure_file(output: build_cfg,
 # build pkg-config files for dpdk
 subdir('buildtools/pkg-config')
 
+# If DPDK is being built as subproject then define
+# varialble with the dependency convention
+if meson.is_subproject()

I wonder if we should just omit this check. Defining the extra variable in case of non-subproject should just be harmless.

meson.build configure_file(output: build_cfg, · line 107

Quoted 5 lines
meson.build +5 -0
+    libdpdk_dep = declare_dependency(
+        version: meson.project_version(),
+        compile_args : pkg_extra_cflags,
+        dependencies: shared_deps
+    )

"shared_deps" is almost certainly not the correct variable to use here without additional changes to guarantee its value. That variable is used in lib and driver meson.build files to hold the libraries to link for each shared object, so at this point in the build, it will likely contain only the dependencies of the final driver built, rather than all the DPDK libraries. I think it would be safer to define "dpdk_shared_deps" global variable at the top of this meson.build file and add to that from lib/meson.build as each library dependency is defined.

Quoted 2 lines
meson.build +2 -0
+endif
+
#2 lore raw

PATCH 1/1 build: allow build DPDK as a meson submodule

In reply to Stephen Hemminger

Some other projects using meson may not be able to use DPDK using the standard distribution pkg-config mechanism. Meson supports a way to handle this via the subproject
https://mesonbuild.com/Subprojects.html

This patch adds the necessary dependency to follow the "Naming convention for dependency variables" from the documentation.

---
Cleaned up from RFC and support both static and shared.

 lib/meson.build |  5 +++++
 meson.build     | 12 ++++++++++++
 2 files changed, 17 insertions(+)
lib/meson.build +5 -0
index 499d26060fdd..e6df538bd6ef 100644
@@ -241,6 +241,11 @@ foreach l:libraries
 
     dpdk_libraries = [shared_lib] + dpdk_libraries
     dpdk_static_libraries = [static_lib] + dpdk_static_libraries
+    if get_option('default_library') == 'static'
+        dpdk_libs_deps += static_dep
+    else
+        dpdk_libs_deps += shared_dep
+    endif
 
     set_variable('shared_rte_' + name, shared_dep)
     set_variable('static_rte_' + name, static_dep)
meson.build +12 -0
index 12cb6e0e83f3..032783e4e6cf 100644
@@ -36,6 +36,7 @@ dpdk_drivers = []
 dpdk_extra_ldflags = []
 dpdk_libs_disabled = []
 dpdk_drvs_disabled = []
+dpdk_libs_deps = []
 abi_version_file = files('ABI_VERSION')
 
 if host_machine.cpu_family().startswith('x86')
@@ -97,6 +98,17 @@ configure_file(output: build_cfg,
 # build pkg-config files for dpdk
 subdir('buildtools/pkg-config')
 
+# If DPDK is being built as subproject then define
+# variable with the dependency convention
+if meson.is_subproject()
+    libdpdk_dep = declare_dependency(
+        version: meson.project_version(),
+        compile_args : pkg_extra_cflags,
+        dependencies: dpdk_libs_deps,
+        link_args: dpdk_extra_ldflags,
+    )
+endif
+
 # final output, list all the libs and drivers to be built
 # this does not affect any part of the build, for information only.
 output_message = '\n=================\nLibraries Enabled\n=================\n'
Signature · 1 line
2.30.2
#3 lore raw
Quoted 49 lines · Stephen Hemminger

Some other projects using meson may not be able to use DPDK using the standard distribution pkg-config mechanism. Meson supports a way to handle this via the subproject
https://mesonbuild.com/Subprojects.html

This patch adds the necessary dependency to follow the "Naming convention for dependency variables" from the documentation.

---
Cleaned up from RFC and support both static and shared.

 lib/meson.build |  5 +++++
 meson.build     | 12 ++++++++++++
 2 files changed, 17 insertions(+)
lib/meson.build +5 -0
index 499d26060fdd..e6df538bd6ef 100644
@@ -241,6 +241,11 @@ foreach l:libraries
 
     dpdk_libraries = [shared_lib] + dpdk_libraries
     dpdk_static_libraries = [static_lib] + dpdk_static_libraries
+    if get_option('default_library') == 'static'
+        dpdk_libs_deps += static_dep
+    else
+        dpdk_libs_deps += shared_dep
+    endif
 
     set_variable('shared_rte_' + name, shared_dep)
     set_variable('static_rte_' + name, static_dep)
meson.build +2 -0
index 12cb6e0e83f3..032783e4e6cf 100644
@@ -36,6 +36,7 @@ dpdk_drivers = []
 dpdk_extra_ldflags = []
 dpdk_libs_disabled = []
 dpdk_drvs_disabled = []
+dpdk_libs_deps = []
 abi_version_file = files('ABI_VERSION')
 
 if host_machine.cpu_family().startswith('x86')
@@ -97,6 +98,17 @@ configure_file(output: build_cfg,
 # build pkg-config files for dpdk
 subdir('buildtools/pkg-config')
 
+# If DPDK is being built as subproject then define

meson.build configure_file(output: build_cfg, · line 111

Quoted 10 lines
meson.build +10 -0
+# variable with the dependency convention
+if meson.is_subproject()
+    libdpdk_dep = declare_dependency(
+        version: meson.project_version(),
+        compile_args : pkg_extra_cflags,
+        dependencies: dpdk_libs_deps,
+        link_args: dpdk_extra_ldflags,
+    )
+endif
+

While the code all looks correct to me, when I tested it out, the resulting app couldn't link. I tested by moving l2fwd/main.c to a new folder and adding the following as a meson.build file in it:

project('l2fwd', 'C')

dpdk_dep = dependency('libdpdk', fallback : ['libdpdk', 'libdpdk_dep']) executable('dpdk-l2fwd', 'main.c',
dependencies: dpdk_dep)

Even though dependencies should include both the libs to link with and the include paths, that didn't seem to work in this case - the compile worked fine with all cflags present, none of the DPDK libraries were given on the link command - just the extra -ldl etc. args.
Adding "link_with: dpdk_libraries" fixed this and allowed it work for me, but I'm surpised that it proved necessary. Stephen, does it work for you with just the dependencies provided?

/Bruce

PS: My testing was done with meson 0.56.2 on Ubuntu 21.10.

#4 lore raw
Quoted 79 lines · On Fri, 5 Nov 2021 14:58:24 +0000 Bruce Richardson…
Quoted 49 lines · Stephen Hemminger

Some other projects using meson may not be able to use DPDK using the standard distribution pkg-config mechanism. Meson supports a way to handle this via the subproject
https://mesonbuild.com/Subprojects.html

This patch adds the necessary dependency to follow the "Naming convention for dependency variables" from the documentation.

---
Cleaned up from RFC and support both static and shared.

 lib/meson.build |  5 +++++
 meson.build     | 12 ++++++++++++
 2 files changed, 17 insertions(+)
lib/meson.build +5 -0
index 499d26060fdd..e6df538bd6ef 100644
@@ -241,6 +241,11 @@ foreach l:libraries
 
     dpdk_libraries = [shared_lib] + dpdk_libraries
     dpdk_static_libraries = [static_lib] + dpdk_static_libraries
+    if get_option('default_library') == 'static'
+        dpdk_libs_deps += static_dep
+    else
+        dpdk_libs_deps += shared_dep
+    endif
 
     set_variable('shared_rte_' + name, shared_dep)
     set_variable('static_rte_' + name, static_dep)
meson.build +2 -0
index 12cb6e0e83f3..032783e4e6cf 100644
@@ -36,6 +36,7 @@ dpdk_drivers = []
 dpdk_extra_ldflags = []
 dpdk_libs_disabled = []
 dpdk_drvs_disabled = []
+dpdk_libs_deps = []
 abi_version_file = files('ABI_VERSION')
 
 if host_machine.cpu_family().startswith('x86')
@@ -97,6 +98,17 @@ configure_file(output: build_cfg,
 # build pkg-config files for dpdk
 subdir('buildtools/pkg-config')
 
+# If DPDK is being built as subproject then define

meson.build configure_file(output: build_cfg, · line 111

Quoted 10 lines
meson.build +10 -0
+# variable with the dependency convention
+if meson.is_subproject()
+    libdpdk_dep = declare_dependency(
+        version: meson.project_version(),
+        compile_args : pkg_extra_cflags,
+        dependencies: dpdk_libs_deps,
+        link_args: dpdk_extra_ldflags,
+    )
+endif
+  

While the code all looks correct to me, when I tested it out, the resulting app couldn't link. I tested by moving l2fwd/main.c to a new folder and adding the following as a meson.build file in it:

project('l2fwd', 'C')

dpdk_dep = dependency('libdpdk', fallback : ['libdpdk', 'libdpdk_dep']) executable('dpdk-l2fwd', 'main.c',
dependencies: dpdk_dep)

Even though dependencies should include both the libs to link with and the include paths, that didn't seem to work in this case - the compile worked fine with all cflags present, none of the DPDK libraries were given on the link command - just the extra -ldl etc. args.
Adding "link_with: dpdk_libraries" fixed this and allowed it work for me, but I'm surpised that it proved necessary. Stephen, does it work for you with just the dependencies provided?

Quoted 3 lines

/Bruce

PS: My testing was done with meson 0.56.2 on Ubuntu 21.10.

I was testing with a cross-build with an app that uses quite limited dependencies, and it worked. Also, the app has same depedencies for some of the parts that are missed.

Will try l3fwd and something more complex for next version

#5 lore raw

PATCH v2 1/1 build: add definitions for use as meson subproject

In reply to Stephen Hemminger

Some other projects using meson may not be able to use DPDK using the standard distribution pkg-config mechanism. Meson supports a way to handle this via the subproject
https://mesonbuild.com/Subprojects.html

This patch adds the necessary dependency to follow the "Naming convention for dependency variables" from the documentation.

---

v2 - add link libraries

 lib/meson.build |  5 +++++
 meson.build     | 13 +++++++++++++
 2 files changed, 18 insertions(+)
lib/meson.build +5 -0
index 499d26060fdd..e6df538bd6ef 100644
@@ -241,6 +241,11 @@ foreach l:libraries
 
     dpdk_libraries = [shared_lib] + dpdk_libraries
     dpdk_static_libraries = [static_lib] + dpdk_static_libraries
+    if get_option('default_library') == 'static'
+        dpdk_libs_deps += static_dep
+    else
+        dpdk_libs_deps += shared_dep
+    endif
 
     set_variable('shared_rte_' + name, shared_dep)
     set_variable('static_rte_' + name, static_dep)
meson.build +13 -0
index 12cb6e0e83f3..3bf6bb794ce1 100644
@@ -36,6 +36,7 @@ dpdk_drivers = []
 dpdk_extra_ldflags = []
 dpdk_libs_disabled = []
 dpdk_drvs_disabled = []
+dpdk_libs_deps = []
 abi_version_file = files('ABI_VERSION')
 
 if host_machine.cpu_family().startswith('x86')
@@ -97,6 +98,18 @@ configure_file(output: build_cfg,
 # build pkg-config files for dpdk
 subdir('buildtools/pkg-config')
 
+# If DPDK is being built as subproject then define
+# variable with the dependency convention
+if meson.is_subproject()
+    libdpdk_dep = declare_dependency(
+        version: meson.project_version(),
+        compile_args : pkg_extra_cflags,
+        dependencies: dpdk_libs_deps,
+        link_args: dpdk_extra_ldflags,
+        link_with: dpdk_libraries
+    )
+endif
+
 # final output, list all the libs and drivers to be built
 # this does not affect any part of the build, for information only.
 output_message = '\n=================\nLibraries Enabled\n=================\n'
Signature · 1 line
2.30.2
Acked-by on v2 1/1
#6 lore raw

Re: [dpdk-dev] [PATCH v2] build: add definitions for use as meson subproject

Quoted 9 lines · Stephen Hemminger

Some other projects using meson may not be able to use DPDK using the standard distribution pkg-config mechanism. Meson supports a way to handle this via the subproject
https://mesonbuild.com/Subprojects.html

This patch adds the necessary dependency to follow the "Naming convention for dependency variables" from the documentation.

One comment inline below. Otherwise:

Quoted 39 lines

---

v2 - add link libraries

 lib/meson.build |  5 +++++
 meson.build     | 13 +++++++++++++
 2 files changed, 18 insertions(+)
lib/meson.build +5 -0
index 499d26060fdd..e6df538bd6ef 100644
@@ -241,6 +241,11 @@ foreach l:libraries
 
     dpdk_libraries = [shared_lib] + dpdk_libraries
     dpdk_static_libraries = [static_lib] + dpdk_static_libraries
+    if get_option('default_library') == 'static'
+        dpdk_libs_deps += static_dep
+    else
+        dpdk_libs_deps += shared_dep
+    endif
 
     set_variable('shared_rte_' + name, shared_dep)
     set_variable('static_rte_' + name, static_dep)
meson.build +1 -0
index 12cb6e0e83f3..3bf6bb794ce1 100644
@@ -36,6 +36,7 @@ dpdk_drivers = []
 dpdk_extra_ldflags = []
 dpdk_libs_disabled = []
 dpdk_drvs_disabled = []
+dpdk_libs_deps = []
 abi_version_file = files('ABI_VERSION')
 
 if host_machine.cpu_family().startswith('x86')
@@ -97,6 +98,18 @@ configure_file(output: build_cfg,
 # build pkg-config files for dpdk
 subdir('buildtools/pkg-config')

meson.build configure_file(output: build_cfg, · line 109

Quoted 10 lines
meson.build +9 -0
 
+# If DPDK is being built as subproject then define
+# variable with the dependency convention
+if meson.is_subproject()
+    libdpdk_dep = declare_dependency(
+        version: meson.project_version(),
+        compile_args : pkg_extra_cflags,
+        dependencies: dpdk_libs_deps,
+        link_args: dpdk_extra_ldflags,
+        link_with: dpdk_libraries

Minor nit, but the dpdk_libraries is always the shared libs, it's dpdk_static_libraries in the static case. Since elsewhere you switched on the "default_library" value, maybe you should do so here.

Personally, I'd tend more towards having two new vars, "dpdk_libs_deps" and "dpdk_static_libs_deps", and then define two global dependency objects:
"libdpdk_dep" and "libdpdk_static_dep", to make it easy for subprojects to pull in the one they want.

Quoted 9 lines
meson.build +3 -0
+    )
+endif
+
 # final output, list all the libs and drivers to be built
 # this does not affect any part of the build, for information only.
 output_message = '\n=================\nLibraries Enabled\n=================\n'
Signature · 1 line
2.30.2
#7 lore raw

Re: [dpdk-dev] [PATCH v2] build: add definitions for use as meson subproject

05/11/2021 19:11, Bruce Richardson:

Quoted 15 lines · Stephen Hemminger

meson.build configure_file(output: build_cfg, · line 109

Quoted 9 lines
meson.build +9 -0
+# If DPDK is being built as subproject then define
+# variable with the dependency convention
+if meson.is_subproject()
+    libdpdk_dep = declare_dependency(
+        version: meson.project_version(),
+        compile_args : pkg_extra_cflags,
+        dependencies: dpdk_libs_deps,
+        link_args: dpdk_extra_ldflags,
+        link_with: dpdk_libraries

Minor nit, but the dpdk_libraries is always the shared libs, it's dpdk_static_libraries in the static case. Since elsewhere you switched on the "default_library" value, maybe you should do so here.

Quoted 4 lines

Personally, I'd tend more towards having two new vars, "dpdk_libs_deps" and "dpdk_static_libs_deps", and then define two global dependency objects:
"libdpdk_dep" and "libdpdk_static_dep", to make it easy for subprojects to pull in the one they want.

I don't want to merge this patch without having an answer to this comment. Stephen, what do you think?

#8 lore raw

Re: [PATCH v2] build: add definitions for use as meson subproject

In reply to Stephen Hemminger
Quoted 5 lines · Stephen Hemminger

Some other projects using meson may not be able to use DPDK using the standard distribution pkg-config mechanism. Meson supports a way to handle this via the subproject
https://mesonbuild.com/Subprojects.html

Quoted 8 lines

This patch adds the necessary dependency to follow the "Naming convention for dependency variables" from the documentation.

---

v2 - add link libraries

Playing around with DPDK as a meson subproject myself, I have some additional thoughts on how to put this in DPDK and some further comments on this patch. For example:

* For static builds we need to "link_whole" the drivers, as well as doing a "link_with" on the libraries
* for shared builds - which will need to be done explicitly by passing the subproject the default_library type parameter we actually don't need to include the "link_with" line since the libs are already included in the shared deps. [I think they should be added to the static deps too, if that doesn't cause any problems]
* we therefore likely need slightly different subproject definitions for shared vs static, and I'd suggest moving that to a new file e.g. in "buildtools/subproject" - to avoid cluttering the main file too much.

If you don't mind, I'll do a re-spin of this functionality in a V3 patch, based on above ideas, and we can see where we go there.

/Bruce

#9 lore raw

PATCH v3 1/1 build: add definitions for use as meson subproject

In reply to Stephen Hemminger

To allow other projects to easily use DPDK as a subproject, add in the necessary dependency definitions. Slightly different definitions are necessary for static and shared builds, since for shared builds the drivers should not be linked in, and the internal meson dependency objects are more complete.

To use DPDK as a subproject fallback i.e. use installed DPDK if present, otherwise the shipped one, the following meson statement can be used:

libdpdk = dependency('libdpdk', fallback: ['dpdk', 'dpdk_dep'])

---
 buildtools/subproject/meson.build | 21 +++++++++++++++++++++
 drivers/meson.build               |  4 ++++
 lib/meson.build                   |  2 ++
 meson.build                       |  6 ++++++
 4 files changed, 33 insertions(+)
 create mode 100644 buildtools/subproject/meson.build
buildtools/subproject/meson.build new file +21 -0
new file mode 100644
index 0000000000..3192efaa40
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2022 Intel Corporation
+
+message('DPDK subproject linking: ' + get_option('default_library'))
+if get_option('default_library') == 'static'
+    dpdk_dep = declare_dependency(
+            version: meson.project_version(),
+            dependencies: dpdk_static_lib_deps,
+            # static library deps in DPDK build don't include "link_with" parameters,
+            # so explicitly link-in both libs and drivers
+            link_with: dpdk_static_libraries,
+            link_whole: dpdk_drivers,
+            link_args: dpdk_extra_ldflags)
+else
+    dpdk_dep = declare_dependency(
+            version: meson.project_version(),
+            # shared library deps include all necessary linking parameters
+            dependencies: dpdk_shared_lib_deps)
+endif
+
+libdpdk_dep = dpdk_dep
drivers/meson.build +4 -0
index 1d8123b00c..db4d9c73bd 100644
@@ -245,6 +245,10 @@ foreach subpath:subdirs
 
         set_variable('shared_@0@'.format(lib_name), shared_dep)
         set_variable('static_@0@'.format(lib_name), static_dep)
+        # for drivers, we only need to add dependency objects for static libs,
+        # shared lib drivers are not linked in
+        dpdk_static_lib_deps += static_dep
+
         dependency_name = ''.join(lib_name.split('rte_'))
         if developer_mode
             message('drivers/@0@: Defining dependency "@1@"'.format(
lib/meson.build +2 -0
index 24adbe44c9..c648f7d800 100644
@@ -266,6 +266,8 @@ foreach l:libraries
 
     set_variable('shared_rte_' + name, shared_dep)
     set_variable('static_rte_' + name, static_dep)
+    dpdk_shared_lib_deps += shared_dep
+    dpdk_static_lib_deps += static_dep
     if developer_mode
         message('lib/@0@: Defining dependency "@1@"'.format(l, name))
     endif
meson.build +6 -0
index 937f6110c0..6085e32a79 100644
@@ -36,6 +36,8 @@ dpdk_build_root = meson.current_build_dir()
 dpdk_conf = configuration_data()
 dpdk_libraries = []
 dpdk_static_libraries = []
+dpdk_shared_lib_deps = []
+dpdk_static_lib_deps = []
 dpdk_chkinc_headers = []
 dpdk_driver_classes = []
 dpdk_drivers = []
@@ -103,6 +105,10 @@ configure_file(output: build_cfg,
 # build pkg-config files for dpdk
 subdir('buildtools/pkg-config')
 
+if meson.is_subproject()
+    subdir('buildtools/subproject')
+endif
+
 # final output, list all the libs and drivers to be built
 # this does not affect any part of the build, for information only.
 output_message = '\n=================\nLibraries Enabled\n=================\n'
Signature · 1 line
2.34.1
Reviewed-by Tested-by on v3 1/1
#10 lore raw

Re: [PATCH v3] build: add definitions for use as meson subproject

Currently utilizing this in an upcoming set of changes for TLDK and all seems to be working for fallback dependency support under both shared and static linkage.

Quoted 108 lines · Bruce Richardson

To allow other projects to easily use DPDK as a subproject, add in the necessary dependency definitions. Slightly different definitions are necessary for static and shared builds, since for shared builds the drivers should not be linked in, and the internal meson dependency objects are more complete.

To use DPDK as a subproject fallback i.e. use installed DPDK if present, otherwise the shipped one, the following meson statement can be used:

libdpdk = dependency('libdpdk', fallback: ['dpdk', 'dpdk_dep'])

---
 buildtools/subproject/meson.build | 21 +++++++++++++++++++++
 drivers/meson.build               |  4 ++++
 lib/meson.build                   |  2 ++
 meson.build                       |  6 ++++++
 4 files changed, 33 insertions(+)
 create mode 100644 buildtools/subproject/meson.build
buildtools/subproject/meson.build new file +9 -0
new file mode 100644
index 0000000000..3192efaa40
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2022 Intel Corporation
+
+message('DPDK subproject linking: ' + get_option('default_library'))
+if get_option('default_library') == 'static'
+    dpdk_dep = declare_dependency(
+            version: meson.project_version(),
+            dependencies: dpdk_static_lib_deps,
+            # static library deps in DPDK build don't include "link_with"

parameters,

buildtools/subproject/meson.build new file +12 -0
+            # so explicitly link-in both libs and drivers
+            link_with: dpdk_static_libraries,
+            link_whole: dpdk_drivers,
+            link_args: dpdk_extra_ldflags)
+else
+    dpdk_dep = declare_dependency(
+            version: meson.project_version(),
+            # shared library deps include all necessary linking parameters
+            dependencies: dpdk_shared_lib_deps)
+endif
+
+libdpdk_dep = dpdk_dep
drivers/meson.build +4 -0
index 1d8123b00c..db4d9c73bd 100644
@@ -245,6 +245,10 @@ foreach subpath:subdirs
 
         set_variable('shared_@0@'.format(lib_name), shared_dep)
         set_variable('static_@0@'.format(lib_name), static_dep)
+        # for drivers, we only need to add dependency objects for static
 libs,
+        # shared lib drivers are not linked in
+        dpdk_static_lib_deps += static_dep
+
         dependency_name = ''.join(lib_name.split('rte_'))
         if developer_mode
             message('drivers/@0@: Defining dependency "@1@"'.format(
lib/meson.build +2 -0
index 24adbe44c9..c648f7d800 100644
@@ -266,6 +266,8 @@ foreach l:libraries
 
     set_variable('shared_rte_' + name, shared_dep)
     set_variable('static_rte_' + name, static_dep)
+    dpdk_shared_lib_deps += shared_dep
+    dpdk_static_lib_deps += static_dep
     if developer_mode
         message('lib/@0@: Defining dependency "@1@"'.format(l, name))
     endif
meson.build +6 -0
index 937f6110c0..6085e32a79 100644
@@ -36,6 +36,8 @@ dpdk_build_root = meson.current_build_dir()
 dpdk_conf = configuration_data()
 dpdk_libraries = []
 dpdk_static_libraries = []
+dpdk_shared_lib_deps = []
+dpdk_static_lib_deps = []
 dpdk_chkinc_headers = []
 dpdk_driver_classes = []
 dpdk_drivers = []
@@ -103,6 +105,10 @@ configure_file(output: build_cfg,
 # build pkg-config files for dpdk
 subdir('buildtools/pkg-config')
 
+if meson.is_subproject()
+    subdir('buildtools/subproject')
+endif
+
 # final output, list all the libs and drivers to be built
 # this does not affect any part of the build, for information only.
 output_message = '\n=================\nLibraries

Enabled\n=================\n'
--
2.34.1

#11 lore raw

Re: [PATCH v3] build: add definitions for use as meson subproject

21/05/2022 02:54, Ben Magistro:

Quoted 4 lines

Currently utilizing this in an upcoming set of changes for TLDK and all seems to be working for fallback dependency support under both shared and static linkage.

Quoted 19 lines
Quoted 13 lines · Bruce Richardson

To allow other projects to easily use DPDK as a subproject, add in the necessary dependency definitions. Slightly different definitions are necessary for static and shared builds, since for shared builds the drivers should not be linked in, and the internal meson dependency objects are more complete.

To use DPDK as a subproject fallback i.e. use installed DPDK if present, otherwise the shipped one, the following meson statement can be used:

libdpdk = dependency('libdpdk', fallback: ['dpdk', 'dpdk_dep'])

Applied, thanks.