2019-11-19 02:26:16 +08:00
|
|
|
AC_DEFUN([AX_ISC_GTEST], [
|
|
|
|
|
|
|
|
enable_gtest="no"
|
|
|
|
GTEST_INCLUDES=
|
|
|
|
|
|
|
|
AC_ARG_WITH([gtest-source],
|
2022-01-10 16:04:56 +01:00
|
|
|
[AS_HELP_STRING([--with-gtest-source[[=PATH]]],
|
2019-11-19 02:26:16 +08:00
|
|
|
[location of the Googletest source])],
|
|
|
|
[enable_gtest="yes" ; GTEST_SOURCE="$withval"])
|
|
|
|
|
|
|
|
AC_ARG_WITH([gtest],
|
2022-01-10 16:04:56 +01:00
|
|
|
[AS_HELP_STRING([--with-gtest[[=PATH]]],
|
2019-11-19 02:26:16 +08:00
|
|
|
[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],
|
2022-01-10 16:04:56 +01:00
|
|
|
[AS_HELP_STRING([--with-lcov[[=PROGRAM]]],
|
2019-11-19 02:26:16 +08:00
|
|
|
[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
|
|
|
|
|
2023-09-29 15:16:18 +02:00
|
|
|
AC_MSG_CHECKING([for gtest source])
|
|
|
|
|
2019-11-19 02:26:16 +08:00
|
|
|
if test "x$GTEST_SOURCE" = "xyes" ; then
|
|
|
|
|
|
|
|
# If not specified, try some common paths.
|
|
|
|
GTEST_SOURCE=
|
2023-09-29 15:16:18 +02:00
|
|
|
for d in /usr/src/googletest /usr/src/gtest /usr/local /usr/pkg /opt /opt/local ; do
|
2023-10-03 17:57:35 +02:00
|
|
|
cmakelists="$d/CMakeLists.txt"
|
2023-10-04 16:55:31 +02:00
|
|
|
if test ! -d "$d/src" -a -d "$d/googletest"; then
|
|
|
|
d="$d/googletest"
|
2023-09-29 15:16:18 +02:00
|
|
|
fi
|
2023-10-04 16:55:31 +02:00
|
|
|
if test -f "$d/src/gtest-all.cc" -a -f "$d/src/gtest_main.cc"; then
|
|
|
|
GTEST_SOURCE="$d"
|
2019-11-19 02:26:16 +08:00
|
|
|
AC_MSG_RESULT([$GTEST_SOURCE])
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2023-10-04 16:55:31 +02:00
|
|
|
if test -z "$GTEST_SOURCE" ; then
|
2023-09-29 15:16:18 +02:00
|
|
|
AC_MSG_ERROR([no gtest sources found])
|
2019-11-19 02:26:16 +08:00
|
|
|
fi
|
|
|
|
else
|
2024-02-20 15:52:53 +01:00
|
|
|
# Trim trailing slashes.
|
|
|
|
GTEST_SOURCE=$(echo "$GTEST_SOURCE" | ${SED} 's:/*$::')
|
2023-10-03 17:57:35 +02:00
|
|
|
cmakelists="$GTEST_SOURCE/CMakeLists.txt"
|
2023-10-04 16:55:31 +02:00
|
|
|
if test ! -d "$GTEST_SOURCE/src" -a -d "$GTEST_SOURCE/googletest"; then
|
|
|
|
GTEST_SOURCE="$GTEST_SOURCE/googletest"
|
2019-11-19 02:26:16 +08:00
|
|
|
fi
|
2023-10-04 16:55:31 +02:00
|
|
|
if test -f "$GTEST_SOURCE/src/gtest-all.cc" -a -f "$GTEST_SOURCE/src/gtest_main.cc"; then
|
2023-09-29 15:16:18 +02:00
|
|
|
AC_MSG_RESULT([$GTEST_SOURCE])
|
2020-07-06 09:47:47 +02:00
|
|
|
else
|
|
|
|
AC_MSG_ERROR([no gtest source at $GTEST_SOURCE])
|
|
|
|
fi
|
2019-11-19 02:26:16 +08:00
|
|
|
fi
|
|
|
|
have_gtest_source=yes
|
2019-11-20 03:57:18 +08:00
|
|
|
|
2019-11-19 02:26:16 +08:00
|
|
|
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"
|
2023-10-03 18:24:31 +02:00
|
|
|
gtest_src_basename="$(basename $GTEST_SOURCE)"
|
2019-11-20 03:57:18 +08:00
|
|
|
|
2023-09-22 21:07:33 +02:00
|
|
|
# Versions starting from 1.8.0 are put in the googletest directory. If the basename
|
2023-09-29 15:16:18 +02:00
|
|
|
# returns googletest string, we need to cut it off and try basename again.
|
2023-10-03 18:24:31 +02:00
|
|
|
if test "$gtest_src_basename" = "googletest"; then
|
|
|
|
gtest_src_parent_dir=${GTEST_SOURCE%"/googletest"}
|
|
|
|
if test -f "$gtest_src_parent_dir/CMakeLists.txt" ; then
|
|
|
|
cmakelists="$gtest_src_parent_dir/CMakeLists.txt"
|
2023-10-03 17:57:35 +02:00
|
|
|
fi
|
2023-10-03 18:24:31 +02:00
|
|
|
gtest_src_basename=$(basename "$gtest_src_parent_dir")
|
2019-11-20 03:57:18 +08:00
|
|
|
fi
|
2023-10-03 18:24:31 +02:00
|
|
|
gtest_src_basename="${gtest_src_basename#googletest-release-}"
|
|
|
|
gtest_src_basename="${gtest_src_basename#gtest-}"
|
|
|
|
gtest_src_basename="${gtest_src_basename#googletest-}"
|
2023-09-22 21:07:33 +02:00
|
|
|
|
2023-10-04 09:39:26 +02:00
|
|
|
gtest_version_candidate=$(echo "$gtest_src_basename" | grep -Eo '[[0-9]+\.[0-9]+\.[0-9]+]')
|
2023-09-25 17:23:53 +02:00
|
|
|
|
|
|
|
if test -z "$gtest_version_candidate" ; then
|
2023-09-27 13:27:27 +02:00
|
|
|
# If the GTEST_VERSION is still not correct semver, we need to determine googletest version in other way.
|
|
|
|
# Let's try to extract it from CMake build script used by Google Test starting from version 1.8.0.
|
2023-09-25 17:23:53 +02:00
|
|
|
if test -f "$cmakelists" ; then
|
2023-10-04 16:55:31 +02:00
|
|
|
gtest_version_candidate=$(grep -F 'set(GOOGLETEST_VERSION' "$cmakelists" | grep -Eo '[[0-9]+\.[0-9]+\.[0-9]+]')
|
2023-09-25 17:23:53 +02:00
|
|
|
if test -n "$gtest_version_candidate"; then
|
2023-10-04 16:55:31 +02:00
|
|
|
GTEST_VERSION="$gtest_version_candidate"
|
2023-09-25 17:23:53 +02:00
|
|
|
fi
|
2023-09-26 15:56:27 +02:00
|
|
|
fi
|
2023-10-04 16:55:31 +02:00
|
|
|
if test "$GTEST_VERSION" = "unknown" ; then
|
2023-09-26 15:12:09 +02:00
|
|
|
# Try to get googletest version from debian/ubuntu package
|
2023-09-29 15:16:18 +02:00
|
|
|
AC_PATH_PROG(DPKG, dpkg)
|
|
|
|
AC_PATH_PROG(DPKGQUERY, dpkg-query)
|
|
|
|
if test -n "${DPKG}" -a -n "${DPKGQUERY}"; then
|
|
|
|
# Let's check if there is a googletest package owning files under given GTEST_SOURCE path
|
|
|
|
${DPKG} -S "$GTEST_SOURCE" 2>/dev/null | grep googletest >/dev/null 2>&1
|
2023-09-26 15:12:09 +02:00
|
|
|
if test $? -eq 0; then
|
2023-09-29 15:16:18 +02:00
|
|
|
GTEST_VERSION="$(${DPKGQUERY} --showformat='${Version}' --show googletest | cut -d'-' -f1)"
|
2023-09-26 15:12:09 +02:00
|
|
|
fi
|
|
|
|
fi
|
2023-09-25 17:23:53 +02:00
|
|
|
fi
|
2023-09-22 21:07:33 +02:00
|
|
|
else
|
2023-10-04 16:55:31 +02:00
|
|
|
GTEST_VERSION="$gtest_version_candidate"
|
2023-09-25 17:23:53 +02:00
|
|
|
fi
|
2019-11-19 02:26:16 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test "$gtest_path" != "no" ; then
|
|
|
|
if test "$gtest_path" != "yes"; then
|
|
|
|
GTEST_PATHS=$gtest_path
|
2023-09-29 15:16:18 +02:00
|
|
|
AC_PATH_PROG([GTEST_CONFIG], [gtest-config], [], [${gtest_path}/bin])
|
2019-11-19 02:26:16 +08:00
|
|
|
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
|
|
|
|
if test -z "${GTEST_PATHS}" ; then
|
|
|
|
GTEST_PATHS="/usr /usr/local"
|
|
|
|
fi
|
|
|
|
GTEST_FOUND="false"
|
|
|
|
fi
|
|
|
|
if test "${GTEST_FOUND}" != "true"; then
|
2023-09-29 15:16:18 +02:00
|
|
|
AC_MSG_CHECKING([for gtest lib path])
|
2019-11-19 02:26:16 +08:00
|
|
|
GTEST_FOUND="false"
|
|
|
|
for dir in $GTEST_PATHS; do
|
|
|
|
if test -f "$dir/include/gtest/gtest.h"; then
|
2020-10-05 12:04:09 +03:00
|
|
|
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"
|
2023-09-29 15:16:18 +02:00
|
|
|
AC_MSG_RESULT([$dir/lib])
|
2023-09-26 12:13:20 +02:00
|
|
|
if test -f "$dir/lib/pkgconfig/gtest.pc" ; then
|
2023-09-29 15:16:18 +02:00
|
|
|
AX_FIND_LIBRARY([gtest], ["$dir/lib/pkgconfig/gtest.pc"])
|
|
|
|
if "${LIBRARY_FOUND}"; then
|
|
|
|
GTEST_VERSION="${LIBRARY_VERSION}"
|
2023-09-26 12:13:20 +02:00
|
|
|
fi
|
|
|
|
fi
|
2020-10-05 12:04:09 +03:00
|
|
|
break
|
2023-09-26 15:12:09 +02:00
|
|
|
elif test -f "$dir/lib/$dumpmachine/libgtest.a" || \
|
|
|
|
test -f "$dir/lib/$dumpmachine/libgtest.so"; then
|
|
|
|
GTEST_INCLUDES="-I$dir/include"
|
|
|
|
# check also multiarch dir in debian/ubuntu distributions
|
|
|
|
GTEST_LDFLAGS="-L$dir/lib/$dumpmachine"
|
|
|
|
GTEST_LDADD="-lgtest"
|
|
|
|
GTEST_FOUND="true"
|
2023-09-29 15:16:18 +02:00
|
|
|
AC_MSG_RESULT([$dir/lib/$dumpmachine])
|
2023-09-26 15:12:09 +02:00
|
|
|
if test -f "$dir/lib/$dumpmachine/pkgconfig/gtest.pc" ; then
|
2023-09-29 15:16:18 +02:00
|
|
|
AX_FIND_LIBRARY([gtest], ["$dir/lib/$dumpmachine/pkgconfig/gtest.pc"])
|
|
|
|
if "${LIBRARY_FOUND}"; then
|
|
|
|
GTEST_VERSION="${LIBRARY_VERSION}"
|
2023-09-26 15:12:09 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
break
|
2020-10-05 12:04:09 +03:00
|
|
|
else
|
2019-11-19 02:26:16 +08:00
|
|
|
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)
|
|
|
|
|
2024-08-13 13:45:25 +03:00
|
|
|
])
|