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])
11 # use compiler from env variables if available
15 # Define --wth-* and --enable-* arguments
18 [AS_HELP_STRING([--enable-debug],
19 [Enable debug build])],
23 AC_ARG_ENABLE(stacktrace,
24 [AS_HELP_STRING([--enable-stacktrace],
25 [Enable stacktrace feature (default=auto)])],
27 [enable_stacktrace=auto])
30 [AS_HELP_STRING([--disable-gui],
31 [Disable the GUI for headless running. Disables QtDBus and the GeoIP Database.])],
35 AC_ARG_ENABLE(systemd,
36 [AS_HELP_STRING([--enable-systemd],
37 [Install the systemd service file (headless only).])],
42 [AS_HELP_STRING([--disable-webui],
43 [Disable the WebUI.])],
47 AC_ARG_ENABLE(qt-dbus,
48 [AS_HELP_STRING([--disable-qt-dbus],
49 [Disable use of QtDBus (GUI only)])],
54 AC_MSG_CHECKING([whether OS is FreeBSD])
55 AS_IF([expr "$host_os" : ".*freebsd.*" > /dev/null],
57 LIBS="-lexecinfo $LIBS"],
58 [AC_MSG_RESULT([no])])
60 AC_MSG_CHECKING([whether OS is macOS])
61 AS_IF([expr "$host_os" : ".*darwin.*" > /dev/null],
64 [AC_MSG_RESULT([no])])
66 # Require 0.23 pkg-config
67 PKG_PROG_PKG_CONFIG([0.23])
68 AS_IF([test "x$PKG_CONFIG" = "x"],
69 [AC_MSG_ERROR([Could not find pkg-config])])
71 # Check which arguments were set and act accordingly
72 AC_MSG_CHECKING([whether to enable the Debug build])
73 AS_CASE(["x$enable_debug"],
76 QBT_ADD_CONFIG="$QBT_ADD_CONFIG release"
77 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG debug"],
80 QBT_ADD_CONFIG="$QBT_ADD_CONFIG debug"
81 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG release"],
82 [AC_MSG_RESULT([$enable_debug])
83 AC_MSG_ERROR([Unknown option "$enable_debug". Use either "yes" or "no".])])
85 AC_MSG_CHECKING([whether to enable the stacktrace feature])
86 AS_CASE(["x$enable_stacktrace"],
89 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"],
92 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
94 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <execinfo.h>]])],
96 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
98 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"])],
99 [AC_MSG_RESULT([$enable_stacktrace])
100 AC_MSG_ERROR([Unknown option "$enable_stacktrace". Use either "yes" or "no".])])
102 AC_MSG_CHECKING([whether to enable the GUI])
103 AS_CASE(["x$enable_gui"],
105 [AC_MSG_RESULT([yes])
107 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nogui"],
111 QBT_ADD_CONFIG="$QBT_ADD_CONFIG nogui"],
112 [AC_MSG_RESULT([$enable_gui])
113 AC_MSG_ERROR([Unknown option "$enable_gui". Use either "yes" or "no".])])
115 AC_MSG_CHECKING([whether to install the systemd service file])
116 AS_CASE(["x$enable_systemd"],
118 [AC_MSG_RESULT([yes])
119 QBT_ADD_CONFIG="$QBT_ADD_CONFIG systemd"],
122 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG systemd"],
123 [AC_MSG_RESULT([$enable_systemd])
124 AC_MSG_ERROR([Unknown option "$enable_systemd". Use either "yes" or "no".])])
126 AC_MSG_CHECKING([whether to enable the WebUI])
127 AS_CASE(["x$enable_webui"],
129 [AC_MSG_RESULT([yes])
130 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nowebui"],
133 QBT_ADD_CONFIG="$QBT_ADD_CONFIG nowebui"],
134 [AC_MSG_RESULT([$enable_webui])
135 AC_MSG_ERROR([Unknown option "$enable_webui". Use either "yes" or "no".])])
138 AS_IF([test "x$QT_QMAKE" = "x"],
139 [AC_MSG_ERROR([Could not find qmake])
141 AS_IF([test "x$enable_gui" = "xyes"],
142 [PKG_CHECK_MODULES(Qt5Svg, [Qt5Svg >= 5.5.1])
144 AC_MSG_CHECKING([whether QtDBus should be enabled])
145 AS_CASE(["x$enable_qt_dbus"],
147 [AC_MSG_RESULT([yes])
149 AS_IF([test "x$HAVE_QTDBUS" = "xfalse"],
150 [AC_MSG_ERROR([Could not find QtDBus])],
151 [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus"]
155 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG dbus"],
156 [AC_MSG_RESULT([$enable_qt_dbus])
157 AC_MSG_ERROR([Unknown option "$enable_qt_dbus". Use either "yes" or "no".])])
160 AX_BOOST_BASE([1.40],
161 [AC_MSG_NOTICE([Boost CXXFLAGS: "$BOOST_CPPFLAGS"])
162 AC_MSG_NOTICE([Boost LDFLAGS: "$BOOST_LDFLAGS"])],
163 [AC_MSG_ERROR([Could not find Boost])])
164 CXXFLAGS="$BOOST_CPPFLAGS $CXXFLAGS"
165 LDFLAGS="$BOOST_LDFLAGS $LDFLAGS"
167 # add workaround for problematic boost version
168 # taken from ax_boost_base.m4
169 m4_define([DETECT_BOOST_VERSION_PROGRAM],
170 [AC_LANG_PROGRAM([[#include <boost/version.hpp>]],
171 [[(void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))]));]])])
173 AC_COMPILE_IFELSE([DETECT_BOOST_VERSION_PROGRAM(106000)], [],
174 [QBT_ADD_DEFINES="$QBT_ADD_DEFINES BOOST_NO_CXX11_RVALUE_REFERENCES"])
177 AC_MSG_NOTICE([Boost.System LIB: "$BOOST_SYSTEM_LIB"])
178 LIBS="$BOOST_SYSTEM_LIB $LIBS"
180 PKG_CHECK_MODULES(libtorrent,
181 [libtorrent-rasterbar >= 1.2],
182 [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS"
183 LIBS="$libtorrent_LIBS $LIBS"])
185 PKG_CHECK_MODULES(openssl,
187 [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
188 LIBS="$openssl_LIBS $LIBS"])
190 PKG_CHECK_MODULES(zlib,
192 [CXXFLAGS="$zlib_CFLAGS $CXXFLAGS"
193 LIBS="$zlib_LIBS $LIBS"])
195 # Check if already in >= C++14 mode because of the flags returned by one of the above packages
196 TMP_CXXFLAGS="$CXXFLAGS"
198 AC_MSG_CHECKING([if compiler defaults to C++14 or later mode])
199 AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
200 [AC_MSG_RESULT([yes])
201 QBT_CXX14_FOUND="yes"],
203 QBT_CXX14_FOUND="no"])
205 # In case of no, check if the compiler can support at least C++14
206 # and if yes, enable it leaving a warning to the user
207 AS_IF([test "x$QBT_CXX14_FOUND" = "xno"],
208 [AC_MSG_CHECKING([if compiler supports C++14])
209 CXXFLAGS="-std=c++14"
210 AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
211 [AC_MSG_RESULT([yes])
212 AC_MSG_CHECKING([if C++14 is disabled by the set compiler flags])
213 # prepend the flag so it won't override conflicting user defined flags
214 CXXFLAGS="-std=c++14 $TMP_CXXFLAGS"
215 AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
217 QBT_ADD_CONFIG="$QBT_ADD_CONFIG c++14"
218 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.])],
219 [AC_MSG_RESULT([yes])
220 AC_MSG_ERROR([The compiler supports C++14 but the user or a dependency has explicitly enabled a lower mode.])])],
222 AC_MSG_ERROR([A compiler supporting C++14 is required.])])
224 CXXFLAGS="$TMP_CXXFLAGS"
226 # These are required because autoconf doesn't expand these **particular**
227 # vars automatically. And qmake cannot autoexpand them.
228 AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])
229 AX_DEFINE_DIR([EXPAND_BINDIR], [bindir])
230 AX_DEFINE_DIR([EXPAND_DATADIR], [datadir])
231 AX_DEFINE_DIR([EXPAND_MANDIR], [mandir])
233 # Original extract() function contributed by pmzqla
234 # $*: Strings to parse
235 # Set $QBT_CONF_DEFINES, $QBT_CONF_INCLUDES, $QBT_CONF_EXTRA_CFLAGS
237 if [[ -z "$*" ]]; then
238 echo "Input string required"
242 # BSD sed needs an actual newline character in the substitute command
245 # Convert " -" to "\n" if not between quotes and remove possible leading white spaces
246 string=$(echo " $*" | $SED -e "s: -:\\${new_line}:g" -e 's:"\(.*\)\n\(.*\)":\"\1 -\2":g' -e "s:'\(.*\)\n\(.*\)':\'\1 -\2':g" -e 's/^[[[:space:]]]*//')
250 case "$(echo "$i" | cut -c1)" in
252 D) QBT_CONF_DEFINES="$QBT_CONF_DEFINES $(echo $i | cut -c2-)";;
253 I) QBT_CONF_INCLUDES="$QBT_CONF_INCLUDES $(echo $i | cut -c2-)";;
254 *) QBT_CONF_EXTRA_CFLAGS="$QBT_CONF_EXTRA_CFLAGS -$i";;
260 extract "$CFLAGS $CXXFLAGS"
261 QBT_ADD_DEFINES="$QBT_ADD_DEFINES $QBT_CONF_DEFINES"
263 # Substitute the values of these vars in conf.pri.in
266 AC_SUBST(QBT_CONF_INCLUDES)
267 AC_SUBST(QBT_CONF_EXTRA_CFLAGS)
268 AC_SUBST(QBT_ADD_CONFIG)
269 AC_SUBST(QBT_REMOVE_CONFIG)
270 AC_SUBST(QBT_ADD_DEFINES)
271 AC_SUBST(QBT_REMOVE_DEFINES)
274 AS_IF([test "x$enable_systemd" = "xyes"],
275 [AC_OUTPUT(dist/unix/systemd/qbittorrent-nox@.service)])
277 AC_MSG_NOTICE([Running qmake to generate the makefile...])
278 TOPDIR="$(cd "$(dirname "$0")" && pwd)"
279 $QT_QMAKE -r "$TOPDIR/qbittorrent.pro" "QMAKE_LRELEASE=$QMAKE_LRELEASE"
283 AS_IF([test "x$qmake_ret" != "x0"],
284 [AC_MSG_ERROR([$QT_QMAKE failed to generate the makefile])])
286 AC_MSG_NOTICE([Good, the configure finished.])