forked from Parallel-NetCDF/PnetCDF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aclocal_coverage.m4
91 lines (84 loc) · 3.69 KB
/
aclocal_coverage.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
dnl Macro to add --enable-coverage option (disabled by default) and add
dnl appropriate compiler flags to permit usage of gcov if that option is
dnl enabled. If WRAPPER_xFLAGS variables are set then the flags will also be
dnl added to those variables.
dnl
dnl Sets "pac_cv_use_coverage=yes" and AC_DEFINEs USE_COVERAGE if coverage was
dnl successfully enabled. Also creates an AM_CONDITIONAL with the name
dnl "BUILD_COVERAGE" that is true iff pac_cv_use_coverage=yes.
dnl
dnl Usage: PAC_CONFIG_SUBDIR_ARGS
dnl
dnl Assumes that all of the compiler macros have already been invoked
dnl (AC_PROG_CC and friends).
AC_DEFUN([PAC_ENABLE_COVERAGE],[
AC_ARG_VAR([GCOV],[name/path for the gcov utility])
AC_CHECK_PROGS([GCOV],[gcov])
AC_ARG_ENABLE([coverage],
[AS_HELP_STRING([--enable-coverage],
[Turn on coverage analysis using gcc and gcov])],
[],[enable_coverage=no])
if test "$enable_coverage" = "yes" ; then
# In AC_PROG_CC, if using the GNU C compiler, set shell variable GCC to yes.
if test "$GCC" = "yes" ; then
CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
LIBS="$LIBS -lgcov"
if test "x${WRAPPER_CFLAGS}" = "x" ; then
WRAPPER_CFLAGS="$WRAPPER_CFLAGS -fprofile-arcs -ftest-coverage"
fi
else
AC_MSG_WARN([--enable-coverage only supported for GCC])
fi
if test "$enable_cxx" = "yes" ; then
if test "$ac_cv_cxx_compiler_gnu" = "yes" ; then
CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage"
LIBS="$LIBS -lgcov"
if test "x${WRAPPER_CXXFLAGS}" = "x" ; then
WRAPPER_CXXFLAGS="$WRAPPER_CXXFLAGS -fprofile-arcs -ftest-coverage"
fi
else
AC_MSG_WARN([--enable-coverage only supported for GCC])
fi
fi
# Add similar options for g77 so that the Fortran tests will also
#
if test "$enable_f77" = yes ; then
if test "$ac_cv_f77_compiler_gnu" = "yes" ; then
FFLAGS="$FFLAGS -fprofile-arcs -ftest-coverage"
LIBS="$LIBS -lgcov"
if test "x${WRAPPER_FFLAGS}" = "x" ; then
WRAPPER_FFLAGS="$WRAPPER_FFLAGS -fprofile-arcs -ftest-coverage"
fi
else
AC_MSG_WARN([--enable-coverage only supported for G77/GFORTRAN])
fi
fi
if test "$enable_fc" = yes ; then
if test "$ac_cv_fc_compiler_gnu" = "yes" ; then
FCFLAGS="$FCFLAGS -fprofile-arcs -ftest-coverage"
LIBS="$LIBS -lgcov"
if test "x${WRAPPER_FCFLAGS}" = "x" ; then
WRAPPER_FCFLAGS="$WRAPPER_FCFLAGS -fprofile-arcs -ftest-coverage"
fi
else
AC_MSG_WARN([--enable-coverage only supported for GFORTRAN])
fi
fi
# On some platforms (e.g., Mac Darwin), we must also *link*
# with the -fprofile-args -ftest-coverage option.
AC_MSG_CHECKING([whether compilation with coverage analysis enabled works])
AC_LINK_IFELSE([AC_LANG_SOURCE([int main(int argc, char **argv){return 1;}])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([Unable to link programs when coverage analysis enabled])])
# Test for the routines that we need to use to ensure that the
# data files are (usually) written out
# FIXME: Some versions of Linux provide usleep, but it rounds times
# up to the next second (!)
AC_CHECK_FUNCS([usleep])
# NOTE: using a "pac_cv_" prefix but not caching because of xFLAGS "side effects"
pac_cv_use_coverage=yes
AC_DEFINE([USE_COVERAGE],[1],[Define if performing coverage tests])
fi
AM_CONDITIONAL([BUILD_COVERAGE],[test "X$pac_cv_use_coverage" = "Xyes"])
])