diff --git a/NEWS.md b/NEWS.md index 446b6777a..cf2dde626 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,9 @@ * fixed compilation of `src/common/sorting.h` with certain compilers due to the deprecation & removal of `std::result_of<>` in C++20. Fixes #3695. +* fixed compilation with the `gtest` library when `gtest` requires additional + libraries by querying `pkg-config` for the correct flags & libraries to + build with. See #3696. # Version 84.0 "Sleeper" 2024-04-28 diff --git a/Rakefile b/Rakefile index 2df193ded..44ad0e749 100644 --- a/Rakefile +++ b/Rakefile @@ -171,7 +171,7 @@ def setup_globals cxxflags += " -Wmisleading-indentation -Wduplicated-cond" if check_compiler_version("gcc", "6.0.0") cxxflags += " -Wshadow-compatible-local -Wduplicated-branches" if check_compiler_version("gcc", "7.0.0") cxxflags += " -Wno-deprecated-copy -Wno-stringop-overflow" if check_compiler_version("gcc", "9.0.0") - cxxflags += " #{c(:QT_CFLAGS)} #{c(:BOOST_CPPFLAGS)} #{c(:USER_CXXFLAGS)}" + cxxflags += " #{c(:QT_CFLAGS)} #{c(:BOOST_CPPFLAGS)} #{c(:USER_CXXFLAGS)} #{c(:GTEST_CFLAGS)}" ldflags = "" ldflags += determine_stack_protector_flags diff --git a/ac/gtest.m4 b/ac/gtest.m4 index 43457947c..00e786cb5 100644 --- a/ac/gtest.m4 +++ b/ac/gtest.m4 @@ -1,13 +1,20 @@ AC_DEFUN([AX_GTEST],[ - GTEST_TYPE=system + GTEST_CFLAGS= + GTEST_LIBS= + GTEST_TYPE=no CPPFLAGS_SAVED="$CPPFLAGS" AC_LANG_PUSH(C++) - AC_CHECK_LIB([gtest_main],[main],[true],[GTEST_TYPE=no],[-lpthread]) - AC_CHECK_HEADERS([gtest/gtest.h],[true],[GTEST_TYPE=no]) + PKG_CHECK_EXISTS([gtest],[gtest_found=yes],[gtest_found=no]) - if test $GTEST_TYPE = no && test -d lib/gtest/include && test -d lib/gtest/src ; then + if test x"$gtest_found" = xyes; then + PKG_CHECK_MODULES([gtest],[gtest],[gtest_found=yes]) + GTEST_CFLAGS="`$PKG_CONFIG --cflags gtest`" + GTEST_LIBS="`$PKG_CONFIG --libs gtest`" + GTEST_TYPE=system + + elif test -d lib/gtest/include && test -d lib/gtest/src ; then AC_MSG_CHECKING(for internal gtest) AC_CACHE_VAL(ax_cv_gtest_internal,[ CPPFLAGS="$CPPFLAGS_SAVED -Ilib/gtest/include" @@ -23,6 +30,8 @@ AC_DEFUN([AX_GTEST],[ AC_LANG_POP CPPFLAGS="$CPPFLAGS_SAVED" + AC_SUBST(GTEST_CFLAGS) + AC_SUBST(GTEST_LIBS) AC_SUBST(GTEST_TYPE) ]) diff --git a/build-config.in b/build-config.in index 81201613c..48be0c270 100644 --- a/build-config.in +++ b/build-config.in @@ -98,6 +98,8 @@ EXTRA_CFLAGS = @EXTRA_CFLAGS@ EXTRA_LDFLAGS = @EXTRA_LDFLAGS@ FMT_INTERNAL = @FMT_INTERNAL@ GOOGLE_BENCHMARK = @GOOGLE_BENCHMARK@ +GTEST_CFLAGS = @GTEST_CFLAGS@ +GTEST_LIBS = @GTEST_LIBS@ GTEST_TYPE = @GTEST_TYPE@ LDFLAGS_RPATHS = @LDFLAGS_RPATHS@ FLAC_CFLAGS = @FLAC_CFLAGS@ diff --git a/rake.d/gtest.rb b/rake.d/gtest.rb index aba4482f3..9e40d36e8 100755 --- a/rake.d/gtest.rb +++ b/rake.d/gtest.rb @@ -24,7 +24,6 @@ $build_system_modules[:gtest] = { :setup => lambda do if $gtest_internal $flags[:cxxflags] += " -Ilib/gtest -Ilib/gtest/include" - $flags[:ldflags] += " -Llib/gtest/src" end end, diff --git a/rake.d/target.rb b/rake.d/target.rb index f23ec8759..042cdd13a 100644 --- a/rake.d/target.rb +++ b/rake.d/target.rb @@ -158,6 +158,7 @@ class Target case entry when nil then nil when :flac then c(:FLAC_LIBS) + when :gtest then $gtest_internal ? [ '-Llib/gtest/src', '-lgtest' ] : c(:GTEST_LIBS) when :iconv then c(:ICONV_LIBS) when :intl then c(:LIBINTL_LIBS) when :cmark then c(:CMARK_LIBS)