diff options
author | Thomas Haller <thaller@redhat.com> | 2024-05-06 08:39:30 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2024-05-06 09:36:57 (GMT) |
commit | 18b74e08383b40f116902a2b9ebb93c8599a923f (patch) | |
tree | cce302c69678348008c2329289622bc16079421e | |
parent | 691202bf0f8766e892c76b4ffd4042bbacf574aa (diff) | |
download | libnl-18b74e08383b40f116902a2b9ebb93c8599a923f.zip libnl-18b74e08383b40f116902a2b9ebb93c8599a923f.tar.gz libnl-18b74e08383b40f116902a2b9ebb93c8599a923f.tar.bz2 |
tests: test compiling all public headers with C++ compiler
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.
-rw-r--r-- | Makefile.am | 19 | ||||
-rw-r--r-- | configure.ac | 16 |
2 files changed, 35 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index 3d8d41a..496a640 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1153,6 +1153,25 @@ 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 %.build-headers-test.o + $(CXX) -Wall -Werror -D_NL_NO_WARN_DEPRECATED_HEADER -I$(srcdir)/include -I$(builddir)/include -c -o $@ $< + +BUILD_HEADERS_OBJS_CXX = $(patsubst %,%.build-headers-test-cxx.o,$(public_headers)) + +CLEANFILES += $(BUILD_HEADERS_OBJS_CXX) + +check-local-build-headers-cxx: $(BUILD_HEADERS_OBJS_CXX) + +check_local += check-local-build-headers-cxx +endif + +############################################################################### + check-local: $(check_local) .PHONY: $(check_local) diff --git a/configure.ac b/configure.ac index cce0ad0..f61a73a 100644 --- a/configure.ac +++ b/configure.ac @@ -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 @@ -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]) @@ -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" @@ -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 |