[ovs-dev] [PATCH 4/5] Automatically verify that OVS header files work OK in C++ also.

Ben Pfaff blp at ovn.org
Mon Jul 31 02:54:59 UTC 2017


This should help address a recurring problem.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 .travis.yml                     |  1 +
 Makefile.am                     |  1 +
 configure.ac                    |  2 ++
 include/openvswitch/automake.mk | 14 ++++++++++++++
 m4/openvswitch.m4               | 21 +++++++++++++++++++++
 5 files changed, 39 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index 9d0fd44281e8..5d708498387e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,6 +16,7 @@ addons:
       - libjemalloc1
       - libjemalloc-dev
       - python-sphinx
+      - libboost-dev
 
 before_install: ./.travis/${TRAVIS_OS_NAME}-prepare.sh
 
diff --git a/Makefile.am b/Makefile.am
index 9679379defef..373ef6e9189f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -108,6 +108,7 @@ MAN_ROOTS =
 noinst_DATA =
 noinst_HEADERS =
 lib_LTLIBRARIES =
+noinst_LTLIBRARIES =
 noinst_man_MANS =
 noinst_PROGRAMS =
 noinst_SCRIPTS =
diff --git a/configure.ac b/configure.ac
index 194c4b92ee34..093b6ffed50e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,7 @@ AM_INIT_AUTOMAKE([tar-pax])
 
 AC_PROG_CC_C99
 AM_PROG_CC_C_O
+AC_PROG_CXX
 AC_PROG_CPP
 AC_PROG_MKDIR_P
 AC_PROG_FGREP
@@ -135,6 +136,7 @@ OVS_CHECK_POSIX_AIO
 OVS_CHECK_PTHREAD_SET_NAME
 OVS_CHECK_LINUX_HOST
 OVS_LIBTOOL_VERSIONS
+OVS_CHECK_CXX
 AX_FUNC_POSIX_MEMALIGN
 
 OVS_CHECK_INCLUDE_NEXT([stdio.h string.h])
diff --git a/include/openvswitch/automake.mk b/include/openvswitch/automake.mk
index 699d9d74ecd0..74b31acfa66b 100644
--- a/include/openvswitch/automake.mk
+++ b/include/openvswitch/automake.mk
@@ -30,3 +30,17 @@ openvswitchinclude_HEADERS = \
 	include/openvswitch/version.h \
 	include/openvswitch/vconn.h \
 	include/openvswitch/vlog.h
+
+if HAVE_CXX
+# OVS does not use C++ itself, but it provides public header files
+# that a C++ compiler should accept, so when --enable-Werror is in
+# effect and a C++ compiler is available, we build a C++ source file
+# that #includes all the public headers, as a way to ensure that they
+# are acceptable as C++.
+noinst_LTLIBRARIES += include/openvswitch/libcxxtest.la
+nodist_include_openvswitch_libcxxtest_la_SOURCES = include/openvswitch/cxxtest.cc
+include/openvswitch/cxxtest.cc: include/openvswitch/automake.mk
+	$(AM_V_GEN)for header in $(openvswitchinclude_HEADERS); do	\
+	  echo $$header;						\
+	done | sed 's,^include/\(.*\)$$,#include <\1>,' > $@
+endif
diff --git a/m4/openvswitch.m4 b/m4/openvswitch.m4
index 648750ab5ad9..8a15a4a77dc2 100644
--- a/m4/openvswitch.m4
+++ b/m4/openvswitch.m4
@@ -620,3 +620,24 @@ AC_DEFUN([OVS_LIBTOOL_VERSIONS],
   AC_MSG_RESULT([libX-$OVS_MAJOR.$OVS_MINOR.so.$LT_CURRENT.0.$OVS_MICRO)])
   AC_SUBST(OVS_LTINFO)
     ])
+
+dnl OVS does not use C++ itself, but it provides public header files
+dnl that a C++ compiler should accept, so when --enable-Werror is in
+dnl effect and a C++ compiler is available, we enable building a C++
+dnl source file that #includes all the public headers, as a way to
+dnl ensure that they are acceptable as C++.
+AC_DEFUN([OVS_CHECK_CXX],
+  [AC_REQUIRE([AC_PROG_CXX])
+   AC_REQUIRE([OVS_ENABLE_WERROR])
+   if test $enable_Werror = yes; then
+     AC_LANG_PUSH([C++])
+     AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM([[#include <boost/static_assert.hpp>
+]],)],
+       [enable_cxx=:],
+       [enable_cxx=false])
+     AC_LANG_POP([C++])
+   else
+     enable_cxx=false
+   fi
+   AM_CONDITIONAL([HAVE_CXX], [$enable_cxx])])
-- 
2.10.2



More information about the dev mailing list