Skip to content

Commit

Permalink
Makefile: link gtest statically
Browse files Browse the repository at this point in the history
The problem:

 - the unittests link against gtest, and gtest is not installed.  that's
   normally fine, but...
 - rbd and rados api unit tests link against gtest, and are installed
   by 'make install'.  they are needed for teuthology runs, etc.
 - if we build gtest as an .la library, we can only control whether *all*
   or *no* .la libraries are linked statically.
 - we want librados to be linked dynamically.

The solution:

 - build gtest as .a instead of a libtool library
 - link it statically, always.

Unit test binaries are bigger now.  Oh well...

Fixes: ceph#2331
Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
Sage Weil committed Jun 13, 2012
1 parent c4a607a commit 66553d2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ all-local:
if WITH_DEBUG
# We need gtest to build the rados-api tests. We only build those in
# a debug build, though.
@cd src/gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la lib/libgtest.a lib/libgtest_main.a
@cd src/gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.a lib/libgtest_main.a
endif

check-local:
# We build gtest this way, instead of using SUBDIRS, because with that,
# gtest's own tests would be run and that would slow us down.
@cd src/gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la
@cd src/gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.a lib/libgtest_main.a
# exercise cli tools
$(srcdir)/src/test/run-cli-tests '$(top_builddir)/src/test'

Expand Down
5 changes: 1 addition & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,11 @@ unittests:: $(check_PROGRAMS)
UNITTEST_CXXFLAGS = \
-I$(top_srcdir)/src/gtest/include \
-I$(top_builddir)/src/gtest/include
UNITTEST_LDADD = \
$(top_builddir)/src/gtest/lib/libgtest.la \
$(top_builddir)/src/gtest/lib/libgtest_main.la \
$(PTHREAD_LIBS)
UNITTEST_STATIC_LDADD = \
$(top_builddir)/src/gtest/lib/libgtest.a \
$(top_builddir)/src/gtest/lib/libgtest_main.a \
$(PTHREAD_LIBS)
UNITTEST_LDADD = ${UNITTEST_STATIC_LDADD}

unittest_encoding_SOURCES = test/encoding.cc
unittest_encoding_LDADD = libcephfs.la librados.la $(PTHREAD_LIBS) -lm \
Expand Down
9 changes: 2 additions & 7 deletions src/gtest/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,8 @@ else
endif

# Build rules for libraries.
lib_LTLIBRARIES = lib/libgtest.la lib/libgtest_main.la
lib_LTLIBRARIES += lib/libgtest.a lib/libgtest_main.a
lib_LIBRARIES = lib/libgtest.a lib/libgtest_main.a

lib_libgtest_la_SOURCES = src/gtest-all.cc
lib_libgtest_a_SOURCES = src/gtest-all.cc

pkginclude_HEADERS = include/gtest/gtest.h \
Expand All @@ -208,9 +206,6 @@ pkginclude_internal_HEADERS = \
include/gtest/internal/gtest-tuple.h \
include/gtest/internal/gtest-type-util.h

lib_libgtest_main_la_SOURCES = src/gtest_main.cc
lib_libgtest_main_la_LIBADD = lib/libgtest.la

lib_libgtest_main_a_SOURCES = src/gtest_main.cc
lib_libgtest_main_a_LIBADD = lib/libgtest.a

Expand Down Expand Up @@ -247,7 +242,7 @@ samples_sample1_unittest_LDADD = lib/libgtest_main.la \
TESTS += samples/sample10_unittest
check_PROGRAMS += samples/sample10_unittest
samples_sample10_unittest_SOURCES = samples/sample10_unittest.cc
samples_sample10_unittest_LDADD = lib/libgtest.la
samples_sample10_unittest_LDADD = lib/libgtest.a

# This tests most constructs of gtest and verifies that libgtest_main
# works.
Expand Down
2 changes: 1 addition & 1 deletion src/gtest/scripts/gtest-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ if test "${this_bindir}" = "${this_bindir%${bindir}}"; then
# TODO([email protected]): This is a dangerous dependency on libtool, we
# should work to remove it, and/or remove libtool altogether, replacing it
# with direct references to the library and a link path.
gtest_libs="${build_dir}/lib/libgtest.la @PTHREAD_CFLAGS@ @PTHREAD_LIBS@"
gtest_libs="${build_dir}/lib/libgtest.a @PTHREAD_CFLAGS@ @PTHREAD_LIBS@"
gtest_ldflags=""
# We provide hooks to include from either the source or build dir, where the
Expand Down

0 comments on commit 66553d2

Please sign in to comment.