[v2,4/4] net/mlx: workaround static linkage with meson
diff mbox series

Message ID 20200127154402.4008069-5-thomas@monjalon.net
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series
  • add static ibverbs in meson
Related show

Checks

Context Check Description
ci/travis-robot success Travis build: passed
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon Jan. 27, 2020, 3:44 p.m. UTC
If ibverbs_link is static and the application choose to link DPDK
as static libraries, both PMD and ibverbs libraries must be linked
as static libraries. And the dependencies of ibverbs (netlink) must
still be linked as shared libraries.

Unfortunately, meson forget about the static requirement for ibverbs
when generating the .pc file.
As a result, libibverbs, libmlx4, libmlx5 are listed in Requires.private
section (allowing to be linked as shared libraries) and libnl is missing.

A fix is in progress for meson, but anyway we will have to live without
such a fix until a better version of meson is widely available:
	https://github.com/mesonbuild/meson/pull/6393

In order to not allow meson suggesting shared libraries in the section
Requires.private of the .pc file, the cflags are passed as hidden_deps.
The list of required dependencies is replaced with ldflags, forcing
static flavor of ibverbs libraries thanks to this syntax:
	-l:libfoo.a

Fixes: 83fff714bd27 ("net/mlx: add static ibverbs linkage with meson")

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 buildtools/meson.build       |  2 ++
 drivers/net/mlx4/meson.build | 14 ++++++++++++--
 drivers/net/mlx5/meson.build | 14 ++++++++++++--
 3 files changed, 26 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/buildtools/meson.build b/buildtools/meson.build
index cd1d054036..2a25527385 100644
--- a/buildtools/meson.build
+++ b/buildtools/meson.build
@@ -7,6 +7,8 @@  pmdinfo = find_program('gen-pmdinfo-cfile.sh')
 
 check_experimental_syms = find_program('check-experimental-syms.sh')
 
+ldflags_ibverbs_static = find_program('options-ibverbs-static.sh')
+
 # set up map-to-def script using python, either built-in or external
 python3 = import('python').find_installation(required: false)
 if python3.found()
diff --git a/drivers/net/mlx4/meson.build b/drivers/net/mlx4/meson.build
index 51d9784ee2..724256bfb4 100644
--- a/drivers/net/mlx4/meson.build
+++ b/drivers/net/mlx4/meson.build
@@ -30,16 +30,26 @@  foreach libname:libnames
 		lib = cc.find_library(libname, required:false)
 	endif
 	if lib.found()
-		libs += [ lib ]
+		libs += lib
+		if static_ibverbs
+			# Build without adding shared libs to Requires.private
+			hidden_deps += lib.partial_dependency(compile_args:true)
+		else
+			ext_deps += lib
+		endif
 	else
 		build = false
 		reason = 'missing dependency, "' + libname + '"'
 	endif
 endforeach
+if build and static_ibverbs
+	# Add static deps ldflags to internal apps and Libs.private
+	ldflags = run_command(ldflags_ibverbs_static, check:true).stdout()
+	ext_deps += declare_dependency(link_args:ldflags.split())
+endif
 
 if build
 	allow_experimental_apis = true
-	ext_deps += libs
 	sources = files(
 		'mlx4.c',
 		'mlx4_ethdev.c',
diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build
index a4f2f79f22..e04c8947e0 100644
--- a/drivers/net/mlx5/meson.build
+++ b/drivers/net/mlx5/meson.build
@@ -30,17 +30,27 @@  foreach libname:libnames
 		lib = cc.find_library(libname, required:false)
 	endif
 	if lib.found()
-		libs += [ lib ]
+		libs += lib
+		if static_ibverbs
+			# Build without adding shared libs to Requires.private
+			hidden_deps += lib.partial_dependency(compile_args:true)
+		else
+			ext_deps += lib
+		endif
 	else
 		build = false
 		reason = 'missing dependency, "' + libname + '"'
 	endif
 endforeach
+if build and static_ibverbs
+	# Add static deps ldflags to internal apps and Libs.private
+	ldflags = run_command(ldflags_ibverbs_static, check:true).stdout()
+	ext_deps += declare_dependency(link_args:ldflags.split())
+endif
 
 if build
 	allow_experimental_apis = true
 	deps += ['hash']
-	ext_deps += libs
 	sources = files(
 		'mlx5.c',
 		'mlx5_ethdev.c',