1 AC_INIT([qbittorrent], [v4.5.0alpha], [bugs.qbittorrent.org], [], [https://www.qbittorrent.org/])
2 AC_CONFIG_AUX_DIR([build-aux])
3 AC_CONFIG_MACRO_DIR([m4])
11 AM_INIT_AUTOMAKE([foreign])
13 # use compiler from env variables if available
17 # Define --wth-* and --enable-* arguments
20 [AS_HELP_STRING([--enable-debug],
21 [Enable debug build])],
25 AC_ARG_ENABLE(stacktrace,
26 [AS_HELP_STRING([--enable-stacktrace],
27 [Enable stacktrace feature (default=auto)])],
29 [enable_stacktrace=auto])
32 [AS_HELP_STRING([--disable-gui],
33 [Disable the GUI for headless running. Disables QtDBus and the GeoIP Database.])],
37 AC_ARG_ENABLE(systemd,
38 [AS_HELP_STRING([--enable-systemd],
39 [Install the systemd service file (headless only).])],
44 [AS_HELP_STRING([--disable-webui],
45 [Disable the WebUI.])],
49 AC_ARG_ENABLE(qt-dbus,
50 [AS_HELP_STRING([--disable-qt-dbus],
51 [Disable use of QtDBus (GUI only)])],
56 AC_MSG_CHECKING([whether to enable specific tweaks for current host "$host_os"])
65 LIBS="-lexecinfo $LIBS"
70 LIBS="-lnetwork $LIBS"
75 LIBS="-lexecinfo $LIBS"
83 # Require 0.23 pkg-config
84 PKG_PROG_PKG_CONFIG([0.23])
85 AS_IF([test "x$PKG_CONFIG" = "x"],
86 [AC_MSG_ERROR([Could not find pkg-config])])
88 # Check which arguments were set and act accordingly
89 AC_MSG_CHECKING([whether to enable the Debug build])
90 AS_CASE(["x$enable_debug"],
93 QBT_ADD_CONFIG="$QBT_ADD_CONFIG release"
94 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG debug"],
97 QBT_ADD_CONFIG="$QBT_ADD_CONFIG debug"
98 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG release"],
99 [AC_MSG_RESULT([$enable_debug])
100 AC_MSG_ERROR([Unknown option "$enable_debug". Use either "yes" or "no".])])
102 AC_MSG_CHECKING([whether to enable the stacktrace feature])
103 AS_CASE(["x$enable_stacktrace"],
106 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"],
108 [AC_MSG_RESULT([yes])
109 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
111 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <execinfo.h>]])],
112 [AC_MSG_RESULT([yes])
113 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
115 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"])],
116 [AC_MSG_RESULT([$enable_stacktrace])
117 AC_MSG_ERROR([Unknown option "$enable_stacktrace". Use either "yes" or "no".])])
119 AC_MSG_CHECKING([whether to enable the GUI])
120 AS_CASE(["x$enable_gui"],
122 [AC_MSG_RESULT([yes])
124 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nogui"],
128 QBT_ADD_CONFIG="$QBT_ADD_CONFIG nogui"],
129 [AC_MSG_RESULT([$enable_gui])
130 AC_MSG_ERROR([Unknown option "$enable_gui". Use either "yes" or "no".])])
132 AC_MSG_CHECKING([whether to install the systemd service file])
133 AS_CASE(["x$enable_systemd"],
135 [AC_MSG_RESULT([yes])
136 QBT_ADD_CONFIG="$QBT_ADD_CONFIG systemd"],
139 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG systemd"],
140 [AC_MSG_RESULT([$enable_systemd])
141 AC_MSG_ERROR([Unknown option "$enable_systemd". Use either "yes" or "no".])])
143 AC_MSG_CHECKING([whether to enable the WebUI])
144 AS_CASE(["x$enable_webui"],
146 [AC_MSG_RESULT([yes])
147 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nowebui"],
150 QBT_ADD_CONFIG="$QBT_ADD_CONFIG nowebui"],
151 [AC_MSG_RESULT([$enable_webui])
152 AC_MSG_ERROR([Unknown option "$enable_webui". Use either "yes" or "no".])])
155 AS_IF([test "x$QT_QMAKE" = "x"],
156 [AC_MSG_ERROR([Could not find qmake])
158 AS_IF([test "x$enable_gui" = "xyes"],
159 [PKG_CHECK_MODULES(Qt5Svg, [Qt5Svg >= 5.15.2])
161 AC_MSG_CHECKING([whether QtDBus should be enabled])
162 AS_CASE(["x$enable_qt_dbus"],
164 [AC_MSG_RESULT([yes])
166 AS_IF([test "x$HAVE_QTDBUS" = "xfalse"],
167 [AC_MSG_ERROR([Could not find QtDBus])],
168 [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus"]
172 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG dbus"],
173 [AC_MSG_RESULT([$enable_qt_dbus])
174 AC_MSG_ERROR([Unknown option "$enable_qt_dbus". Use either "yes" or "no".])])
177 AX_BOOST_BASE([1.65],
178 [AC_MSG_NOTICE([Boost CXXFLAGS: "$BOOST_CPPFLAGS"])
179 AC_MSG_NOTICE([Boost LDFLAGS: "$BOOST_LDFLAGS"])],
180 [AC_MSG_ERROR([Could not find Boost])])
181 CXXFLAGS="$BOOST_CPPFLAGS $CXXFLAGS"
182 LDFLAGS="$BOOST_LDFLAGS $LDFLAGS"
184 # add workaround for problematic boost version
185 # taken from ax_boost_base.m4
186 m4_define([DETECT_BOOST_VERSION_PROGRAM],
187 [AC_LANG_PROGRAM([[#include <boost/version.hpp>]],
188 [[(void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))]));]])])
190 PKG_CHECK_MODULES(libtorrent,
191 [libtorrent-rasterbar >= 2.0.4],
192 [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS" QBT_ADD_DEFINES="$QBT_ADD_DEFINES QBT_USES_LIBTORRENT2"],
193 [PKG_CHECK_MODULES(libtorrent,
194 [libtorrent-rasterbar >= 1.2.14 libtorrent-rasterbar < 2],
195 [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"])])
197 PKG_CHECK_MODULES(openssl,
199 [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
200 LIBS="$openssl_LIBS $LIBS"])
202 PKG_CHECK_MODULES(zlib,
204 [CXXFLAGS="$zlib_CFLAGS $CXXFLAGS"
205 LIBS="$zlib_LIBS $LIBS"])
207 # Check if already in >= C++17 mode because of the flags returned by one of the above packages
208 TMP_CXXFLAGS="$CXXFLAGS"
210 AC_MSG_CHECKING([if compiler defaults to C++17 or later mode])
211 AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
212 [AC_MSG_RESULT([yes])
213 QBT_CXX17_FOUND="yes"],
215 QBT_CXX17_FOUND="no"])
217 # In case of no, check if the compiler can support at least C++17
218 # and if yes, enable it leaving a warning to the user
219 AS_IF([test "x$QBT_CXX17_FOUND" = "xno"],
220 [AC_MSG_CHECKING([if compiler supports C++17])
221 CXXFLAGS="-std=c++17"
222 AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
223 [AC_MSG_RESULT([yes])
224 AC_MSG_CHECKING([if C++17 is disabled by the set compiler flags])
225 # prepend the flag so it won't override conflicting user defined flags
226 CXXFLAGS="-std=c++17 $TMP_CXXFLAGS"
227 AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
229 QBT_ADD_CONFIG="$QBT_ADD_CONFIG c++17"
230 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.])],
231 [AC_MSG_RESULT([yes])
232 AC_MSG_ERROR([The compiler supports C++17 but the user or a dependency has explicitly enabled a lower mode.])])],
234 AC_MSG_ERROR([A compiler supporting C++17 is required.])])
236 CXXFLAGS="$TMP_CXXFLAGS"
238 # These are required because autoconf doesn't expand these **particular**
239 # vars automatically. And qmake cannot autoexpand them.
240 AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])
241 AX_DEFINE_DIR([EXPAND_BINDIR], [bindir])
242 AX_DEFINE_DIR([EXPAND_DATADIR], [datadir])
243 AX_DEFINE_DIR([EXPAND_MANDIR], [mandir])
245 # Original extract() function contributed by pmzqla
246 # $*: Strings to parse
247 # Set $QBT_CONF_DEFINES, $QBT_CONF_INCLUDES, $QBT_CONF_EXTRA_CFLAGS
249 if [[ -z "$*" ]]; then
250 echo "Input string required"
254 # BSD sed needs an actual newline character in the substitute command
257 # Convert " -" to "\n" if not between quotes and remove possible leading white spaces
258 string=$(echo " $*" | $SED -e "s: -:\\${new_line}:g" -e 's:"\(.*\)\n\(.*\)":\"\1 -\2":g' -e "s:'\(.*\)\n\(.*\)':\'\1 -\2':g" -e 's/^[[[:space:]]]*//')
262 case "$(echo "$i" | cut -c1)" in
264 D) QBT_CONF_DEFINES="$QBT_CONF_DEFINES $(echo $i | cut -c2-)";;
265 I) QBT_CONF_INCLUDES="$QBT_CONF_INCLUDES $(echo $i | cut -c2-)";;
266 *) QBT_CONF_EXTRA_CFLAGS="$QBT_CONF_EXTRA_CFLAGS -$i";;
272 extract "$CFLAGS $CXXFLAGS"
273 QBT_ADD_DEFINES="$QBT_ADD_DEFINES $QBT_CONF_DEFINES"
275 # Substitute the values of these vars in conf.pri.in
278 AC_SUBST(QBT_CONF_INCLUDES)
279 AC_SUBST(QBT_CONF_EXTRA_CFLAGS)
280 AC_SUBST(QBT_ADD_CONFIG)
281 AC_SUBST(QBT_REMOVE_CONFIG)
282 AC_SUBST(QBT_ADD_DEFINES)
283 AC_SUBST(QBT_REMOVE_DEFINES)
285 QBT_CONFIG_FILES="conf.pri"
287 AS_IF([test "x$enable_systemd" = "xyes"],
288 [QBT_CONFIG_FILES="$QBT_CONFIG_FILES dist/unix/systemd/qbittorrent-nox@.service"])
290 AC_CONFIG_FILES(["$QBT_CONFIG_FILES"])
293 AC_MSG_NOTICE([Running qmake to generate the makefile...])
294 TOPDIR="$(cd "$(dirname "$0")" && pwd)"
295 $QT_QMAKE -r "$TOPDIR/qbittorrent.pro" "QMAKE_LRELEASE=$QMAKE_LRELEASE"
299 AS_IF([test "x$qmake_ret" != "x0"],
300 [AC_MSG_ERROR([$QT_QMAKE failed to generate the makefile])])
302 AC_MSG_NOTICE([Good, the configure finished.])