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])
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 AC_COMPILE_IFELSE([DETECT_BOOST_VERSION_PROGRAM(106000)], [],
191 [QBT_ADD_DEFINES="$QBT_ADD_DEFINES BOOST_NO_CXX11_RVALUE_REFERENCES"])
193 PKG_CHECK_MODULES(libtorrent,
194 [libtorrent-rasterbar >= 2.0.4],
195 [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS" QBT_ADD_DEFINES="$QBT_ADD_DEFINES QBT_USES_LIBTORRENT2"],
196 [PKG_CHECK_MODULES(libtorrent,
197 [libtorrent-rasterbar >= 1.2.14 libtorrent-rasterbar < 2],
198 [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"])])
200 PKG_CHECK_MODULES(openssl,
202 [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
203 LIBS="$openssl_LIBS $LIBS"])
205 PKG_CHECK_MODULES(zlib,
207 [CXXFLAGS="$zlib_CFLAGS $CXXFLAGS"
208 LIBS="$zlib_LIBS $LIBS"])
210 # Check if already in >= C++17 mode because of the flags returned by one of the above packages
211 TMP_CXXFLAGS="$CXXFLAGS"
213 AC_MSG_CHECKING([if compiler defaults to C++17 or later mode])
214 AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
215 [AC_MSG_RESULT([yes])
216 QBT_CXX17_FOUND="yes"],
218 QBT_CXX17_FOUND="no"])
220 # In case of no, check if the compiler can support at least C++17
221 # and if yes, enable it leaving a warning to the user
222 AS_IF([test "x$QBT_CXX17_FOUND" = "xno"],
223 [AC_MSG_CHECKING([if compiler supports C++17])
224 CXXFLAGS="-std=c++17"
225 AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
226 [AC_MSG_RESULT([yes])
227 AC_MSG_CHECKING([if C++17 is disabled by the set compiler flags])
228 # prepend the flag so it won't override conflicting user defined flags
229 CXXFLAGS="-std=c++17 $TMP_CXXFLAGS"
230 AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
232 QBT_ADD_CONFIG="$QBT_ADD_CONFIG c++17"
233 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.])],
234 [AC_MSG_RESULT([yes])
235 AC_MSG_ERROR([The compiler supports C++17 but the user or a dependency has explicitly enabled a lower mode.])])],
237 AC_MSG_ERROR([A compiler supporting C++17 is required.])])
239 CXXFLAGS="$TMP_CXXFLAGS"
241 # These are required because autoconf doesn't expand these **particular**
242 # vars automatically. And qmake cannot autoexpand them.
243 AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])
244 AX_DEFINE_DIR([EXPAND_BINDIR], [bindir])
245 AX_DEFINE_DIR([EXPAND_DATADIR], [datadir])
246 AX_DEFINE_DIR([EXPAND_MANDIR], [mandir])
248 # Original extract() function contributed by pmzqla
249 # $*: Strings to parse
250 # Set $QBT_CONF_DEFINES, $QBT_CONF_INCLUDES, $QBT_CONF_EXTRA_CFLAGS
252 if [[ -z "$*" ]]; then
253 echo "Input string required"
257 # BSD sed needs an actual newline character in the substitute command
260 # Convert " -" to "\n" if not between quotes and remove possible leading white spaces
261 string=$(echo " $*" | $SED -e "s: -:\\${new_line}:g" -e 's:"\(.*\)\n\(.*\)":\"\1 -\2":g' -e "s:'\(.*\)\n\(.*\)':\'\1 -\2':g" -e 's/^[[[:space:]]]*//')
265 case "$(echo "$i" | cut -c1)" in
267 D) QBT_CONF_DEFINES="$QBT_CONF_DEFINES $(echo $i | cut -c2-)";;
268 I) QBT_CONF_INCLUDES="$QBT_CONF_INCLUDES $(echo $i | cut -c2-)";;
269 *) QBT_CONF_EXTRA_CFLAGS="$QBT_CONF_EXTRA_CFLAGS -$i";;
275 extract "$CFLAGS $CXXFLAGS"
276 QBT_ADD_DEFINES="$QBT_ADD_DEFINES $QBT_CONF_DEFINES"
278 # Substitute the values of these vars in conf.pri.in
281 AC_SUBST(QBT_CONF_INCLUDES)
282 AC_SUBST(QBT_CONF_EXTRA_CFLAGS)
283 AC_SUBST(QBT_ADD_CONFIG)
284 AC_SUBST(QBT_REMOVE_CONFIG)
285 AC_SUBST(QBT_ADD_DEFINES)
286 AC_SUBST(QBT_REMOVE_DEFINES)
288 QBT_CONFIG_FILES="conf.pri"
290 AS_IF([test "x$enable_systemd" = "xyes"],
291 [QBT_CONFIG_FILES="$QBT_CONFIG_FILES dist/unix/systemd/qbittorrent-nox@.service"])
293 AC_CONFIG_FILES(["$QBT_CONFIG_FILES"])
296 AC_MSG_NOTICE([Running qmake to generate the makefile...])
297 TOPDIR="$(cd "$(dirname "$0")" && pwd)"
298 $QT_QMAKE -r "$TOPDIR/qbittorrent.pro" "QMAKE_LRELEASE=$QMAKE_LRELEASE"
302 AS_IF([test "x$qmake_ret" != "x0"],
303 [AC_MSG_ERROR([$QT_QMAKE failed to generate the makefile])])
305 AC_MSG_NOTICE([Good, the configure finished.])