Skip to content

Commit

Permalink
build: test compiling all public headers with C++ compiler
Browse files Browse the repository at this point in the history
While libnl3 is a C library (and itself can only be built using a C
compiler), the public headers are supposed to also work with C++.

Add a test for that.

Unfortunately, this test does not cover whether all symbols are
correctly marked as "extern "C"" for linkage.
  • Loading branch information
thom311 committed May 6, 2024
1 parent b7d05e5 commit aba991a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,31 @@ check_local += check-local-build-headers

###############################################################################

if HAS_CXX
%.build-headers-test-cxx.c: %
mkdir -p "$(dir $@)"
printf "#include <cstdio>\n#include <$$(echo "$<" | sed 's|.*\<include/netlink/|netlink/|')>\nint main(void) { return 0; }" > $@

%.build-headers-test-cxx.o: %.build-headers-test-cxx.c
$(CXX) \
-Wall \
-Werror \
-I$(srcdir)/include \
-I$(builddir)/include \
-D_NL_NO_WARN_DEPRECATED_HEADER \
-c \
-o $@ $<

BUILD_HEADERS_OBJS_CXX = $(patsubst %,%.build-headers-test-cxx.o,$(public_headers))
check-local-build-headers-cxx: $(BUILD_HEADERS_OBJS_CXX)
else
check-local-build-headers-cxx:
endif

check_local += check-local-build-headers-cxx

###############################################################################

check-local: $(check_local)

.PHONY: $(check_local)
Expand Down
16 changes: 16 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ AC_SUBST(LT_AGE)

AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_INSTALL
LT_INIT
AC_PROG_MKDIR_P
Expand All @@ -72,6 +73,15 @@ AC_CHECK_PROGS(YACC, 'bison -y')
AC_C_CONST
AC_C_INLINE

AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[#ifndef __cplusplus
#error "broken C++"
#endif]])],,
[CXX=;])
AC_LANG_POP([C++])
AM_CONDITIONAL([HAS_CXX], [test "x$CXX" != x])

PKG_CHECK_MODULES([CHECK], [check >= 0.9.0],
[has_check="yes"],
[AC_MSG_WARN([*** Disabling building of unit tests])
Expand Down Expand Up @@ -155,6 +165,11 @@ fi

AC_OUTPUT

CXX_MSG="none"
if test "x$CXX" != x ; then
CXX_MSG="[$CXX]"
fi

echo
echo "libnl $LIBNL_VERSION configuration${LIBNL_GIT_SHA:+ (git:$LIBNL_GIT_SHA)}:"
echo " --enable-pthreads=$enable_pthreads"
Expand All @@ -164,4 +179,5 @@ echo " --enable-debug=$enable_debug"
echo " --enable-cli=$enable_cli"
echo
echo " check: $has_check"
echo " CXX: $CXX_MSG (only used for tests)"
echo

0 comments on commit aba991a

Please sign in to comment.