From 6f65d24796a0aaca0c20f4c074aa71e39f38e68d Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Tue, 18 Feb 2020 21:18:55 +0100 Subject: Make sure both C and C++ programs including gphoto2 headers compile Check that programs including libgphoto2 headers compile when compiled for a number of different language standards: C: ansi c99 c11 C++: ansi c++98 c++11 c++14 c++17 For each of these language standards, if the compiler does not compile an empty example program, we do not test whether compiling with the gphoto2/*.h headers included works. This will work with GCC as the compiler, and also should work with CLANG as the compiler as CLANG is mostly compatible in these matters. On other compilers, the test compile of the empty program should fail, and thus no checks with the gphoto2/*.h headers included will be performed. C90/ANSI C apparently does not define __STDC_VERSION__, so the C source code needed to be changed to become ANSI C compatible. In C++ pedantic compilation source, we now use actual C++ code instead of relying on C code working when compiled as C++ code. In Travis CI, we now actually require both C and C++. --- tests/Makefile.am | 95 +++++++++++++++++++++++++++++++++++++ tests/test-pedantic-compilation.c | 6 +++ tests/test-pedantic-compilation.cxx | 4 +- 3 files changed, 103 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index c20c0e9f8..6c3d4449c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -143,6 +143,101 @@ test_pedantic_cxx_LDADD = \ $(INTLLIBS) +######################################################################## +# Test pendantic compilation for multiple language standard +######################################################################## + +generic_pedantic_cppflags = +generic_pedantic_cppflags += -I$(top_srcdir)/libgphoto2_port +generic_pedantic_cppflags += -I$(top_srcdir) + +if GP_HAVE_PEDANTIC_FLAGS_C90 +TESTS += test-pedantic-c90 +check_PROGRAMS += test-pedantic-c90 +test_pedantic_c90_SOURCES = test-pedantic-compilation.c +test_pedantic_c90_CPPFLAGS = $(generic_pedantic_cppflags) +test_pedantic_c90_CFLAGS = $(GP_PEDANTIC_CFLAGS_C90) +test_pedantic_c90_LDADD = +test_pedantic_c90_LDFLAGS = +endif + +if GP_HAVE_PEDANTIC_FLAGS_C99 +TESTS += test-pedantic-c99 +check_PROGRAMS += test-pedantic-c99 +test_pedantic_c99_SOURCES = test-pedantic-compilation.c +test_pedantic_c99_CPPFLAGS = $(generic_pedantic_cppflags) +test_pedantic_c99_CFLAGS = $(GP_PEDANTIC_CFLAGS_C99) +test_pedantic_c99_LDADD = +test_pedantic_c99_LDFLAGS = +endif + +if GP_HAVE_PEDANTIC_FLAGS_C11 +TESTS += test-pedantic-c11 +check_PROGRAMS += test-pedantic-c11 +test_pedantic_c11_SOURCES = test-pedantic-compilation.c +test_pedantic_c11_CPPFLAGS = $(generic_pedantic_cppflags) +test_pedantic_c11_CFLAGS = $(GP_PEDANTIC_CFLAGS_C11) +test_pedantic_c11_LDADD = +test_pedantic_c11_LDFLAGS = +endif + +if GP_HAVE_PEDANTIC_FLAGS_CXX98 +if HAVE_CXX +TESTS += test-pedantic-cxx98 +check_PROGRAMS += test-pedantic-cxx98 +else +EXTRA_PROGRAMS += test-pedantic-cxx98 +endif +test_pedantic_cxx98_SOURCES = test-pedantic-compilation.cxx +test_pedantic_cxx98_CPPFLAGS = $(generic_pedantic_cppflags) +test_pedantic_cxx98_CXXFLAGS = $(GP_PEDANTIC_CXXFLAGS_CXX98) +test_pedantic_cxx98_LDADD = +test_pedantic_cxx98_LDFLAGS = +endif + +if GP_HAVE_PEDANTIC_FLAGS_CXX11 +if HAVE_CXX +TESTS += test-pedantic-cxx11 +check_PROGRAMS += test-pedantic-cxx11 +else +EXTRA_PROGRAMS += test-pedantic-cxx11 +endif +test_pedantic_cxx11_SOURCES = test-pedantic-compilation.cxx +test_pedantic_cxx11_CPPFLAGS = $(generic_pedantic_cppflags) +test_pedantic_cxx11_CXXFLAGS = $(GP_PEDANTIC_CXXFLAGS_CXX11) +test_pedantic_cxx11_LDADD = +test_pedantic_cxx11_LDFLAGS = +endif + +if GP_HAVE_PEDANTIC_FLAGS_CXX14 +if HAVE_CXX +TESTS += test-pedantic-cxx14 +check_PROGRAMS += test-pedantic-cxx14 +else +EXTRA_PROGRAMS += test-pedantic-cxx14 +endif +test_pedantic_cxx14_SOURCES = test-pedantic-compilation.cxx +test_pedantic_cxx14_CPPFLAGS = $(generic_pedantic_cppflags) +test_pedantic_cxx14_CXXFLAGS = $(GP_PEDANTIC_CXXFLAGS_CXX14) +test_pedantic_cxx14_LDADD = +test_pedantic_cxx14_LDFLAGS = +endif + +if GP_HAVE_PEDANTIC_FLAGS_CXX17 +if HAVE_CXX +TESTS += test-pedantic-cxx17 +check_PROGRAMS += test-pedantic-cxx17 +else +EXTRA_PROGRAMS += test-pedantic-cxx17 +endif +test_pedantic_cxx17_SOURCES = test-pedantic-compilation.cxx +test_pedantic_cxx17_CPPFLAGS = $(generic_pedantic_cppflags) +test_pedantic_cxx17_CXXFLAGS = $(GP_PEDANTIC_CXXFLAGS_CXX17) +test_pedantic_cxx17_LDADD = +test_pedantic_cxx17_LDFLAGS = +endif + + ######################################################################## # Implement the checks for the installed library ######################################################################## diff --git a/tests/test-pedantic-compilation.c b/tests/test-pedantic-compilation.c index 269ea080d..bb88d1a82 100644 --- a/tests/test-pedantic-compilation.c +++ b/tests/test-pedantic-compilation.c @@ -17,10 +17,16 @@ #include +#ifdef __STDC_VERSION__ unsigned long stdc_version = __STDC_VERSION__; +#endif int main() { +#ifdef __STDC_VERSION__ printf("stdc_version = %lu\n", stdc_version); +#else + printf("stdc_version = undefined\n"); +#endif return 0; } diff --git a/tests/test-pedantic-compilation.cxx b/tests/test-pedantic-compilation.cxx index 70bac2f2b..5dbe12083 100644 --- a/tests/test-pedantic-compilation.cxx +++ b/tests/test-pedantic-compilation.cxx @@ -15,12 +15,12 @@ #include #include -#include +#include unsigned long cxx_version = __cplusplus; int main() { - printf("cxx_version = %lu\n", cxx_version); + std::cout << "cxx_version = " << cxx_version << std::endl; return 0; } -- cgit v1.2.1