diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-05-29 22:46:07 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-05-30 11:48:28 +0200 |
| commit | 29051766975d471c4eff9f7b3137752234cf1a4c (patch) | |
| tree | 1eeee2a54ffeff13d0e8ed78951cd2a12a830a6e /configure.ac | |
| parent | f773897a3025438326c1131e1586d9ddae080c4f (diff) | |
| download | PROJ-29051766975d471c4eff9f7b3137752234cf1a4c.tar.gz PROJ-29051766975d471c4eff9f7b3137752234cf1a4c.zip | |
Enable c++ compilation with autotools and cmake, hardened compilation flags and add catch2 framework
Hardened compilation flags come from GDAL' configure.ac and are
'combat proven'
Dummy test added just to demonstrate catch2 based tests work.
Diffstat (limited to 'configure.ac')
| -rw-r--r-- | configure.ac | 131 |
1 files changed, 126 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac index 495fb037..b09d3d87 100644 --- a/configure.ac +++ b/configure.ac @@ -10,17 +10,138 @@ AC_CONFIG_AUX_DIR([.]) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(src/proj_config.h) -dnl Enable as much warnings as possible -AX_CFLAGS_WARN_ALL(C_WFLAGS) -AC_SUBST(C_WFLAGS,$C_WFLAGS) - dnl Checks for programs. AC_PROG_CC +AC_PROG_CXX +AX_CXX_COMPILE_STDCXX_11([noext],[mandatory]) AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET AM_PROG_LIBTOOL +dnl Enable as much warnings as possible +AX_CFLAGS_WARN_ALL(C_WFLAGS) +AX_CXXFLAGS_WARN_ALL(CXX_WFLAGS) + + +dnl For ICC: it needs -we10006 instead of -Werror to turn unknown options to errors +dnl Some gcc/clang versions might succeed on this test, so also include -Werror in ERROR_ON_UNKNOWN_OPTIONS +AX_CHECK_COMPILE_FLAG([-Werror -we10006],[ERROR_ON_UNKNOWN_OPTIONS="-Werror -we10006"],[ERROR_ON_UNKNOWN_OPTIONS="-Werror"]) + +dnl A few ICC warnings to turn off +dnl warning #188: enumerated type mixed with another type (needed on libcsf) +dnl warning #1684: conversion from pointer to same-sized integral type (potential portability problem) (needed on frmts/mrf) +dnl warning #2259: non-pointer conversion from "size_t={unsigned long}" to "int" may lose significant bits +dnl warning #2304: non-explicit constructor with single argument may cause implicit type conversion +dnl warning #3280: declaration hides member +dnl remark #11074: Inlining inhibited by limit max-size +dnl remark #11076: To get full report use -qopt-report=4 -qopt-report-phase ipo +AX_CHECK_COMPILE_FLAG([-diag-disable 188,1684,2259,2304,3280,11074,11076],[C_WFLAGS="$C_WFLAGS -diag-disable 188,1684,2259,2304,3280,11074,11076" CXX_WFLAGS="$CXX_WFLAGS -diag-disable 188,1684,2259,2304,3280,11074,11076"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +AX_CHECK_COMPILE_FLAG([-Wextra],[C_WFLAGS="$C_WFLAGS -Wextra" CXX_WFLAGS="$CXX_WFLAGS -Wextra"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Winit-self],[C_WFLAGS="$C_WFLAGS -Winit-self" CXX_WFLAGS="$CXX_WFLAGS -Winit-self"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wunused-parameter], [C_WFLAGS="$C_WFLAGS -Wunused-parameter" CXX_WFLAGS="$CXX_WFLAGS -Wunused-parameter" NO_UNUSED_PARAMETER_FLAG="-Wno-unused-parameter"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wmissing-prototypes], [C_WFLAGS="$C_WFLAGS -Wmissing-prototypes"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wmissing-declarations], [C_WFLAGS="$C_WFLAGS -Wmissing-declarations"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wformat], [C_WFLAGS="$C_WFLAGS -Wformat" CXX_WFLAGS="$CXX_WFLAGS -Wformat"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wformat -Werror=format-security -Wno-format-nonliteral], [C_WFLAGS="$C_WFLAGS -Werror=format-security -Wno-format-nonliteral" CXX_WFLAGS="$CXX_WFLAGS -Werror=format-security -Wno-format-nonliteral"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wshorten-64-to-32], [C_WFLAGS="$C_WFLAGS -Wshorten-64-to-32" CXX_WFLAGS="$CXX_WFLAGS -Wshorten-64-to-32"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wlogical-op], [C_WFLAGS="$C_WFLAGS -Wlogical-op" CXX_WFLAGS="$CXX_WFLAGS -Wlogical-op" NO_LOGICAL_OP_FLAG="-Wno-logical-op"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wshadow], [C_WFLAGS="$C_WFLAGS -Wshadow" CXX_WFLAGS="$CXX_WFLAGS -Wshadow"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl Error out on things that will fail with MSVC +AX_CHECK_COMPILE_FLAG([-Werror=vla], [C_WFLAGS="$C_WFLAGS -Werror=vla" CXX_WFLAGS="$CXX_WFLAGS -Werror=vla"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Werror=declaration-after-statement], [C_WFLAGS="$C_WFLAGS -Wdeclaration-after-statement"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl -Wclobbered is not reliable on most gcc versions +dnl AX_CHECK_COMPILE_FLAG([-Wno-clobbered], [C_WFLAGS="$C_WFLAGS -Wno-clobbered" CXX_WFLAGS="$CXX_WFLAGS -Wno-clobbered"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl Warn when macros __TIME__, __DATE__ or __TIMESTAMP__ are encountered as they might prevent bit-wise-identical reproducible compilations. +AX_CHECK_COMPILE_FLAG([-Wdate-time], [C_WFLAGS="$C_WFLAGS -Wdate-time" CXX_WFLAGS="$CXX_WFLAGS -Wdate-time"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl GCC 6 warnings +AX_CHECK_COMPILE_FLAG([-Wnull-dereference], [C_WFLAGS="$C_WFLAGS -Wnull-dereference" CXX_WFLAGS="$CXX_WFLAGS -Wnull-dereference"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wduplicated-cond], [C_WFLAGS="$C_WFLAGS -Wduplicated-cond" CXX_WFLAGS="$CXX_WFLAGS -Wduplicated-cond"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl GCC 7 warnings +dnl Do not enable yet. Causes warning in alg/gdalthinplate.cpp due to armadillo templates +dnl AX_CHECK_COMPILE_FLAG([-Wduplicated-branches], [C_WFLAGS="$C_WFLAGS -Wduplicated-branches" CXX_WFLAGS="$CXX_WFLAGS -Wduplicated-branches"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl GCC 8 warnings +AC_LANG_PUSH([C++]) +AX_CHECK_COMPILE_FLAG([-Wextra-semi], [CXX_WFLAGS="$CXX_WFLAGS -Wextra-semi"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AC_LANG_POP([C++]) + +AX_CHECK_COMPILE_FLAG([-Wno-sign-compare], [NO_SIGN_COMPARE="-Wno-sign-compare"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl clang >= 3.9 +AX_CHECK_COMPILE_FLAG([-Wcomma], [C_WFLAGS="$C_WFLAGS -Wcomma" CXX_WFLAGS="$CXX_WFLAGS -Wcomma"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl clang and gcc 5 +AX_CHECK_COMPILE_FLAG([-Wfloat-conversion], [C_WFLAGS="$C_WFLAGS -Wfloat-conversion" CXX_WFLAGS="$CXX_WFLAGS -Wfloat-conversion"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl clang >= 3.2 +AX_CHECK_COMPILE_FLAG([-Wdocumentation -Wno-documentation-deprecated-sync], [C_WFLAGS="$C_WFLAGS -Wdocumentation -Wno-documentation-deprecated-sync" CXX_WFLAGS="$CXX_WFLAGS -Wdocumentation -Wno-documentation-deprecated-sync"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl gnu89 is a reasonable target to get MSVC compatibility. +dnl but only apply it with gcc, since clang will throw a lot of warnings +SAVED_CFLAGS=$CFLAGS +CFLAGS="$CFLAGS $ERROR_ON_UNKNOWN_OPTIONS -std=gnu89" +AC_MSG_CHECKING([if -std=gnu89 can be enabled]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM( + [[#if defined(__clang__) || !defined(__GNUC__) + #error "not gcc" + #endif]])], + [C_WFLAGS="$C_WFLAGS -std=gnu89"] + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no])]) +CFLAGS=$SAVED_CFLAGS + +dnl C++ specific stuff + +AC_LANG_PUSH([C++]) +AX_CHECK_COMPILE_FLAG([-Wunused-private-field], [CXX_WFLAGS="$CXX_WFLAGS -Wunused-private-field"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wmissing-prototypes], [CXX_WFLAGS="$CXX_WFLAGS -Wmissing-prototypes"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wmissing-declarations], [CXX_WFLAGS="$CXX_WFLAGS -Wmissing-declarations"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wnon-virtual-dtor], [CXX_WFLAGS="$CXX_WFLAGS -Wnon-virtual-dtor" NO_NON_VIRTUAL_DTOR_FLAG="-Wno-non-virtual-dtor"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Wold-style-cast], [WARN_OLD_STYLE_CAST="-Wold-style-cast"],,[$ERROR_ON_UNKNOWN_OPTIONS]) +AX_CHECK_COMPILE_FLAG([-Weffc++], [WARN_EFFCPLUSPLUS="-Weffc++"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl g++-4.8 complain a bit too much with -Weffc++ +if test "$WARN_EFFCPLUSPLUS" != ""; then + SAVED_CXXFLAGS=$CXXFLAGS + CXXFLAGS="$CXXFLAGS $WARN_EFFCPLUSPLUS -Werror" + AC_MSG_CHECKING([if -Weffc++ should be enabled]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM( + [[ + class Base {}; + class A: public Base {}; + ]])], + [AC_MSG_RESULT([yes])], + [WARN_EFFCPLUSPLUS=""] + [AC_MSG_RESULT([no])]) + CXXFLAGS="$SAVED_CXXFLAGS $WARN_EFFCPLUSPLUS" +fi + +dnl Clang enables -Woverloaded-virtual if -Wall is defined, but not GCC +AX_CHECK_COMPILE_FLAG([-Woverloaded-virtual], [CXX_WFLAGS="$CXX_WFLAGS -Woverloaded-virtual"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +dnl Forbid use of 'or', 'and', ... alias operators +AX_CHECK_COMPILE_FLAG([-fno-operator-names], [CXX_WFLAGS="$CXX_WFLAGS -fno-operator-names"],,[$ERROR_ON_UNKNOWN_OPTIONS]) + +HAVE_GCC_WARNING_ZERO_AS_NULL_POINTER_CONSTANT=no +AX_CHECK_COMPILE_FLAG([-Wzero-as-null-pointer-constant], [CXX_WFLAGS="$CXX_WFLAGS -Wzero-as-null-pointer-constant" HAVE_GCC_WARNING_ZERO_AS_NULL_POINTER_CONSTANT=yes],,[$ERROR_ON_UNKNOWN_OPTIONS]) +if test "$HAVE_GCC_WARNING_ZERO_AS_NULL_POINTER_CONSTANT" = "yes"; then +AC_DEFINE_UNQUOTED(HAVE_GCC_WARNING_ZERO_AS_NULL_POINTER_CONSTANT, 1, + [Define to 1 if the compiler supports -Wzero-as-null-pointer-constant]) +fi + +AC_LANG_POP([C++]) + +AC_SUBST(C_WFLAGS,$C_WFLAGS) +AC_SUBST(CXX_WFLAGS,$CXX_WFLAGS) + + dnl Checks for libraries. save_CFLAGS="$CFLAGS" CFLAGS=`echo "$CFLAGS" | sed "s/-Werror/ /"` @@ -142,7 +263,7 @@ AC_SUBST(MUTEX_SETTING,$MUTEX_SETTING) AC_SUBST(THREAD_LIB,$THREAD_LIB) AC_CONFIG_FILES([Makefile cmake/Makefile src/Makefile - test/Makefile test/gie/Makefile test/gigs/Makefile + test/Makefile test/gie/Makefile test/gigs/Makefile test/cpp/Makefile man/Makefile man/man1/Makefile man/man3/Makefile nad/Makefile jniwrap/Makefile jniwrap/org.osgeo.proj/Makefile jniwrap/org.osgeo.proj/org/Makefile jniwrap/org.osgeo.proj/org/proj4/Makefile]) AC_CONFIG_FILES([nad/install], [chmod +x nad/install]) |
