From 4493fd9c31e01a39f806092ecaecc239ca3e10c9 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sun, 12 Apr 2015 01:02:13 +0300 Subject: [PATCH] Allow to use system QJson. Closes #1744. --- configure | 132 ++++++++++++++++++++++++++++++++++++++++ configure.ac | 23 +++++++ src/app/application.cpp | 2 +- src/webui/jsonutils.h | 5 ++ src/webui/webui.pri | 7 ++- 5 files changed, 165 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 37add6d14..162a90afe 100755 --- a/configure +++ b/configure @@ -601,6 +601,8 @@ EXPAND_BINDIR EXPAND_PREFIX zlib_LIBS zlib_CFLAGS +qjson_LIBS +qjson_CFLAGS libtorrent_LIBS libtorrent_CFLAGS BOOST_SYSTEM_LIB @@ -716,6 +718,7 @@ with_qt5 with_libtorrent_rasterbar0_16 with_geoip_database_embedded with_qtsingleapplication +with_qjson enable_debug enable_gui enable_systemd @@ -742,6 +745,8 @@ PKG_CONFIG_LIBDIR QT_QMAKE libtorrent_CFLAGS libtorrent_LIBS +qjson_CFLAGS +qjson_LIBS zlib_CFLAGS zlib_LIBS' @@ -1389,6 +1394,9 @@ Optional Packages: --with-qtsingleapplication=[system|shipped] Use the shipped qtsingleapplication library or the system one (default=shipped) + --with-qjson=[system|shipped] + Use the shipped qjson library or the system one + (default=shipped) (Qt4 only --with-boost[=ARG] use Boost library from a standard location (ARG=yes), from the specified location (ARG=), or disable it (ARG=no) [ARG=yes] @@ -1423,6 +1431,9 @@ Some influential environment variables: C compiler flags for libtorrent, overriding pkg-config libtorrent_LIBS linker flags for libtorrent, overriding pkg-config + qjson_CFLAGS + C compiler flags for qjson, overriding pkg-config + qjson_LIBS linker flags for qjson, overriding pkg-config zlib_CFLAGS C compiler flags for zlib, overriding pkg-config zlib_LIBS linker flags for zlib, overriding pkg-config @@ -4200,6 +4211,15 @@ else fi + +# Check whether --with-qjson was given. +if test "${with_qjson+set}" = set; then : + withval=$with_qjson; +else + with_qjson=shipped +fi + + # Check whether --enable-debug was given. if test "${enable_debug+set}" = set; then : enableval=$enable_debug; @@ -5507,6 +5527,118 @@ $as_echo "$with_qtsingleapplication" >&6; } as_fn_error $? "Unknown option \"$with_qtsingleapplication\". Use either \"system\" or \"shipped\"." "$LINENO" 5 ;; esac +if test "x$with_qt5" = "xno"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking which qjson to use" >&5 +$as_echo_n "checking which qjson to use... " >&6; } + case "x$with_qjson" in #( + "xshipped") : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: shipped" >&5 +$as_echo "shipped" >&6; } + QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG usesystemqjson" ;; #( + "xsystem") : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: system" >&5 +$as_echo "system" >&6; } + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for qjson" >&5 +$as_echo_n "checking for qjson... " >&6; } + +if test -n "$qjson_CFLAGS"; then + pkg_cv_qjson_CFLAGS="$qjson_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"QJson >= 0.8.1\""; } >&5 + ($PKG_CONFIG --exists --print-errors "QJson >= 0.8.1") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_qjson_CFLAGS=`$PKG_CONFIG --cflags "QJson >= 0.8.1" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$qjson_LIBS"; then + pkg_cv_qjson_LIBS="$qjson_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"QJson >= 0.8.1\""; } >&5 + ($PKG_CONFIG --exists --print-errors "QJson >= 0.8.1") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_qjson_LIBS=`$PKG_CONFIG --libs "QJson >= 0.8.1" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + qjson_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "QJson >= 0.8.1" 2>&1` + else + qjson_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "QJson >= 0.8.1" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$qjson_PKG_ERRORS" >&5 + + as_fn_error $? "Package requirements (QJson >= 0.8.1) were not met: + +$qjson_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +Alternatively, you may set the environment variables qjson_CFLAGS +and qjson_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details." "$LINENO" 5 +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +Alternatively, you may set the environment variables qjson_CFLAGS +and qjson_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details. + +To get pkg-config, see . +See \`config.log' for more details" "$LINENO" 5; } +else + qjson_CFLAGS=$pkg_cv_qjson_CFLAGS + qjson_LIBS=$pkg_cv_qjson_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + CPPFLAGS="$qjson_CFLAGS $CPPFLAGS" + LIBS="$qjson_LIBS $LIBS" +fi + QBT_ADD_CONFIG="$QBT_ADD_CONFIG usesystemqjson" ;; #( + *) : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_qjson" >&5 +$as_echo "$with_qjson" >&6; } + as_fn_error $? "Unknown option \"$with_qjson\". Use either \"system\" or \"shipped\"." "$LINENO" 5 ;; +esac + +fi + pkg_failed=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zlib" >&5 diff --git a/configure.ac b/configure.ac index 348d888d9..37f74f93c 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,12 @@ AC_ARG_WITH(qtsingleapplication, [], [with_qtsingleapplication=shipped]) +AC_ARG_WITH(qjson, + [AS_HELP_STRING([--with-qjson=@<:@system|shipped@:>@], + [Use the shipped qjson library or the system one (default=shipped) (Qt4 only])], + [], + [with_qjson=shipped]) + AC_ARG_ENABLE(debug, [AS_HELP_STRING([--enable-debug], [Enable debug build])], @@ -214,6 +220,23 @@ AS_CASE(["x$with_qtsingleapplication"], [AC_MSG_RESULT([$with_qtsingleapplication]) AC_MSG_ERROR([Unknown option "$with_qtsingleapplication". Use either "system" or "shipped".])]) +AS_IF([test "x$with_qt5" = "xno"], + [AC_MSG_CHECKING([which qjson to use]) + AS_CASE(["x$with_qjson"], + ["xshipped"], + [AC_MSG_RESULT([shipped]) + QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG usesystemqjson"], + ["xsystem"], + [AC_MSG_RESULT([system]) + PKG_CHECK_MODULES(qjson, + [QJson >= 0.8.1], + [CPPFLAGS="$qjson_CFLAGS $CPPFLAGS" + LIBS="$qjson_LIBS $LIBS"]) + QBT_ADD_CONFIG="$QBT_ADD_CONFIG usesystemqjson"], + [AC_MSG_RESULT([$with_qjson]) + AC_MSG_ERROR([Unknown option "$with_qjson". Use either "system" or "shipped".])]) + ]) + PKG_CHECK_MODULES(zlib, [zlib], [CPPFLAGS="$zlib_CFLAGS $CPPFLAGS" diff --git a/src/app/application.cpp b/src/app/application.cpp index 73470159f..fd81a1559 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -50,7 +50,7 @@ #endif // DISABLE_GUI #ifndef DISABLE_WEBUI -#include "webui.h" +#include "../webui/webui.h" #endif #include "application.h" diff --git a/src/webui/jsonutils.h b/src/webui/jsonutils.h index b8619dc66..55288278e 100644 --- a/src/webui/jsonutils.h +++ b/src/webui/jsonutils.h @@ -36,8 +36,13 @@ #include #else #include +#ifndef USE_SYSTEM_QJSON #include "qjson/parser.h" #include "qjson/serializer.h" +#else // USE_SYSTEM_QJSON +#include +#include +#endif // USE_SYSTEM_QJSON #endif namespace json { diff --git a/src/webui/webui.pri b/src/webui/webui.pri index 1c36c4a9c..8aa1a2887 100644 --- a/src/webui/webui.pri +++ b/src/webui/webui.pri @@ -1,5 +1,3 @@ -INCLUDEPATH += $$PWD - HEADERS += \ $$PWD/webui.h \ $$PWD/btjson.h \ @@ -20,6 +18,9 @@ SOURCES += \ $$PWD/abstractwebapplication.cpp # QJson JSON parser/serializer for using with Qt4 -lessThan(QT_MAJOR_VERSION, 5): include(qjson/qjson.pri) +lessThan(QT_MAJOR_VERSION, 5) { + !usesystemqjson: include(qjson/qjson.pri) + else: DEFINES += USE_SYSTEM_QJSON +} RESOURCES += $$PWD/webui.qrc