Permalink
Browse files

Build gtest if GTEST_ROOT is specified

As of gtest-1.6.0 there is no make install target and the
recommended way to use gtest is to build it as part of the
build process

Change-Id: I1f0ff93b86cac5be781f9a10f9f31c0e2ba703dd
Reviewed-on: http://review.couchbase.org/15945
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
1 parent 81fa70d commit c8b32227375cd3e8f272a8b5b13430dc3642fbc2 @trondn trondn committed May 12, 2012
Showing with 52 additions and 18 deletions.
  1. +11 −1 Makefile.am
  2. +32 −16 configure.ac
  3. +1 −1 m4/couchbase.m4
  4. +8 −0 tests/gtest-sources.cc
View
12 Makefile.am
@@ -36,12 +36,22 @@ endif
TESTS=${check_PROGRAMS}
+tests_cbio_unit_tests_CPPFLAGS = $(AM_CPPFLAGS)
tests_cbio_unit_tests_SOURCES = tests/cbio_unit_tests.cc \
tests/document_unit_tests.cc \
tests/strerror_unit_tests.cc \
tests/instance_unit_tests.cc
tests_cbio_unit_tests_DEPENDENCIES = libcbio.la
-tests_cbio_unit_tests_LDADD = -lgtest libcbio.la
+tests_cbio_unit_tests_LDADD = libcbio.la
+
+if HAVE_GOOGLETEST_SRC
+tests_cbio_unit_tests_SOURCES += tests/gtest-sources.cc
+tests_cbio_unit_tests_CPPFLAGS += -I$(GTEST_ROOT) -I$(GTEST_ROOT)/include
+endif
+
+if !HAVE_GOOGLETEST_SRC
+tests_cbio_unit_tests_LDADD += -lgtest
+endif
LINTFLAGS=-Iinclude -b -c -errchk=%all \
-erroff=E_INCL_NUSD,E_CAST_INT_TO_SMALL_INT,E_PTRDIFF_OVERFLOW \
View
48 configure.ac
@@ -43,25 +43,41 @@ AC_SUBST(LIBCBIO_API_CURRENT)
AC_SUBST(LIBCBIO_API_REVISION)
AC_SUBST(LIBCBIO_API_AGE)
-AC_CACHE_CHECK([for gtest], [ac_cv_have_gtest], [
- AC_LANG_PUSH([C++])
- SAVED_LIBS="$LIBS"
- LIBS="-lgtest"
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM(
- [
+AS_IF([test "x$GTEST_ROOT" != "x"], [
+ AC_CACHE_CHECK([for gtest source], [ac_cv_have_gtest_src], [
+ AS_IF([test -f "$GTEST_ROOT/src/gtest-all.cc"],
+ [ac_cv_have_gtest_src=yes],
+ [ac_cv_have_gtest_src=no]) ])
+], [
+ ac_cv_have_gtest_src=no
+ GTEST_ROOT=.
+])
+
+AC_SUBST(GTEST_ROOT)
+AS_IF([test "x$ac_cv_have_gtest_src" = "xno"], [
+ AC_CACHE_CHECK([for gtest], [ac_cv_have_gtest], [
+ AC_LANG_PUSH([C++])
+ SAVED_LIBS="$LIBS"
+ LIBS="-lgtest"
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [
#include "gtest/gtest.h"
- ],
- [
+ ],
+ [
return 0;
- ])],
- [ac_cv_have_gtest=yes],
- [ac_cv_have_gtest=no])
- AC_LANG_POP([C++])
- LIBS="$SAVED_LIBS"
+ ])],
+ [ac_cv_have_gtest=yes],
+ [ac_cv_have_gtest=no])
+ AC_LANG_POP([C++])
+ LIBS="$SAVED_LIBS"
+ ])
])
-AM_CONDITIONAL(HAVE_GOOGLETEST, [test "$ac_cv_have_gtest" = "yes"])
+AM_CONDITIONAL(HAVE_GOOGLETEST_SRC, [test "$ac_cv_have_gtest_src" = "yes"])
+AM_CONDITIONAL(HAVE_GOOGLETEST, [test "$ac_cv_have_gtest" = "yes" -o \
+ "$ac_cv_have_gtest_src" = "yes"])
+
AC_CHECK_HEADERS_ONCE([libcouchstore/couch_common.h])
AS_IF([test "x$ac_cv_header_libcouchstore_couch_common_h" != "xyes"],
@@ -104,7 +120,7 @@ AH_BOTTOM([
dnl ----------------------------------------------------------------------------
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
-AS_IF([test "$ac_cv_have_gtest" != "yes"],
+AS_IF([test "$ac_cv_have_gtest" = "no" -a "$ac_cv_have_gtest_src" = "no"],
[
echo "*****"
echo "*"
View
2 m4/couchbase.m4
@@ -57,7 +57,7 @@ AC_DEFUN([COUCHBASE_GENERIC_COMPILER], [
GCC_C_DEBUG="-O0 -g3"
GCC_CXX_DEBUG="-O0 -g3"
GCC_VISIBILITY="-DHAVE_VISIBILITY=1 -fvisibility=hidden"
- GCC_CPPFLAGS="-pipe"
+ GCC_CPPFLAGS="-pipe -pthread"
GCC_CFLAGS="-std=gnu99"
GCC_CXXFLAGS=""
GCC_C89=-std=c89
View
8 tests/gtest-sources.cc
@@ -0,0 +1,8 @@
+/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ * This file is just a wrapper file used to include the gtest-all.cc located
+ * under $GTEST_ROOT. Ideally I would have liked to put it in Makefile.am, but
+ * then automake started to complain about missing files if we _didn't_ have
+ * GTEST_ROOT defined (even if we didn't need to compile the file etc).
+ */
+#include "src/gtest-all.cc"

0 comments on commit c8b3222

Please sign in to comment.