acimpoeru / google-glog

Automatically exported from code.google.com/p/google-glog
Other
0 stars 0 forks source link

build problems when building with gtest (includes patch) #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

when building with gtest support on MacOSX, I needed the
following changes to be able to compile from trunk:

Index: Makefile.am
===================================================================
--- Makefile.am (revision 41)
+++ Makefile.am (working copy)
@@ -142,7 +142,7 @@
 stl_logging_unittest_SOURCES = $(gloginclude_HEADERS) \
                                src/stl_logging_unittest.cc
 nodist_stl_logging_unittest_SOURCES = $(nodist_gloginclude_HEADERS)
-stl_logging_unittest_CXXFLAGS = $(PTHREAD_CFLAGS)
+stl_logging_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 stl_logging_unittest_LDFLAGS = $(PTHREAD_CFLAGS)
 stl_logging_unittest_LDADD = libglog.la $(COMMON_LIBS)

Index: src/logging_unittest.cc
===================================================================
--- src/logging_unittest.cc     (revision 41)
+++ src/logging_unittest.cc     (working copy)
@@ -1120,10 +1120,12 @@
   base::internal::SetExitOnDFatal(true);
   EXPECT_TRUE(base::internal::GetExitOnDFatal());

+#ifdef GTEST_HAS_DEATH_TEST
   // Death comes on little cats' feet.
   EXPECT_DEBUG_DEATH({
       LOG(DFATAL) << "This should be fatal in debug mode";
     }, "This should be fatal in debug mode");
+#endif
 }

 #ifdef HAVE_STACKTRACE

Although I'm not an autotools expert, I suggest removing the
following files from the subversion repository as they're rebuilt
when running 'autoreconf -fvi':

    configure Makefile.in depcomp config.guess config.sub
    ltmain.sh INSTALL aclocal.m4 install-sh

Best, maw

Original issue reported on code.google.com by maw@gmail.com on 11 Mar 2009 at 2:00

GoogleCodeExporter commented 8 years ago
A newer version of the patch, additionally makes configure honor
non-standard installations using --with-gflags=/path/to/gflags

Best, maw

Index: src/logging_unittest.cc
===================================================================
--- src/logging_unittest.cc (revision 41)
+++ src/logging_unittest.cc (working copy)
@@ -1120,10 +1120,12 @@
   base::internal::SetExitOnDFatal(true);
   EXPECT_TRUE(base::internal::GetExitOnDFatal());

+#ifdef GTEST_HAS_DEATH_TEST
   // Death comes on little cats' feet.
   EXPECT_DEBUG_DEATH({
       LOG(DFATAL) << "This should be fatal in debug mode";
     }, "This should be fatal in debug mode");
+#endif
 }

 #ifdef HAVE_STACKTRACE
Index: configure.ac
===================================================================
--- configure.ac    (revision 41)
+++ configure.ac    (working copy)
@@ -99,13 +99,23 @@
 fi

 # Check if there is google-gflags library installed.
+SAVE_CFLAGS="$CFLAGS"
+SAVE_LIBS="$LIBS"
+if test x"$with_gflags" != x; then
+  GFLAGS_CFLAGS=-I${with_gflags}/include
+  GFLAGS_LIBS=-L${with_gflags}/lib -lgflags
+  CFLAGS="$CFLAGS $GFLAGS_CFLAGS"
+  LIBS="$LIBS $GFLAGS_LIBS"
+fi
 AC_CHECK_LIB(gflags, main, ac_cv_have_libgflags=1, ac_cv_have_libgflags=0)
 if test x"$ac_cv_have_libgflags" = x"1"; then
-  GFLAGS_LIBS=-lgflags
   AC_DEFINE(HAVE_LIB_GFLAGS, 1, [define if you have google gflags library])
 else
+  GFLAGS_CFLAGS=
   GFLAGS_LIBS=
 fi
+CFLAGS="$SAVE_CFLAGS"
+LIBS="$SAVE_LIBS"

 # TODO(hamaji): Use official m4 macros provided by testing libraries
 #               once the m4 macro of Google Mocking becomes ready.
@@ -211,9 +221,10 @@
 AC_SUBST(ac_cv_have_u_int16_t)
 AC_SUBST(ac_cv_have___uint16)
 AC_SUBST(ac_cv_have_libgflags)
-AC_SUBST(GFLAGS_LIBS)
+AC_SUBST(GFLAGS_CFLAGS)
 AC_SUBST(GTEST_CFLAGS)
 AC_SUBST(GMOCK_CFLAGS)
+AC_SUBST(GFLAGS_LIBS)
 AC_SUBST(GTEST_LIBS)
 AC_SUBST(GMOCK_LIBS)

Index: Makefile.am
===================================================================
--- Makefile.am (revision 41)
+++ Makefile.am (working copy)
@@ -47,9 +47,9 @@
 # The libraries libglog depends on.
 COMMON_LIBS = $(PTHREAD_LIBS) $(GFLAGS_LIBS) $(UNWIND_LIBS)
 # Compile switches for our unittest.
-TEST_CFLAGS = $(GTEST_CFLAGS) $(GMOCK_CFLAGS)
+TEST_CFLAGS = $(GTEST_CFLAGS) $(GMOCK_CFLAGS) $(GFLAGS_CFLAGS)
 # Libraries for our unittest.
-TEST_LIBS = $(GTEST_LIBS) $(GMOCK_LIBS)
+TEST_LIBS = $(GTEST_LIBS) $(GMOCK_LIBS) $(GFLAGS_LIBS)

 ## unittests you want to run when people type 'make check'.
 ## TESTS is for binary unittests, check_SCRIPTS for script-based unittests.
@@ -94,7 +94,7 @@
 logging_striptest0_SOURCES = $(gloginclude_HEADERS) \
                              src/logging_striptest_main.cc
 nodist_logging_striptest0_SOURCES = $(nodist_gloginclude_HEADERS)
-logging_striptest0_CXXFLAGS = $(PTHREAD_CFLAGS)
+logging_striptest0_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 logging_striptest0_LDFLAGS = $(PTHREAD_CFLAGS)
 logging_striptest0_LDADD = libglog.la $(COMMON_LIBS)

@@ -102,7 +102,7 @@
 logging_striptest2_SOURCES = $(gloginclude_HEADERS) \
                              src/logging_striptest2.cc
 nodist_logging_striptest2_SOURCES = $(nodist_gloginclude_HEADERS)
-logging_striptest2_CXXFLAGS = $(PTHREAD_CFLAGS)
+logging_striptest2_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 logging_striptest2_LDFLAGS = $(PTHREAD_CFLAGS)
 logging_striptest2_LDADD = libglog.la $(COMMON_LIBS)

@@ -110,7 +110,7 @@
 logging_striptest10_SOURCES = $(gloginclude_HEADERS) \
                               src/logging_striptest10.cc
 nodist_logging_striptest10_SOURCES = $(nodist_gloginclude_HEADERS)
-logging_striptest10_CXXFLAGS = $(PTHREAD_CFLAGS)
+logging_striptest10_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 logging_striptest10_LDFLAGS = $(PTHREAD_CFLAGS)
 logging_striptest10_LDADD = libglog.la $(COMMON_LIBS)

@@ -126,7 +126,7 @@
 stacktrace_unittest_SOURCES = $(gloginclude_HEADERS) \
                               src/stacktrace_unittest.cc
 nodist_stacktrace_unittest_SOURCES = $(nodist_gloginclude_HEADERS)
-stacktrace_unittest_CXXFLAGS = $(PTHREAD_CFLAGS)
+stacktrace_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 stacktrace_unittest_LDFLAGS = $(PTHREAD_CFLAGS)
 stacktrace_unittest_LDADD = libglog.la $(COMMON_LIBS)

@@ -142,9 +142,9 @@
 stl_logging_unittest_SOURCES = $(gloginclude_HEADERS) \
                                src/stl_logging_unittest.cc
 nodist_stl_logging_unittest_SOURCES = $(nodist_gloginclude_HEADERS)
-stl_logging_unittest_CXXFLAGS = $(PTHREAD_CFLAGS)
+stl_logging_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 stl_logging_unittest_LDFLAGS = $(PTHREAD_CFLAGS)
-stl_logging_unittest_LDADD = libglog.la $(COMMON_LIBS)
+stl_logging_unittest_LDADD = libglog.la $(COMMON_LIBS) $(TEST_LIBS)

 TEST_BINARIES += signalhandler_unittest
 signalhandler_unittest_SOURCES = $(gloginclude_HEADERS) \
@@ -191,8 +191,8 @@
                        src/base/commandlineflags.h src/googletest.h
 nodist_libglog_la_SOURCES = $(nodist_gloginclude_HEADERS)

-libglog_la_CXXFLAGS = $(PTRHEAD_CFLAGS) -DNDEBUG
-libglog_la_LDFLAGS = $(PTRHEAD_CFLAGS)
+libglog_la_CXXFLAGS = $(PTRHEAD_CFLAGS) $(GFLAGS_CFLAGS) -DNDEBUG
+libglog_la_LDFLAGS = $(PTRHEAD_CFLAGS) $(GFLAGS_LDFLAGS)
 libglog_la_LIBADD = $(COMMON_LIBS)

 ## The location of the windows project file for each binary we make

Original comment by maw@gmail.com on 21 Mar 2009 at 2:22

GoogleCodeExporter commented 8 years ago
Fixed patch, was missing some shell quotes and a well-placed $(TEST_LIBS):

Index: src/logging_unittest.cc
===================================================================
--- src/logging_unittest.cc (revision 41)
+++ src/logging_unittest.cc (working copy)
@@ -1120,10 +1120,12 @@
   base::internal::SetExitOnDFatal(true);
   EXPECT_TRUE(base::internal::GetExitOnDFatal());

+#ifdef GTEST_HAS_DEATH_TEST
   // Death comes on little cats' feet.
   EXPECT_DEBUG_DEATH({
       LOG(DFATAL) << "This should be fatal in debug mode";
     }, "This should be fatal in debug mode");
+#endif
 }

 #ifdef HAVE_STACKTRACE
Index: configure.ac
===================================================================
--- configure.ac    (revision 41)
+++ configure.ac    (working copy)
@@ -99,13 +99,23 @@
 fi

 # Check if there is google-gflags library installed.
+SAVE_CFLAGS="$CFLAGS"
+SAVE_LIBS="$LIBS"
+if test x"$with_gflags" != x; then
+  GFLAGS_CFLAGS="-I${with_gflags}/include"
+  GFLAGS_LIBS="-L${with_gflags}/lib -lgflags"
+  CFLAGS="$CFLAGS $GFLAGS_CFLAGS"
+  LIBS="$LIBS $GFLAGS_LIBS"
+fi
 AC_CHECK_LIB(gflags, main, ac_cv_have_libgflags=1, ac_cv_have_libgflags=0)
 if test x"$ac_cv_have_libgflags" = x"1"; then
-  GFLAGS_LIBS=-lgflags
   AC_DEFINE(HAVE_LIB_GFLAGS, 1, [define if you have google gflags library])
 else
+  GFLAGS_CFLAGS=
   GFLAGS_LIBS=
 fi
+CFLAGS="$SAVE_CFLAGS"
+LIBS="$SAVE_LIBS"

 # TODO(hamaji): Use official m4 macros provided by testing libraries
 #               once the m4 macro of Google Mocking becomes ready.
@@ -211,9 +221,10 @@
 AC_SUBST(ac_cv_have_u_int16_t)
 AC_SUBST(ac_cv_have___uint16)
 AC_SUBST(ac_cv_have_libgflags)
-AC_SUBST(GFLAGS_LIBS)
+AC_SUBST(GFLAGS_CFLAGS)
 AC_SUBST(GTEST_CFLAGS)
 AC_SUBST(GMOCK_CFLAGS)
+AC_SUBST(GFLAGS_LIBS)
 AC_SUBST(GTEST_LIBS)
 AC_SUBST(GMOCK_LIBS)

Index: Makefile.am
===================================================================
--- Makefile.am (revision 41)
+++ Makefile.am (working copy)
@@ -47,9 +47,9 @@
 # The libraries libglog depends on.
 COMMON_LIBS = $(PTHREAD_LIBS) $(GFLAGS_LIBS) $(UNWIND_LIBS)
 # Compile switches for our unittest.
-TEST_CFLAGS = $(GTEST_CFLAGS) $(GMOCK_CFLAGS)
+TEST_CFLAGS = $(GTEST_CFLAGS) $(GMOCK_CFLAGS) $(GFLAGS_CFLAGS)
 # Libraries for our unittest.
-TEST_LIBS = $(GTEST_LIBS) $(GMOCK_LIBS)
+TEST_LIBS = $(GTEST_LIBS) $(GMOCK_LIBS) $(GFLAGS_LIBS)

 ## unittests you want to run when people type 'make check'.
 ## TESTS is for binary unittests, check_SCRIPTS for script-based unittests.
@@ -94,7 +94,7 @@
 logging_striptest0_SOURCES = $(gloginclude_HEADERS) \
                              src/logging_striptest_main.cc
 nodist_logging_striptest0_SOURCES = $(nodist_gloginclude_HEADERS)
-logging_striptest0_CXXFLAGS = $(PTHREAD_CFLAGS)
+logging_striptest0_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 logging_striptest0_LDFLAGS = $(PTHREAD_CFLAGS)
 logging_striptest0_LDADD = libglog.la $(COMMON_LIBS)

@@ -102,7 +102,7 @@
 logging_striptest2_SOURCES = $(gloginclude_HEADERS) \
                              src/logging_striptest2.cc
 nodist_logging_striptest2_SOURCES = $(nodist_gloginclude_HEADERS)
-logging_striptest2_CXXFLAGS = $(PTHREAD_CFLAGS)
+logging_striptest2_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 logging_striptest2_LDFLAGS = $(PTHREAD_CFLAGS)
 logging_striptest2_LDADD = libglog.la $(COMMON_LIBS)

@@ -110,7 +110,7 @@
 logging_striptest10_SOURCES = $(gloginclude_HEADERS) \
                               src/logging_striptest10.cc
 nodist_logging_striptest10_SOURCES = $(nodist_gloginclude_HEADERS)
-logging_striptest10_CXXFLAGS = $(PTHREAD_CFLAGS)
+logging_striptest10_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 logging_striptest10_LDFLAGS = $(PTHREAD_CFLAGS)
 logging_striptest10_LDADD = libglog.la $(COMMON_LIBS)

@@ -126,7 +126,7 @@
 stacktrace_unittest_SOURCES = $(gloginclude_HEADERS) \
                               src/stacktrace_unittest.cc
 nodist_stacktrace_unittest_SOURCES = $(nodist_gloginclude_HEADERS)
-stacktrace_unittest_CXXFLAGS = $(PTHREAD_CFLAGS)
+stacktrace_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 stacktrace_unittest_LDFLAGS = $(PTHREAD_CFLAGS)
 stacktrace_unittest_LDADD = libglog.la $(COMMON_LIBS)

@@ -142,17 +142,17 @@
 stl_logging_unittest_SOURCES = $(gloginclude_HEADERS) \
                                src/stl_logging_unittest.cc
 nodist_stl_logging_unittest_SOURCES = $(nodist_gloginclude_HEADERS)
-stl_logging_unittest_CXXFLAGS = $(PTHREAD_CFLAGS)
+stl_logging_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 stl_logging_unittest_LDFLAGS = $(PTHREAD_CFLAGS)
-stl_logging_unittest_LDADD = libglog.la $(COMMON_LIBS)
+stl_logging_unittest_LDADD = libglog.la $(COMMON_LIBS) $(TEST_LIBS)

 TEST_BINARIES += signalhandler_unittest
 signalhandler_unittest_SOURCES = $(gloginclude_HEADERS) \
                                src/signalhandler_unittest.cc
 nodist_signalhandler_unittest_SOURCES = $(nodist_gloginclude_HEADERS)
-signalhandler_unittest_CXXFLAGS = $(PTHREAD_CFLAGS)
+signalhandler_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(TEST_CFLAGS)
 signalhandler_unittest_LDFLAGS = $(PTHREAD_CFLAGS)
-signalhandler_unittest_LDADD = libglog.la $(COMMON_LIBS)
+signalhandler_unittest_LDADD = libglog.la $(COMMON_LIBS) $(TEST_LIBS)

 TESTS += utilities_unittest
 utilities_unittest_SOURCES = $(gloginclude_HEADERS) \
@@ -191,8 +191,8 @@
                        src/base/commandlineflags.h src/googletest.h
 nodist_libglog_la_SOURCES = $(nodist_gloginclude_HEADERS)

-libglog_la_CXXFLAGS = $(PTRHEAD_CFLAGS) -DNDEBUG
-libglog_la_LDFLAGS = $(PTRHEAD_CFLAGS)
+libglog_la_CXXFLAGS = $(PTRHEAD_CFLAGS) $(GFLAGS_CFLAGS) -DNDEBUG
+libglog_la_LDFLAGS = $(PTRHEAD_CFLAGS) $(GFLAGS_LDFLAGS)
 libglog_la_LIBADD = $(COMMON_LIBS)

 ## The location of the windows project file for each binary we make

Original comment by maw@gmail.com on 21 Mar 2009 at 3:11

GoogleCodeExporter commented 8 years ago
I thought I responded to this bug, but I noticed I just responded on glog's 
mail-
list, not on this bug, sorry. I'll copy&paste my email...

Thanks for the patch! I'd like to use your work. Could you sign our Individual 
Contributor
License Agreement, please? The process is just submitting an HTML form
and it shouldn't take your time so much.

http://code.google.com/legal/individual-cla-v1.0.html

Please note that these forms do not transfer copyright: the
contributor retains her ownership in the work. The CLA just grants
Google a "perpetual, non-exclusive, royalty-free, etc..." right to use
the work, sublicense it, and so on.

> Although I'm not an autotools expert, I suggest removing the
> following files from the subversion repository as they're rebuilt
> when running 'autoreconf -fvi':
>
>     configure Makefile.in depcomp config.guess config.sub
>     ltmain.sh INSTALL aclocal.m4 install-sh

I think some opensource projects check these kind of generated files
in their repository, and some other projects don't check them in.
There are both pros. and cons. for each approach (e.g., it is the
benefit of our approach that users can try to compile svn head without
autotools). I'm using the former way to keep consistency with other
Google's opensource C++ library projects such as google-gflags. So,
I'd like to keep the approach.

Original comment by shinichi...@gmail.com on 21 Mar 2009 at 3:12

GoogleCodeExporter commented 8 years ago
Applied the patch. Thanks!

http://code.google.com/p/google-glog/source/detail?r=42

Original comment by shinichi...@gmail.com on 7 Apr 2009 at 6:34