1 AC_INIT([qbittorrent], [v4.2.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
17 AC_ARG_WITH(qtsingleapplication,
18 [AS_HELP_STRING([--with-qtsingleapplication=@<:@system|shipped@:>@],
19 [Use the shipped qtsingleapplication library or the system one (default=shipped)])],
21 [with_qtsingleapplication=shipped])
24 [AS_HELP_STRING([--enable-debug],
25 [Enable debug build])],
29 AC_ARG_ENABLE(stacktrace,
30 [AS_HELP_STRING([--enable-stacktrace],
31 [Enable stacktrace feature (default=auto)])],
33 [enable_stacktrace=auto])
36 [AS_HELP_STRING([--disable-gui],
37 [Disable the GUI for headless running. Disables QtDBus and the GeoIP Database.])],
41 AC_ARG_ENABLE(systemd,
42 [AS_HELP_STRING([--enable-systemd],
43 [Install the systemd service file (headless only).])],
48 [AS_HELP_STRING([--disable-webui],
49 [Disable the WebUI.])],
53 AC_ARG_ENABLE(qt-dbus,
54 [AS_HELP_STRING([--disable-qt-dbus],
55 [Disable use of QtDBus (GUI only)])],
60 AC_MSG_CHECKING([whether OS is FreeBSD])
61 AS_IF([expr "$host_os" : ".*freebsd.*" > /dev/null],
63 LIBS="-lexecinfo $LIBS"],
64 [AC_MSG_RESULT([no])])
66 AC_MSG_CHECKING([whether OS is macOS])
67 AS_IF([expr "$host_os" : ".*darwin.*" > /dev/null],
70 [AC_MSG_RESULT([no])])
72 # Require 0.23 pkg-config
73 PKG_PROG_PKG_CONFIG([0.23])
74 AS_IF([test "x$PKG_CONFIG" = "x"],
75 [AC_MSG_ERROR([Could not find pkg-config])])
77 # Check which arguments were set and act accordingly
78 AC_MSG_CHECKING([whether to enable the Debug build])
79 AS_CASE(["x$enable_debug"],
82 QBT_ADD_CONFIG="$QBT_ADD_CONFIG release"
83 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG debug"],
86 QBT_ADD_CONFIG="$QBT_ADD_CONFIG debug"
87 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG release"],
88 [AC_MSG_RESULT([$enable_debug])
89 AC_MSG_ERROR([Unknown option "$enable_debug". Use either "yes" or "no".])])
91 AC_MSG_CHECKING([whether to enable the stacktrace feature])
92 AS_CASE(["x$enable_stacktrace"],
95 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"],
98 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
100 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <execinfo.h>]])],
101 [AC_MSG_RESULT([yes])
102 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
104 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"])],
105 [AC_MSG_RESULT([$enable_stacktrace])
106 AC_MSG_ERROR([Unknown option "$enable_stacktrace". Use either "yes" or "no".])])
108 AC_MSG_CHECKING([whether to enable the GUI])
109 AS_CASE(["x$enable_gui"],
111 [AC_MSG_RESULT([yes])
113 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nogui"],
117 QBT_ADD_CONFIG="$QBT_ADD_CONFIG nogui"],
118 [AC_MSG_RESULT([$enable_gui])
119 AC_MSG_ERROR([Unknown option "$enable_gui". Use either "yes" or "no".])])
121 AC_MSG_CHECKING([whether to install the systemd service file])
122 AS_CASE(["x$enable_systemd"],
124 [AC_MSG_RESULT([yes])
125 QBT_ADD_CONFIG="$QBT_ADD_CONFIG systemd"],
128 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG systemd"],
129 [AC_MSG_RESULT([$enable_systemd])
130 AC_MSG_ERROR([Unknown option "$enable_systemd". Use either "yes" or "no".])])
132 AC_MSG_CHECKING([whether to enable the WebUI])
133 AS_CASE(["x$enable_webui"],
135 [AC_MSG_RESULT([yes])
136 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nowebui"],
139 QBT_ADD_CONFIG="$QBT_ADD_CONFIG nowebui"],
140 [AC_MSG_RESULT([$enable_webui])
141 AC_MSG_ERROR([Unknown option "$enable_webui". Use either "yes" or "no".])])
144 AS_IF([test "x$QT_QMAKE" = "x"],
145 [AC_MSG_ERROR([Could not find qmake])
147 AS_IF([test "x$enable_gui" = "xyes"],
148 [PKG_CHECK_MODULES(Qt5Svg, [Qt5Svg >= 5.5.1])
150 AC_MSG_CHECKING([whether QtDBus should be enabled])
151 AS_CASE(["x$enable_qt_dbus"],
153 [AC_MSG_RESULT([yes])
155 AS_IF([test "x$HAVE_QTDBUS" = "xfalse"],
156 [AC_MSG_ERROR([Could not find QtDBus])],
157 [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus"]
161 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG dbus"],
162 [AC_MSG_RESULT([$enable_qt_dbus])
163 AC_MSG_ERROR([Unknown option "$enable_qt_dbus". Use either "yes" or "no".])])
166 AX_BOOST_BASE([1.35],
167 [AC_MSG_NOTICE([Boost CXXFLAGS: "$BOOST_CPPFLAGS"])
168 AC_MSG_NOTICE([Boost LDFLAGS: "$BOOST_LDFLAGS"])],
169 [AC_MSG_ERROR([Could not find Boost])])
170 CXXFLAGS="$BOOST_CPPFLAGS $CXXFLAGS"
171 LDFLAGS="$BOOST_LDFLAGS $LDFLAGS"
173 # add workaround for problematic boost version
174 # taken from ax_boost_base.m4
175 m4_define([DETECT_BOOST_VERSION_PROGRAM],
176 [AC_LANG_PROGRAM([[#include <boost/version.hpp>]],
177 [[(void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))]));]])])
179 AC_COMPILE_IFELSE([DETECT_BOOST_VERSION_PROGRAM(106000)], [],
180 [QBT_ADD_DEFINES="$QBT_ADD_DEFINES BOOST_NO_CXX11_RVALUE_REFERENCES"])
183 AC_MSG_NOTICE([Boost.System LIB: "$BOOST_SYSTEM_LIB"])
184 LIBS="$BOOST_SYSTEM_LIB $LIBS"
186 AC_MSG_CHECKING([which qtsingleapplication to use])
187 AS_CASE(["x$with_qtsingleapplication"],
189 [AC_MSG_RESULT([shipped])
190 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG usesystemqtsingleapplication"],
192 [AC_MSG_RESULT([system])
193 QBT_ADD_CONFIG="$QBT_ADD_CONFIG usesystemqtsingleapplication"],
194 [AC_MSG_RESULT([$with_qtsingleapplication])
195 AC_MSG_ERROR([Unknown option "$with_qtsingleapplication". Use either "system" or "shipped".])])
197 PKG_CHECK_MODULES(libtorrent,
198 [libtorrent-rasterbar >= 1.1.10],
199 [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS"
200 LIBS="$libtorrent_LIBS $LIBS"])
202 PKG_CHECK_MODULES(openssl,
204 [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
205 LIBS="$openssl_LIBS $LIBS"])
207 PKG_CHECK_MODULES(zlib,
209 [CXXFLAGS="$zlib_CFLAGS $CXXFLAGS"
210 LIBS="$zlib_LIBS $LIBS"])
212 # Check if already in >= C++14 mode because of the flags returned by one of the above packages
213 TMP_CXXFLAGS="$CXXFLAGS"
215 AC_MSG_CHECKING([if compiler defaults to C++14 or later mode])
216 AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
217 [AC_MSG_RESULT([yes])
218 QBT_CXX14_FOUND="yes"],
220 QBT_CXX14_FOUND="no"])
222 # In case of no, check if the compiler can support at least C++14
223 # and if yes, enable it leaving a warning to the user
224 AS_IF([test "x$QBT_CXX14_FOUND" = "xno"],
225 [AC_MSG_CHECKING([if compiler supports C++14])
226 CXXFLAGS="-std=c++14"
227 AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
228 [AC_MSG_RESULT([yes])
229 AC_MSG_CHECKING([if C++14 is disabled by the set compiler flags])
230 # prepend the flag so it won't override conflicting user defined flags
231 CXXFLAGS="-std=c++14 $TMP_CXXFLAGS"
232 AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
234 QBT_ADD_CONFIG="$QBT_ADD_CONFIG c++14"
235 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.])],
236 [AC_MSG_RESULT([yes])
237 AC_MSG_ERROR([The compiler supports C++14 but the user or a dependency has explicitly enabled a lower mode.])])],
239 AC_MSG_ERROR([A compiler supporting C++14 is required.])])
241 CXXFLAGS="$TMP_CXXFLAGS"
243 # These are required because autoconf doesn't expand these **particular**
244 # vars automatically. And qmake cannot autoexpand them.
245 AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])
246 AX_DEFINE_DIR([EXPAND_BINDIR], [bindir])
247 AX_DEFINE_DIR([EXPAND_DATADIR], [datadir])
248 AX_DEFINE_DIR([EXPAND_MANDIR], [mandir])
250 # Original extract() function contributed by pmzqla
251 # $*: Strings to parse
252 # Set $QBT_CONF_DEFINES, $QBT_CONF_INCLUDES, $QBT_CONF_EXTRA_CFLAGS
254 if [[ -z "$*" ]]; then
255 echo "Input string required"
259 # BSD sed needs an actual newline character in the substitute command
262 # Convert " -" to "\n" if not between quotes and remove possible leading white spaces
263 string=$(echo " $*" | $SED -e "s: -:\\${new_line}:g" -e 's:"\(.*\)\n\(.*\)":\"\1 -\2":g' -e "s:'\(.*\)\n\(.*\)':\'\1 -\2':g" -e 's/^[[[:space:]]]*//')
267 case "$(echo "$i" | cut -c1)" in
269 D) QBT_CONF_DEFINES="$QBT_CONF_DEFINES $(echo $i | cut -c2-)";;
270 I) QBT_CONF_INCLUDES="$QBT_CONF_INCLUDES $(echo $i | cut -c2-)";;
271 *) QBT_CONF_EXTRA_CFLAGS="$QBT_CONF_EXTRA_CFLAGS -$i";;
277 extract "$CFLAGS $CXXFLAGS"
278 QBT_ADD_DEFINES="$QBT_ADD_DEFINES $QBT_CONF_DEFINES"
280 # Substitute the values of these vars in conf.pri.in
283 AC_SUBST(QBT_CONF_INCLUDES)
284 AC_SUBST(QBT_CONF_EXTRA_CFLAGS)
285 AC_SUBST(QBT_ADD_CONFIG)
286 AC_SUBST(QBT_REMOVE_CONFIG)
287 AC_SUBST(QBT_ADD_DEFINES)
288 AC_SUBST(QBT_REMOVE_DEFINES)
291 AS_IF([test "x$enable_systemd" = "xyes"],
292 [AC_OUTPUT(dist/unix/systemd/qbittorrent-nox@.service)])
294 AC_MSG_NOTICE([Running qmake to generate the makefile...])
295 TOPDIR="$(cd "$(dirname "$0")" && pwd)"
296 $QT_QMAKE -r "$TOPDIR/qbittorrent.pro" "QMAKE_LRELEASE=$QMAKE_LRELEASE"
300 AS_IF([test "x$qmake_ret" != "x0"],
301 [AC_MSG_ERROR([$QT_QMAKE failed to generate the makefile])])
303 AC_MSG_NOTICE([Good, the configure finished.])