From 15dffb02f179974c6726f16aff586c49eec8c7ca Mon Sep 17 00:00:00 2001 From: Jelte Jansen Date: Wed, 30 Nov 2011 15:27:36 +0100 Subject: [PATCH] [1442] conditionally check whether gtest needs pthread --- configure.ac | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index d2b1de9bb5..d54cad241d 100644 --- a/configure.ac +++ b/configure.ac @@ -724,8 +724,37 @@ then if test "${GTEST_FOUND}" != "true"; then AC_MSG_ERROR([Cannot find gtest in: $GTEST_PATHS]) fi - # TODO: check whether this is needed (depends on gtest compile flags) - GTEST_LDADD="$GTEST_LDADD $PTHREAD_LDFLAGS" + # On some systems, there is no gtest-config script, which is supposed + # to inform us whether we need -lpthread as well (a gtest compile-time + # option). So we still need to test that manually + LIBS_SAVED=$LIBS + LIBS="$LIBS $GTEST_LDADD" + AC_MSG_CHECKING([Checking whether gtest tests need -lpthread]) + AC_TRY_LINK([ + #include + ],[ + int i = 0; + char* c = NULL; + ::testing::InitGoogleTest(&i, &c); + return (0); + ], + [ AC_MSG_RESULT(no) ], + [ + LIBS="$LIBS $GTEST_LDADD $PTHREAD_LDFLAGS" + AC_TRY_LINK([ + #include + ],[ + int i = 0; + char* c = NULL; + ::testing::InitGoogleTest(&i, &c); + return (0); + ], + [ AC_MSG_RESULT(yes) + GTEST_LDADD="$GTEST_LDADD $PTHREAD_LDFLAGS" + ], + [ AC_MSG_ERROR(unable to compile with gtest) ]) + ]) + LIBS=$LIBS_SAVED else GTEST_INCLUDES= GTEST_LDFLAGS=