Combine all the column filter related widgets
[qBittorrent.git] / configure.ac
blobb1c3ebbb75dc8e6b3a9c49f61d8557d7b00bd383
1 AC_INIT([qbittorrent], [v4.6.0alpha1], [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([foreign])
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.71],
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 PKG_CHECK_MODULES(libtorrent,
191                   [libtorrent-rasterbar >= 2.0.8],
192                   [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS" QBT_ADD_DEFINES="$QBT_ADD_DEFINES QBT_USES_LIBTORRENT2"],
193                   [PKG_CHECK_MODULES(libtorrent,
194                                      [libtorrent-rasterbar >= 1.2.18 libtorrent-rasterbar < 2],
195                                      [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"])])
197 PKG_CHECK_MODULES(openssl,
198                   [openssl >= 1.1.1],
199                   [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
200                   LIBS="$openssl_LIBS $LIBS"])
202 PKG_CHECK_MODULES(zlib,
203                  [zlib >= 1.2.11],
204                  [CXXFLAGS="$zlib_CFLAGS $CXXFLAGS"
205                  LIBS="$zlib_LIBS $LIBS"])
207 # Check if already in >= C++17 mode because of the flags returned by one of the above packages
208 TMP_CXXFLAGS="$CXXFLAGS"
209 CXXFLAGS=""
210 AC_MSG_CHECKING([if compiler defaults to C++17 or later mode])
211 AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
212                   [AC_MSG_RESULT([yes])
213                    QBT_CXX17_FOUND="yes"],
214                   [AC_MSG_RESULT([no])
215                    QBT_CXX17_FOUND="no"])
217 # In case of no, check if the compiler can support at least C++17
218 # and if yes, enable it leaving a warning to the user
219 AS_IF([test "x$QBT_CXX17_FOUND" = "xno"],
220       [AC_MSG_CHECKING([if compiler supports C++17])
221        CXXFLAGS="-std=c++17"
222        AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
223                         [AC_MSG_RESULT([yes])
224                          AC_MSG_CHECKING([if C++17 is disabled by the set compiler flags])
225                          # prepend the flag so it won't override conflicting user defined flags
226                          CXXFLAGS="-std=c++17 $TMP_CXXFLAGS"
227                          AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
228                                            [AC_MSG_RESULT([no])
229                                             QBT_ADD_CONFIG="$QBT_ADD_CONFIG c++17"
230                                             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.])],
231                                            [AC_MSG_RESULT([yes])
232                                             AC_MSG_ERROR([The compiler supports C++17 but the user or a dependency has explicitly enabled a lower mode.])])],
233                         [AC_MSG_RESULT([no])
234                          AC_MSG_ERROR([A compiler supporting C++17 is required.])])
235       ])
236 CXXFLAGS="$TMP_CXXFLAGS"
238 # These are required because autoconf doesn't expand these **particular**
239 # vars automatically. And qmake cannot autoexpand them.
240 AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])
241 AX_DEFINE_DIR([EXPAND_BINDIR], [bindir])
242 AX_DEFINE_DIR([EXPAND_DATADIR], [datadir])
243 AX_DEFINE_DIR([EXPAND_MANDIR], [mandir])
245 # Original extract() function contributed by pmzqla
246 # $*: Strings to parse
247 # Set $QBT_CONF_DEFINES, $QBT_CONF_INCLUDES, $QBT_CONF_EXTRA_CFLAGS
248 extract() {
249   if [[ -z "$*" ]]; then
250     echo "Input string required"
251     return 1
252   fi
254   # BSD sed needs an actual newline character in the substitute command
255   new_line='
257   # Convert " -" to "\n" if not between quotes and remove possible leading white spaces
258   string=$(echo " $*" | $SED -e "s: -:\\${new_line}:g" -e 's:"\(.*\)\n\(.*\)":\"\1 -\2":g' -e "s:'\(.*\)\n\(.*\)':\'\1 -\2':g" -e 's/^[[[:space:]]]*//')
259   SAVEIFS=$IFS
260   IFS=$(printf "\n\b")
261   for i in $string; do
262     case "$(echo "$i" | cut -c1)" in
263       '') ;;
264       D) QBT_CONF_DEFINES="$QBT_CONF_DEFINES $(echo $i | cut -c2-)";;
265       I) QBT_CONF_INCLUDES="$QBT_CONF_INCLUDES $(echo $i | cut -c2-)";;
266       *) QBT_CONF_EXTRA_CFLAGS="$QBT_CONF_EXTRA_CFLAGS -$i";;
267     esac
268   done
269   IFS=$SAVEIFS
272 extract "$CFLAGS $CXXFLAGS"
273 QBT_ADD_DEFINES="$QBT_ADD_DEFINES $QBT_CONF_DEFINES"
275 # Substitute the values of these vars in conf.pri.in
276 AC_SUBST(QBT_CC)
277 AC_SUBST(QBT_CXX)
278 AC_SUBST(QBT_CONF_INCLUDES)
279 AC_SUBST(QBT_CONF_EXTRA_CFLAGS)
280 AC_SUBST(QBT_ADD_CONFIG)
281 AC_SUBST(QBT_REMOVE_CONFIG)
282 AC_SUBST(QBT_ADD_DEFINES)
283 AC_SUBST(QBT_REMOVE_DEFINES)
285 QBT_CONFIG_FILES="conf.pri"
287 AS_IF([test "x$enable_systemd" = "xyes"],
288       [QBT_CONFIG_FILES="$QBT_CONFIG_FILES dist/unix/systemd/qbittorrent-nox@.service"])
290 AC_CONFIG_FILES(["$QBT_CONFIG_FILES"])
291 AC_OUTPUT
293 AC_MSG_NOTICE([Running qmake to generate the makefile...])
294 TOPDIR="$(cd "$(dirname "$0")" && pwd)"
295 $QT_QMAKE -r "$TOPDIR/qbittorrent.pro" "QMAKE_LRELEASE=$QMAKE_LRELEASE"
296 qmake_ret="$?"
298 AS_ECHO()
299 AS_IF([test "x$qmake_ret" != "x0"],
300       [AC_MSG_ERROR([$QT_QMAKE failed to generate the makefile])])
302 AC_MSG_NOTICE([Good, the configure finished.])
303 AS_ECHO()