configure: query pkg-config for flags & libraries for gtest

See #3696
This commit is contained in:
Moritz Bunkus 2024-05-04 19:46:15 +02:00
parent 7e1bea9527
commit 5430290cf1
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85
6 changed files with 20 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
])

View File

@ -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@

View File

@ -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,

View File

@ -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)