Bump to 4.5.0alpha1
[qBittorrent.git] / configure.ac
blobdb038c56fbbf018238dd575336ad723bfcbee402
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])
4 : ${CFLAGS=""}
5 : ${CXXFLAGS=""}
6 AC_PROG_CC
7 AC_PROG_CXX
8 AC_PROG_SED
9 AC_LANG(C++)
10 AC_CANONICAL_HOST
11 AM_INIT_AUTOMAKE
13 # use compiler from env variables if available
14 QBT_CC="$CC"
15 QBT_CXX="$CXX"
17 # Define --wth-* and --enable-* arguments
19 AC_ARG_ENABLE(debug,
20               [AS_HELP_STRING([--enable-debug],
21                               [Enable debug build])],
22               [],
23               [enable_debug=no])
25 AC_ARG_ENABLE(stacktrace,
26               [AS_HELP_STRING([--enable-stacktrace],
27                               [Enable stacktrace feature (default=auto)])],
28               [],
29               [enable_stacktrace=auto])
31 AC_ARG_ENABLE(gui,
32               [AS_HELP_STRING([--disable-gui],
33                               [Disable the GUI for headless running. Disables QtDBus and the GeoIP Database.])],
34               [],
35               [enable_gui=yes])
37 AC_ARG_ENABLE(systemd,
38               [AS_HELP_STRING([--enable-systemd],
39                               [Install the systemd service file (headless only).])],
40               [],
41               [enable_systemd=no])
43 AC_ARG_ENABLE(webui,
44               [AS_HELP_STRING([--disable-webui],
45                               [Disable the WebUI.])],
46               [],
47               [enable_webui=yes])
49 AC_ARG_ENABLE(qt-dbus,
50               [AS_HELP_STRING([--disable-qt-dbus],
51                               [Disable use of QtDBus (GUI only)])],
52               [],
53               [enable_qt_dbus=yes])
55 # Detect OS
56 AC_MSG_CHECKING([whether to enable specific tweaks for current host "$host_os"])
57 case "$host_os" in
58     *darwin*)
59         AC_MSG_RESULT([yes])
60         enable_qt_dbus=no
61         ;;
63     *freebsd*)
64         AC_MSG_RESULT([yes])
65         LIBS="-lexecinfo $LIBS"
66         ;;
68     *haiku*)
69         AC_MSG_RESULT([yes])
70         LIBS="-lnetwork $LIBS"
71         ;;
73     *openbsd*)
74         AC_MSG_RESULT([yes])
75         LIBS="-lexecinfo $LIBS"
76         ;;
78     *)
79         AC_MSG_RESULT([no])
80         ;;
81 esac
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"],
91         ["xno"],
92               [AC_MSG_RESULT([no])
93               QBT_ADD_CONFIG="$QBT_ADD_CONFIG release"
94               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG debug"],
95         ["xyes"],
96                [AC_MSG_RESULT([yes])
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"],
104         ["xno"],
105               [AC_MSG_RESULT([no])
106               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"],
107         ["xyes"],
108                [AC_MSG_RESULT([yes])
109                QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
110         ["xauto"],
111                 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <execinfo.h>]])],
112                 [AC_MSG_RESULT([yes])
113                 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
114                 [AC_MSG_RESULT([no])
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"],
121         ["xyes"],
122                [AC_MSG_RESULT([yes])
123                enable_systemd=[no]
124                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nogui"],
125         ["xno"],
126               [AC_MSG_RESULT([no])
127               enable_qt_dbus=[no]
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"],
134         ["xyes"],
135                [AC_MSG_RESULT([yes])
136                QBT_ADD_CONFIG="$QBT_ADD_CONFIG systemd"],
137         ["xno"],
138               [AC_MSG_RESULT([no])
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"],
145         ["xyes"],
146                [AC_MSG_RESULT([yes])
147                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nowebui"],
148         ["xno"],
149               [AC_MSG_RESULT([no])
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".])])
154 FIND_QT5()
155 AS_IF([test "x$QT_QMAKE" = "x"],
156       [AC_MSG_ERROR([Could not find qmake])
157       ])
158 AS_IF([test "x$enable_gui" = "xyes"],
159       [PKG_CHECK_MODULES(Qt5Svg, [Qt5Svg >= 5.15.2])
160       ])
161 AC_MSG_CHECKING([whether QtDBus should be enabled])
162 AS_CASE(["x$enable_qt_dbus"],
163         ["xyes"],
164                [AC_MSG_RESULT([yes])
165                FIND_QTDBUS()
166                AS_IF([test "x$HAVE_QTDBUS" = "xfalse"],
167                      [AC_MSG_ERROR([Could not find QtDBus])],
168                      [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus"]
169                     )],
170         ["xno"],
171               [AC_MSG_RESULT([no])
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,
201                   [openssl >= 1.1.1],
202                   [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
203                   LIBS="$openssl_LIBS $LIBS"])
205 PKG_CHECK_MODULES(zlib,
206                  [zlib >= 1.2.11],
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"
212 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"],
217                   [AC_MSG_RESULT([no])
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()],
231                                            [AC_MSG_RESULT([no])
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.])])],
236                         [AC_MSG_RESULT([no])
237                          AC_MSG_ERROR([A compiler supporting C++17 is required.])])
238       ])
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
251 extract() {
252   if [[ -z "$*" ]]; then
253     echo "Input string required"
254     return 1
255   fi
257   # BSD sed needs an actual newline character in the substitute command
258   new_line='
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:]]]*//')
262   SAVEIFS=$IFS
263   IFS=$(printf "\n\b")
264   for i in $string; do
265     case "$(echo "$i" | cut -c1)" in
266       '') ;;
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";;
270     esac
271   done
272   IFS=$SAVEIFS
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
279 AC_SUBST(QBT_CC)
280 AC_SUBST(QBT_CXX)
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"])
294 AC_OUTPUT
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"
299 qmake_ret="$?"
301 AS_ECHO()
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.])
306 AS_ECHO()