[Networkmanager] Using NetworkManager libraries in CMake

Thomas Haller thaller at redhat.com
Tue Jan 3 10:26:43 UTC 2023

On Tue, 2023-01-03 at 10:56 +1300, Tom Isaacson wrote:
> I'm using ModemManager 1.22.16. I've added this to my Yocto build
> using:
> https://cgit.openembedded.org/meta-openembedded/tree/meta-networking/recipes-connectivity/networkmanager?h=dunfell
> My application is built within Yocto using CMake. I want to use the
> nm_dbus_ functions specified in shared/nm-glib-aux/nm-dbus-aux.h.

you cannot. This is internal source code of NetworkManager, it's not
public/stable API. Well, of course it's free software, so you are
welcome to use it in any way that suits you (while honoring LGPL
license). But it's probably cumbersome.

Note that "nm-glib-aux" merely contains utility/convenience helpers
around glib and GDBus. It does nothing magical, you can just
reimplement them, or even copying them (while honoring LGPL).

The actual APIs of NetworkManager are:

NetworkManager provides a shared library (based on glib + GDBus) that
abstracs the D-Bus API and has code to handle NetworkManager's
connection profiles. That's "libnm", and you can use "libnm.pc" file.
Try `pkg-config --cflags --libs libnm`.

In the NetworkManager sources there are also two headers:
these headers are part of libnm's API, but you can also use them
independently. They are header only, so you only need them as build
dependency, but you don't need to link with libnm. In that case, also
get the include directory from "libnm.pc"

Finally, you can of course always talk D-Bus directly. Then you don't
need any library (aside a D-Bus library). The documentation for the D-
Bus API is here: https://networkmanager.dev/docs/developers/ .

Finally2, the file formats in /etc/NetworkManager/system-connections
are also an API. But you probable want you use D-Bus (or something on
top of D-Bus, like libnm).

> 1. How can I declare NetworkManager to CMake? I can see there's a
> NetworkManager.pc.in file but it doesn't always get built.

libnm.pc, if you want to use libnm.

> 2. The include file only appears way down in
> rootfs-dbg/usr/src/debug/networkmanager/1.22.16-r0/NetworkManager-
> 1.22.16/shared/nm-glib-aux/nm-dbus-aux.h,
> is this expected?

This is an internal source file of NetworkManager, not public API.

> 3. When I include nm-dbus-aux.h the build fails because it includes
> nm-std-aux/nm-dbus-compat.h which isn't present. Do I need to set a
> build flag for this?


More information about the Networkmanager mailing list