2 AC_INIT([qbittorrent], [v4.4.0alpha], [bugs.qbittorrent.org], [], [https://www.qbittorrent.org/])
3 AC_CONFIG_AUX_DIR([build-aux])
4 AC_CONFIG_MACRO_DIR([m4])
14 # use compiler from env variables if available
18 # Define --wth-* and --enable-* arguments
21 [AS_HELP_STRING([--enable-debug],
22 [Enable debug build])],
26 AC_ARG_ENABLE(stacktrace,
27 [AS_HELP_STRING([--enable-stacktrace],
28 [Enable stacktrace feature (default=auto)])],
30 [enable_stacktrace=auto])
33 [AS_HELP_STRING([--disable-gui],
34 [Disable the GUI for headless running. Disables QtDBus and the GeoIP Database.])],
38 AC_ARG_ENABLE(systemd,
39 [AS_HELP_STRING([--enable-systemd],
40 [Install the systemd service file (headless only).])],
45 [AS_HELP_STRING([--disable-webui],
46 [Disable the WebUI.])],
50 AC_ARG_ENABLE(qt-dbus,
51 [AS_HELP_STRING([--disable-qt-dbus],
52 [Disable use of QtDBus (GUI only)])],
57 AC_MSG_CHECKING([whether OS is FreeBSD])
58 AS_IF([expr "$host_os" : ".*freebsd.*" > /dev/null],
60 LIBS="-lexecinfo $LIBS"],
61 [AC_MSG_RESULT([no])])
63 AC_MSG_CHECKING([whether OS is macOS])
64 AS_IF([expr "$host_os" : ".*darwin.*" > /dev/null],
67 [AC_MSG_RESULT([no])])
69 # Require 0.23 pkg-config
70 PKG_PROG_PKG_CONFIG([0.23])
71 AS_IF([test "x$PKG_CONFIG" = "x"],
72 [AC_MSG_ERROR([Could not find pkg-config])])
74 # Check which arguments were set and act accordingly
75 AC_MSG_CHECKING([whether to enable the Debug build])
76 AS_CASE(["x$enable_debug"],
79 QBT_ADD_CONFIG="$QBT_ADD_CONFIG release"
80 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG debug"],
83 QBT_ADD_CONFIG="$QBT_ADD_CONFIG debug"
84 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG release"],
85 [AC_MSG_RESULT([$enable_debug])
86 AC_MSG_ERROR([Unknown option "$enable_debug". Use either "yes" or "no".])])
88 AC_MSG_CHECKING([whether to enable the stacktrace feature])
89 AS_CASE(["x$enable_stacktrace"],
92 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"],
95 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
97 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <execinfo.h>]])],
99 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
101 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"])],
102 [AC_MSG_RESULT([$enable_stacktrace])
103 AC_MSG_ERROR([Unknown option "$enable_stacktrace". Use either "yes" or "no".])])
105 AC_MSG_CHECKING([whether to enable the GUI])
106 AS_CASE(["x$enable_gui"],
108 [AC_MSG_RESULT([yes])
110 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nogui"],
114 QBT_ADD_CONFIG="$QBT_ADD_CONFIG nogui"],
115 [AC_MSG_RESULT([$enable_gui])
116 AC_MSG_ERROR([Unknown option "$enable_gui". Use either "yes" or "no".])])
118 AC_MSG_CHECKING([whether to install the systemd service file])
119 AS_CASE(["x$enable_systemd"],
121 [AC_MSG_RESULT([yes])
122 QBT_ADD_CONFIG="$QBT_ADD_CONFIG systemd"],
125 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG systemd"],
126 [AC_MSG_RESULT([$enable_systemd])
127 AC_MSG_ERROR([Unknown option "$enable_systemd". Use either "yes" or "no".])])
129 AC_MSG_CHECKING([whether to enable the WebUI])
130 AS_CASE(["x$enable_webui"],
132 [AC_MSG_RESULT([yes])
133 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nowebui"],
136 QBT_ADD_CONFIG="$QBT_ADD_CONFIG nowebui"],
137 [AC_MSG_RESULT([$enable_webui])
138 AC_MSG_ERROR([Unknown option "$enable_webui". Use either "yes" or "no".])])
141 AS_IF([test "x$QT_QMAKE" = "x"],
142 [AC_MSG_ERROR([Could not find qmake])
144 AS_IF([test "x$enable_gui" = "xyes"],
145 [PKG_CHECK_MODULES(Qt5Svg, [Qt5Svg >= 5.15.2])
147 AC_MSG_CHECKING([whether QtDBus should be enabled])
148 AS_CASE(["x$enable_qt_dbus"],
150 [AC_MSG_RESULT([yes])
152 AS_IF([test "x$HAVE_QTDBUS" = "xfalse"],
153 [AC_MSG_ERROR([Could not find QtDBus])],
154 [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus"]
158 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG dbus"],
159 [AC_MSG_RESULT([$enable_qt_dbus])
160 AC_MSG_ERROR([Unknown option "$enable_qt_dbus". Use either "yes" or "no".])])
163 AX_BOOST_BASE([1.65],
164 [AC_MSG_NOTICE([Boost CXXFLAGS: "$BOOST_CPPFLAGS"])
165 AC_MSG_NOTICE([Boost LDFLAGS: "$BOOST_LDFLAGS"])],
166 [AC_MSG_ERROR([Could not find Boost])])
167 CXXFLAGS="$BOOST_CPPFLAGS $CXXFLAGS"
168 LDFLAGS="$BOOST_LDFLAGS $LDFLAGS"
170 # add workaround for problematic boost version
171 # taken from ax_boost_base.m4
172 m4_define([DETECT_BOOST_VERSION_PROGRAM],
173 [AC_LANG_PROGRAM([[#include <boost/version.hpp>]],
174 [[(void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))]));]])])
176 AC_COMPILE_IFELSE([DETECT_BOOST_VERSION_PROGRAM(106000)], [],
177 [QBT_ADD_DEFINES="$QBT_ADD_DEFINES BOOST_NO_CXX11_RVALUE_REFERENCES"])
179 PKG_CHECK_MODULES(libtorrent,
180 [libtorrent-rasterbar >= 2.0.4],
181 [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS" QBT_ADD_DEFINES="$QBT_ADD_DEFINES QBT_USES_LIBTORRENT2"],
182 [PKG_CHECK_MODULES(libtorrent,
183 [libtorrent-rasterbar >= 1.2.14 libtorrent-rasterbar < 2],
184 [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"])])
186 PKG_CHECK_MODULES(openssl,
188 [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
189 LIBS="$openssl_LIBS $LIBS"])
191 PKG_CHECK_MODULES(zlib,
193 [CXXFLAGS="$zlib_CFLAGS $CXXFLAGS"
194 LIBS="$zlib_LIBS $LIBS"])
196 # Check if already in >= C++17 mode because of the flags returned by one of the above packages
197 TMP_CXXFLAGS="$CXXFLAGS"
199 AC_MSG_CHECKING([if compiler defaults to C++17 or later mode])
200 AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
201 [AC_MSG_RESULT([yes])
202 QBT_CXX17_FOUND="yes"],
204 QBT_CXX17_FOUND="no"])
206 # In case of no, check if the compiler can support at least C++17
207 # and if yes, enable it leaving a warning to the user
208 AS_IF([test "x$QBT_CXX17_FOUND" = "xno"],
209 [AC_MSG_CHECKING([if compiler supports C++17])
210 CXXFLAGS="-std=c++17"
211 AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
212 [AC_MSG_RESULT([yes])
213 AC_MSG_CHECKING([if C++17 is disabled by the set compiler flags])
214 # prepend the flag so it won't override conflicting user defined flags
215 CXXFLAGS="-std=c++17 $TMP_CXXFLAGS"
216 AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
218 QBT_ADD_CONFIG="$QBT_ADD_CONFIG c++17"
219 AC_MSG_WARN([C++17 mode is now force enabled. The C++ mode should match the mode that other libraries were built with, otherwise you'll likely get linking errors.])],
220 [AC_MSG_RESULT([yes])
221 AC_MSG_ERROR([The compiler supports C++17 but the user or a dependency has explicitly enabled a lower mode.])])],
223 AC_MSG_ERROR([A compiler supporting C++17 is required.])])
225 CXXFLAGS="$TMP_CXXFLAGS"
227 # These are required because autoconf doesn't expand these **particular**
228 # vars automatically. And qmake cannot autoexpand them.
229 AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])
230 AX_DEFINE_DIR([EXPAND_BINDIR], [bindir])
231 AX_DEFINE_DIR([EXPAND_DATADIR], [datadir])
232 AX_DEFINE_DIR([EXPAND_MANDIR], [mandir])
234 # Original extract() function contributed by pmzqla
235 # $*: Strings to parse
236 # Set $QBT_CONF_DEFINES, $QBT_CONF_INCLUDES, $QBT_CONF_EXTRA_CFLAGS
238 if [[ -z "$*" ]]; then
239 echo "Input string required"
243 # BSD sed needs an actual newline character in the substitute command
246 # Convert " -" to "\n" if not between quotes and remove possible leading white spaces
247 string=$(echo " $*" | $SED -e "s: -:\\${new_line}:g" -e 's:"\(.*\)\n\(.*\)":\"\1 -\2":g' -e "s:'\(.*\)\n\(.*\)':\'\1 -\2':g" -e 's/^[[[:space:]]]*//')
251 case "$(echo "$i" | cut -c1)" in
253 D) QBT_CONF_DEFINES="$QBT_CONF_DEFINES $(echo $i | cut -c2-)";;
254 I) QBT_CONF_INCLUDES="$QBT_CONF_INCLUDES $(echo $i | cut -c2-)";;
255 *) QBT_CONF_EXTRA_CFLAGS="$QBT_CONF_EXTRA_CFLAGS -$i";;
261 extract "$CFLAGS $CXXFLAGS"
262 QBT_ADD_DEFINES="$QBT_ADD_DEFINES $QBT_CONF_DEFINES"
264 # Substitute the values of these vars in conf.pri.in
267 AC_SUBST(QBT_CONF_INCLUDES)
268 AC_SUBST(QBT_CONF_EXTRA_CFLAGS)
269 AC_SUBST(QBT_ADD_CONFIG)
270 AC_SUBST(QBT_REMOVE_CONFIG)
271 AC_SUBST(QBT_ADD_DEFINES)
272 AC_SUBST(QBT_REMOVE_DEFINES)
274 QBT_CONFIG_FILES="conf.pri"
276 AS_IF([test "x$enable_systemd" = "xyes"],
277 [QBT_CONFIG_FILES="$QBT_CONFIG_FILES dist/unix/systemd/qbittorrent-nox@.service"])
279 AC_CONFIG_FILES(["$QBT_CONFIG_FILES"])
282 AC_MSG_NOTICE([Running qmake to generate the makefile...])
283 TOPDIR="$(cd "$(dirname "$0")" && pwd)"
284 $QT_QMAKE -r "$TOPDIR/qbittorrent.pro" "QMAKE_LRELEASE=$QMAKE_LRELEASE"
288 AS_IF([test "x$qmake_ret" != "x0"],
289 [AC_MSG_ERROR([$QT_QMAKE failed to generate the makefile])])
291 AC_MSG_NOTICE([Good, the configure finished.])