# Checks whether the gtest library is available on the system
# Allows for adjusting the include and library path.
# Sets have_gtest=yes if the library is present and
# reports the compiler and linker flags in 
# GTEST_CXXFLAGS AND GTEST_LDFLAGS, respectively.
AC_DEFUN([AC_CHECK_GTEST],
[
  AC_ARG_WITH([gtest-include-path],
  [AS_HELP_STRING([--with-gtest-include-path],
    [location of the Google test headers, defaults to /usr/include])],
  [GTEST_CXXFLAGS="-I$withval"],
  [GTEST_CXXFLAGS='-I/usr/include'])

  AC_ARG_WITH([gtest-lib-path],
  [AS_HELP_STRING([--with-gtest-lib-path], [location of the Google test libraries])],
  [GTEST_LDFLAGS="-L$withval -lpthread"],
  [GTEST_LDFLAGS='-lgtest -lpthread'])

  AC_LANG_CPLUSPLUS

  # We need to get to the 5th arg to link with -lpthread too. Mimic the default
  # AC_CHECK_LIB action when found.
  AC_CHECK_LIB([gtest], [main],
               [AC_DEFINE(HAVE_LIBGTEST) LIBS="-lgtest $LIBS"],
               [],
               [-lpthread])
]) # AC_CHECK_GTEST


# Checks whether the gtest library is available on the system
# Allows for adjusting the include and library path.
# Sets have_gtest=yes if the library is present and
# reports the compiler and linker flags in 
# GTEST_CXXFLAGS AND GTEST_LDFLAGS, respectively.
AC_DEFUN([AC_CHECK_GTEST],
[
  AC_ARG_WITH([gtest-include-path],
  [AS_HELP_STRING([--with-gtest-include-path],
    [location of the Google test headers, defaults to /usr/include])],
  [GTEST_CXXFLAGS="-I$withval"],
  [GTEST_CXXFLAGS='-I/usr/include'])

  AC_ARG_WITH([gtest-lib-path],
  [AS_HELP_STRING([--with-gtest-lib-path], [location of the Google test libraries])],
  [GTEST_LDFLAGS="-L$withval -lpthread"],
  [GTEST_LDFLAGS='-lgtest -lpthread'])

  AC_LANG_PUSH(C++)

  # We need to get to the 5th arg to link with -lpthread too. Mimic the default
  # AC_CHECK_LIB action when found.
  AC_CHECK_LIB([gtest], [main],
               [AC_DEFINE(HAVE_LIBGTEST) LIBS="-lgtest $LIBS"],
               [],
               [-lpthread])

  AC_LANG_POP
]) # AC_CHECK_GTEST


Use AC_LANG_PUSH(C++)/AC_LANG_POP so as not to contaminate configure.ac
Use AC_LANG_PUSH(C++)/AC_LANG_POP so as not to contaminate configure.ac
