Skip to content

Commit 66553d2

Browse files
author
Sage Weil
committed
Makefile: link gtest statically
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]>
1 parent c4a607a commit 66553d2

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ all-local:
1515
if WITH_DEBUG
1616
# We need gtest to build the rados-api tests. We only build those in
1717
# a debug build, though.
18-
@cd src/gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la lib/libgtest.a lib/libgtest_main.a
18+
@cd src/gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.a lib/libgtest_main.a
1919
endif
2020

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

src/Makefile.am

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,11 @@ unittests:: $(check_PROGRAMS)
504504
UNITTEST_CXXFLAGS = \
505505
-I$(top_srcdir)/src/gtest/include \
506506
-I$(top_builddir)/src/gtest/include
507-
UNITTEST_LDADD = \
508-
$(top_builddir)/src/gtest/lib/libgtest.la \
509-
$(top_builddir)/src/gtest/lib/libgtest_main.la \
510-
$(PTHREAD_LIBS)
511507
UNITTEST_STATIC_LDADD = \
512508
$(top_builddir)/src/gtest/lib/libgtest.a \
513509
$(top_builddir)/src/gtest/lib/libgtest_main.a \
514510
$(PTHREAD_LIBS)
511+
UNITTEST_LDADD = ${UNITTEST_STATIC_LDADD}
515512

516513
unittest_encoding_SOURCES = test/encoding.cc
517514
unittest_encoding_LDADD = libcephfs.la librados.la $(PTHREAD_LIBS) -lm \

src/gtest/Makefile.am

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,8 @@ else
179179
endif
180180

181181
# Build rules for libraries.
182-
lib_LTLIBRARIES = lib/libgtest.la lib/libgtest_main.la
183-
lib_LTLIBRARIES += lib/libgtest.a lib/libgtest_main.a
182+
lib_LIBRARIES = lib/libgtest.a lib/libgtest_main.a
184183

185-
lib_libgtest_la_SOURCES = src/gtest-all.cc
186184
lib_libgtest_a_SOURCES = src/gtest-all.cc
187185

188186
pkginclude_HEADERS = include/gtest/gtest.h \
@@ -208,9 +206,6 @@ pkginclude_internal_HEADERS = \
208206
include/gtest/internal/gtest-tuple.h \
209207
include/gtest/internal/gtest-type-util.h
210208

211-
lib_libgtest_main_la_SOURCES = src/gtest_main.cc
212-
lib_libgtest_main_la_LIBADD = lib/libgtest.la
213-
214209
lib_libgtest_main_a_SOURCES = src/gtest_main.cc
215210
lib_libgtest_main_a_LIBADD = lib/libgtest.a
216211

@@ -247,7 +242,7 @@ samples_sample1_unittest_LDADD = lib/libgtest_main.la \
247242
TESTS += samples/sample10_unittest
248243
check_PROGRAMS += samples/sample10_unittest
249244
samples_sample10_unittest_SOURCES = samples/sample10_unittest.cc
250-
samples_sample10_unittest_LDADD = lib/libgtest.la
245+
samples_sample10_unittest_LDADD = lib/libgtest.a
251246

252247
# This tests most constructs of gtest and verifies that libgtest_main
253248
# works.

src/gtest/scripts/gtest-config.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ if test "${this_bindir}" = "${this_bindir%${bindir}}"; then
214214
# TODO([email protected]): This is a dangerous dependency on libtool, we
215215
# should work to remove it, and/or remove libtool altogether, replacing it
216216
# with direct references to the library and a link path.
217-
gtest_libs="${build_dir}/lib/libgtest.la @PTHREAD_CFLAGS@ @PTHREAD_LIBS@"
217+
gtest_libs="${build_dir}/lib/libgtest.a @PTHREAD_CFLAGS@ @PTHREAD_LIBS@"
218218
gtest_ldflags=""
219219
220220
# We provide hooks to include from either the source or build dir, where the

0 commit comments

Comments
 (0)