1 AC_INIT([qbittorrent], [v4.4.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 OS is FreeBSD])
57 AS_IF([expr "$host_os" : ".*freebsd.*" > /dev/null],
59 LIBS="-lexecinfo $LIBS"],
60 [AC_MSG_RESULT([no])])
62 AC_MSG_CHECKING([whether OS is macOS])
63 AS_IF([expr "$host_os" : ".*darwin.*" > /dev/null],
66 [AC_MSG_RESULT([no])])
68 # Require 0.23 pkg-config
69 PKG_PROG_PKG_CONFIG([0.23])
70 AS_IF([test "x$PKG_CONFIG" = "x"],
71 [AC_MSG_ERROR([Could not find pkg-config])])
73 # Check which arguments were set and act accordingly
74 AC_MSG_CHECKING([whether to enable the Debug build])
75 AS_CASE(["x$enable_debug"],
78 QBT_ADD_CONFIG="$QBT_ADD_CONFIG release"
79 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG debug"],
82 QBT_ADD_CONFIG="$QBT_ADD_CONFIG debug"
83 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG release"],
84 [AC_MSG_RESULT([$enable_debug])
85 AC_MSG_ERROR([Unknown option "$enable_debug". Use either "yes" or "no".])])
87 AC_MSG_CHECKING([whether to enable the stacktrace feature])
88 AS_CASE(["x$enable_stacktrace"],
91 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"],
94 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
96 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <execinfo.h>]])],
98 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
100 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"])],
101 [AC_MSG_RESULT([$enable_stacktrace])
102 AC_MSG_ERROR([Unknown option "$enable_stacktrace". Use either "yes" or "no".])])
104 AC_MSG_CHECKING([whether to enable the GUI])
105 AS_CASE(["x$enable_gui"],
107 [AC_MSG_RESULT([yes])
109 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nogui"],
113 QBT_ADD_CONFIG="$QBT_ADD_CONFIG nogui"],
114 [AC_MSG_RESULT([$enable_gui])
115 AC_MSG_ERROR([Unknown option "$enable_gui". Use either "yes" or "no".])])
117 AC_MSG_CHECKING([whether to install the systemd service file])
118 AS_CASE(["x$enable_systemd"],
120 [AC_MSG_RESULT([yes])
121 QBT_ADD_CONFIG="$QBT_ADD_CONFIG systemd"],
124 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG systemd"],
125 [AC_MSG_RESULT([$enable_systemd])
126 AC_MSG_ERROR([Unknown option "$enable_systemd". Use either "yes" or "no".])])
128 AC_MSG_CHECKING([whether to enable the WebUI])
129 AS_CASE(["x$enable_webui"],
131 [AC_MSG_RESULT([yes])
132 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nowebui"],
135 QBT_ADD_CONFIG="$QBT_ADD_CONFIG nowebui"],
136 [AC_MSG_RESULT([$enable_webui])
137 AC_MSG_ERROR([Unknown option "$enable_webui". Use either "yes" or "no".])])
140 AS_IF([test "x$QT_QMAKE" = "x"],
141 [AC_MSG_ERROR([Could not find qmake])
143 AS_IF([test "x$enable_gui" = "xyes"],
144 [PKG_CHECK_MODULES(Qt5Svg, [Qt5Svg >= 5.5.1])
146 AC_MSG_CHECKING([whether QtDBus should be enabled])
147 AS_CASE(["x$enable_qt_dbus"],
149 [AC_MSG_RESULT([yes])
151 AS_IF([test "x$HAVE_QTDBUS" = "xfalse"],
152 [AC_MSG_ERROR([Could not find QtDBus])],
153 [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus"]
157 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG dbus"],
158 [AC_MSG_RESULT([$enable_qt_dbus])
159 AC_MSG_ERROR([Unknown option "$enable_qt_dbus". Use either "yes" or "no".])])
162 AX_BOOST_BASE([1.65],
163 [AC_MSG_NOTICE([Boost CXXFLAGS: "$BOOST_CPPFLAGS"])
164 AC_MSG_NOTICE([Boost LDFLAGS: "$BOOST_LDFLAGS"])],
165 [AC_MSG_ERROR([Could not find Boost])])
166 CXXFLAGS="$BOOST_CPPFLAGS $CXXFLAGS"
167 LDFLAGS="$BOOST_LDFLAGS $LDFLAGS"
169 # add workaround for problematic boost version
170 # taken from ax_boost_base.m4
171 m4_define([DETECT_BOOST_VERSION_PROGRAM],
172 [AC_LANG_PROGRAM([[#include <boost/version.hpp>]],
173 [[(void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))]));]])])
175 AC_COMPILE_IFELSE([DETECT_BOOST_VERSION_PROGRAM(106000)], [],
176 [QBT_ADD_DEFINES="$QBT_ADD_DEFINES BOOST_NO_CXX11_RVALUE_REFERENCES"])
179 AC_MSG_NOTICE([Boost.System LIB: "$BOOST_SYSTEM_LIB"])
180 LIBS="$BOOST_SYSTEM_LIB $LIBS"
182 PKG_CHECK_MODULES(libtorrent,
183 [libtorrent-rasterbar >= 1.2.11],
184 [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS"
185 LIBS="$libtorrent_LIBS $LIBS"])
187 PKG_CHECK_MODULES(openssl,
189 [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
190 LIBS="$openssl_LIBS $LIBS"])
192 PKG_CHECK_MODULES(zlib,
194 [CXXFLAGS="$zlib_CFLAGS $CXXFLAGS"
195 LIBS="$zlib_LIBS $LIBS"])
197 # Check if already in >= C++14 mode because of the flags returned by one of the above packages
198 TMP_CXXFLAGS="$CXXFLAGS"
200 AC_MSG_CHECKING([if compiler defaults to C++14 or later mode])
201 AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
202 [AC_MSG_RESULT([yes])
203 QBT_CXX14_FOUND="yes"],
205 QBT_CXX14_FOUND="no"])
207 # In case of no, check if the compiler can support at least C++14
208 # and if yes, enable it leaving a warning to the user
209 AS_IF([test "x$QBT_CXX14_FOUND" = "xno"],
210 [AC_MSG_CHECKING([if compiler supports C++14])
211 CXXFLAGS="-std=c++14"
212 AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
213 [AC_MSG_RESULT([yes])
214 AC_MSG_CHECKING([if C++14 is disabled by the set compiler flags])
215 # prepend the flag so it won't override conflicting user defined flags
216 CXXFLAGS="-std=c++14 $TMP_CXXFLAGS"
217 AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
219 QBT_ADD_CONFIG="$QBT_ADD_CONFIG c++14"
220 AC_MSG_WARN([C++14 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.])],
221 [AC_MSG_RESULT([yes])
222 AC_MSG_ERROR([The compiler supports C++14 but the user or a dependency has explicitly enabled a lower mode.])])],
224 AC_MSG_ERROR([A compiler supporting C++14 is required.])])
226 CXXFLAGS="$TMP_CXXFLAGS"
228 # These are required because autoconf doesn't expand these **particular**
229 # vars automatically. And qmake cannot autoexpand them.
230 AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])
231 AX_DEFINE_DIR([EXPAND_BINDIR], [bindir])
232 AX_DEFINE_DIR([EXPAND_DATADIR], [datadir])
233 AX_DEFINE_DIR([EXPAND_MANDIR], [mandir])
235 # Original extract() function contributed by pmzqla
236 # $*: Strings to parse
237 # Set $QBT_CONF_DEFINES, $QBT_CONF_INCLUDES, $QBT_CONF_EXTRA_CFLAGS
239 if [[ -z "$*" ]]; then
240 echo "Input string required"
244 # BSD sed needs an actual newline character in the substitute command
247 # Convert " -" to "\n" if not between quotes and remove possible leading white spaces
248 string=$(echo " $*" | $SED -e "s: -:\\${new_line}:g" -e 's:"\(.*\)\n\(.*\)":\"\1 -\2":g' -e "s:'\(.*\)\n\(.*\)':\'\1 -\2':g" -e 's/^[[[:space:]]]*//')
252 case "$(echo "$i" | cut -c1)" in
254 D) QBT_CONF_DEFINES="$QBT_CONF_DEFINES $(echo $i | cut -c2-)";;
255 I) QBT_CONF_INCLUDES="$QBT_CONF_INCLUDES $(echo $i | cut -c2-)";;
256 *) QBT_CONF_EXTRA_CFLAGS="$QBT_CONF_EXTRA_CFLAGS -$i";;
262 extract "$CFLAGS $CXXFLAGS"
263 QBT_ADD_DEFINES="$QBT_ADD_DEFINES $QBT_CONF_DEFINES"
265 # Substitute the values of these vars in conf.pri.in
268 AC_SUBST(QBT_CONF_INCLUDES)
269 AC_SUBST(QBT_CONF_EXTRA_CFLAGS)
270 AC_SUBST(QBT_ADD_CONFIG)
271 AC_SUBST(QBT_REMOVE_CONFIG)
272 AC_SUBST(QBT_ADD_DEFINES)
273 AC_SUBST(QBT_REMOVE_DEFINES)
276 AS_IF([test "x$enable_systemd" = "xyes"],
277 [AC_OUTPUT(dist/unix/systemd/qbittorrent-nox@.service)])
279 AC_MSG_NOTICE([Running qmake to generate the makefile...])
280 TOPDIR="$(cd "$(dirname "$0")" && pwd)"
281 $QT_QMAKE -r "$TOPDIR/qbittorrent.pro" "QMAKE_LRELEASE=$QMAKE_LRELEASE"
285 AS_IF([test "x$qmake_ret" != "x0"],
286 [AC_MSG_ERROR([$QT_QMAKE failed to generate the makefile])])
288 AC_MSG_NOTICE([Good, the configure finished.])