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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
AC_DEFUN([AX_ISC_GTEST], [
enable_gtest="no"
GTEST_INCLUDES=
AC_ARG_WITH([gtest-source],
[AS_HELP_STRING([--with-gtest-source[[=PATH]]],
[location of the Googletest source])],
[enable_gtest="yes" ; GTEST_SOURCE="$withval"])
AC_ARG_WITH([gtest],
[AS_HELP_STRING([--with-gtest[[=PATH]]],
[specify a path to gtest header files (PATH/include) and library (PATH/lib)])],
[gtest_path="$withval"; enable_gtest="yes"], [gtest_path="no"])
AC_ARG_WITH([lcov],
[AS_HELP_STRING([--with-lcov[[=PROGRAM]]],
[enable gtest and coverage target using the specified lcov])],
[lcov="$withval"],
[lcov="no"])
USE_LCOV="no"
if test "$lcov" != "no"; then
# force gtest if not set
if test "$enable_gtest" = "no"; then
# AC_MSG_ERROR("lcov needs gtest for test coverage report")
AC_MSG_NOTICE([gtest support is now enabled, because used by coverage tests])
enable_gtest="yes"
fi
if test "$lcov" != "yes"; then
LCOV=$lcov
else
AC_PATH_PROG([LCOV], [lcov])
fi
if test -x "${LCOV}"; then
USE_LCOV="yes"
else
AC_MSG_ERROR([Cannot find lcov.])
fi
# is genhtml always in the same directory?
GENHTML=`echo "$LCOV" | ${SED} s/lcov$/genhtml/`
if test ! -x $GENHTML; then
AC_MSG_ERROR([genhtml not found, needed for lcov])
fi
# GCC specific?
CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage"
LIBS=" $LIBS -lgcov"
AC_SUBST(CPPFLAGS)
AC_SUBST(LIBS)
AC_SUBST(LCOV)
AC_SUBST(GENHTML)
fi
AC_SUBST(USE_LCOV)
#
# Check availability of gtest, which will be used for unit tests.
#
GTEST_LDFLAGS=
GTEST_LDADD=
DISTCHECK_GTEST_CONFIGURE_FLAG=
GTEST_VERSION="unknown"
if test "x$enable_gtest" = "xyes" ; then
DISTCHECK_GTEST_CONFIGURE_FLAG="--with-gtest=$gtest_path"
if test -n "$with_gtest_source" ; then
if test "x$GTEST_SOURCE" = "xyes" ; then
AC_MSG_CHECKING([for gtest source])
# If not specified, try some common paths.
GTEST_SOURCE=
for d in /usr/src/gtest /usr/local /usr/pkg /opt /opt/local ; do
if test -f $d/src/gtest-all.cc -a $d/src/gtest_main.cc; then
GTEST_SOURCE=$d
AC_MSG_RESULT([$GTEST_SOURCE])
break
fi
done
if test -z $GTEST_SOURCE ; then
AC_MSG_ERROR([no gtest source but it was selected])
fi
else
if test ! -d $GTEST_SOURCE/src -a -d $GTEST_SOURCE/googletest; then
GTEST_SOURCE=$GTEST_SOURCE/googletest
fi
if test -f $GTEST_SOURCE/src/gtest-all.cc -a $GTEST_SOURCE/src/gtest_main.cc; then
have_gtest_source=yes
else
AC_MSG_ERROR([no gtest source at $GTEST_SOURCE])
fi
fi
have_gtest_source=yes
GTEST_LDADD="\$(top_builddir)/ext/gtest/libgtest.a"
DISTCHECK_GTEST_CONFIGURE_FLAG="--with-gtest-source=$GTEST_SOURCE"
GTEST_INCLUDES="-I$GTEST_SOURCE -I$GTEST_SOURCE/include"
GTEST_VERSION="`basename $GTEST_SOURCE`"
# Versions starting from 1.8.0 are put in the googletest directory. If the basename
# returns googletest string, we need to cut it off and try baseline again.
if test "$GTEST_VERSION" = "googletest"; then
GTEST_VERSION=${GTEST_SOURCE%"/googletest"}
GTEST_VERSION=`basename $GTEST_VERSION`
fi
GTEST_VERSION="${GTEST_VERSION#googletest-release-}"
GTEST_VERSION="${GTEST_VERSION#gtest-}"
fi
if test "$gtest_path" != "no" ; then
if test "$gtest_path" != "yes"; then
GTEST_PATHS=$gtest_path
if test -x "${gtest_path}/bin/gtest-config" ; then
GTEST_CONFIG="${gtest_path}/bin/gtest-config"
fi
else
AC_PATH_PROG([GTEST_CONFIG], [gtest-config])
fi
if test -x "${GTEST_CONFIG}" ; then :
# using cppflags instead of cxxflags
GTEST_INCLUDES=`${GTEST_CONFIG} --cppflags`
GTEST_LDFLAGS=`${GTEST_CONFIG} --ldflags`
GTEST_LDADD=`${GTEST_CONFIG} --libs`
GTEST_VERSION=`${GTEST_CONFIG} --version`
GTEST_FOUND="true"
else
AC_MSG_WARN([Unable to locate Google Test gtest-config.])
if test -z "${GTEST_PATHS}" ; then
GTEST_PATHS="/usr /usr/local"
fi
GTEST_FOUND="false"
fi
if test "${GTEST_FOUND}" != "true"; then
GTEST_FOUND="false"
for dir in $GTEST_PATHS; do
if test -f "$dir/include/gtest/gtest.h"; then
if test -f "$dir/lib/libgtest.a" || \
test -f "$dir/lib/libgtest.so"; then
GTEST_INCLUDES="-I$dir/include"
GTEST_LDFLAGS="-L$dir/lib"
GTEST_LDADD="-lgtest"
GTEST_FOUND="true"
break
else
AC_MSG_WARN([Found Google Test include but not the library in $dir.])
fi
fi
done
fi
if test "${GTEST_FOUND}" != "true"; then
AC_MSG_ERROR([Cannot find gtest in: $GTEST_PATHS])
fi
fi
fi
AM_CONDITIONAL(HAVE_GTEST, test $enable_gtest != "no")
AM_CONDITIONAL(HAVE_GTEST_SOURCE, test "X$have_gtest_source" = "Xyes")
AC_SUBST(DISTCHECK_GTEST_CONFIGURE_FLAG)
AC_SUBST(GTEST_INCLUDES)
AC_SUBST(GTEST_LDFLAGS)
AC_SUBST(GTEST_LDADD)
AC_SUBST(GTEST_SOURCE)
])dnl AX_ISC_GTEST
|