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.0.6],
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++11 mode because of the flags returned by one of the above packages
213 AC_MSG_CHECKING([if compiler is using C++11 or later mode])
214 AC_COMPILE_IFELSE([DETECT_CPP11_PROGRAM()],
215 [AC_MSG_RESULT([yes])
216 QBT_CXX11_FOUND="yes"],
218 QBT_CXX11_FOUND="no"])
220 # In case of no, check if the compiler can support at least C++11
221 # and if yes, enable it leaving a warning to the user
222 AS_IF([test "x$QBT_CXX11_FOUND" = "xno"],
223 [AC_MSG_CHECKING([if compiler supports C++11])
224 TMP_CXXFLAGS="$CXXFLAGS"
225 CXXFLAGS="$CXXFLAGS -std=c++11"
226 AC_COMPILE_IFELSE([DETECT_CPP11_PROGRAM()],
227 [AC_MSG_RESULT([yes])
228 AC_MSG_CHECKING([if C++11 is disabled by the set compiler flags])
229 # prepend the flag so it won't override conflicting user defined flags
230 CXXFLAGS="-std=c++11 $TMP_CXXFLAGS"
231 AC_COMPILE_IFELSE([DETECT_CPP11_PROGRAM()],
233 CXXFLAGS="$TMP_CXXFLAGS -std=c++11"
234 AC_MSG_WARN([C++11 mode is now force enabled.
235 Make sure you use the same C++ mode for qBittorrent and its dependencies.
236 To explicitly set qBittorrent to a later mode use CXXFLAGS.
237 Example: `CXXFLAGS="\$CXXFLAGS -std=c++14" ./configure`])],
238 [AC_MSG_RESULT([yes])
239 AC_MSG_ERROR([The compiler supports C++11 but the user or a dependency has explicitly enabled a lower mode.])])],
241 AC_MSG_ERROR([A compiler supporting C++11 is required.])])
244 # These are required because autoconf doesn't expand these **particular**
245 # vars automatically. And qmake cannot autoexpand them.
246 AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])
247 AX_DEFINE_DIR([EXPAND_BINDIR], [bindir])
248 AX_DEFINE_DIR([EXPAND_DATADIR], [datadir])
249 AX_DEFINE_DIR([EXPAND_MANDIR], [mandir])
251 # Original extract() function contributed by pmzqla
252 # $*: Strings to parse
253 # Set $QBT_CONF_DEFINES, $QBT_CONF_INCLUDES, $QBT_CONF_EXTRA_CFLAGS
255 if [[ -z "$*" ]]; then
256 echo "Input string required"
260 # BSD sed needs an actual newline character in the substitute command
263 # Convert " -" to "\n" if not between quotes and remove possible leading white spaces
264 string=$(echo " $*" | $SED -e "s: -:\\${new_line}:g" -e 's:"\(.*\)\n\(.*\)":\"\1 -\2":g' -e "s:'\(.*\)\n\(.*\)':\'\1 -\2':g" -e 's/^[[[:space:]]]*//')
268 case "$(echo "$i" | cut -c1)" in
270 D) QBT_CONF_DEFINES="$QBT_CONF_DEFINES $(echo $i | cut -c2-)";;
271 I) QBT_CONF_INCLUDES="$QBT_CONF_INCLUDES $(echo $i | cut -c2-)";;
272 *) QBT_CONF_EXTRA_CFLAGS="$QBT_CONF_EXTRA_CFLAGS -$i";;
278 extract "$CFLAGS $CXXFLAGS"
279 QBT_ADD_DEFINES="$QBT_ADD_DEFINES $QBT_CONF_DEFINES"
281 # Substitute the values of these vars in conf.pri.in
284 AC_SUBST(QBT_CONF_INCLUDES)
285 AC_SUBST(QBT_CONF_EXTRA_CFLAGS)
286 AC_SUBST(QBT_ADD_CONFIG)
287 AC_SUBST(QBT_REMOVE_CONFIG)
288 AC_SUBST(QBT_ADD_DEFINES)
289 AC_SUBST(QBT_REMOVE_DEFINES)
292 AS_IF([test "x$enable_systemd" = "xyes"],
293 [AC_OUTPUT(dist/unix/systemd/qbittorrent-nox@.service)])
297 AC_MSG_NOTICE([Running qmake to generate the makefile...])
298 CONFDIR="$( cd "$( dirname "$0" )" && pwd )"
300 $QT_QMAKE -r [$CONFDIR]/qbittorrent.pro "QMAKE_LRELEASE=$QMAKE_LRELEASE"
305 AS_IF([test "x$ret" = "x0"],
306 [AC_MSG_NOTICE([Good, your configure finished.])],
307 [AC_MSG_ERROR([Failed running $QT_QMAKE to generate the makefile])])