libnm: allow opt-out of including system headers in <NetworkManager.h>

In public libnm headers we include some libc/linux headers, although
libnm doesn't strictly need them.

The <linux/*.h> headers conflict with some network headers provided by
libc and they need to be included in the right order. As
<NetworkManager.h> drags in some linux headers, this makes it
unnecessarily complicated.

It also feels ugly to include headers we don't need, only for the
sake of convenience. Allow to opt out.

Also, for internal build, don't do this. When building NetworkManager
we need control about the headers and their order of inclusion.
This commit is contained in:
Thomas Haller
2020-12-13 22:05:10 +01:00
parent 45ed23c46e
commit 89c8592f93
3 changed files with 11 additions and 7 deletions

View File

@@ -11,7 +11,6 @@
#endif
#include "nm-setting.h"
#include <linux/if_vlan.h>
G_BEGIN_DECLS

View File

@@ -12,12 +12,6 @@
#include <glib.h>
#include <netinet/in.h>
/* For ETH_ALEN and INFINIBAND_ALEN */
#include <linux/if_ether.h>
#include <linux/if_infiniband.h>
#include "nm-core-enum-types.h"
#include "nm-setting-sriov.h"
#include "nm-setting-tc-config.h"

View File

@@ -115,6 +115,17 @@
#include "nm-autoptr.h"
#if !defined(NETWORKMANAGER_COMPILATION) \
&& (!defined(NM_NO_INCLUDE_EXTRA_HEADERS) || !NM_NO_INCLUDE_EXTRA_HEADERS)
/* historically, NetworkManager.h drags in the following system headers.
* These are not strictly necessary and the user may wish to opt out from
* including them. */
#include <linux/if_ether.h>
#include <linux/if_infiniband.h>
#include <linux/if_vlan.h>
#include <netinet/in.h>
#endif
#undef __NETWORKMANAGER_H_INSIDE__
#endif /* __NETWORKMANAGER_H__ */