Sync translations from Transifex and run lupdate
[qBittorrent.git] / configure.ac
blob536d7d5eb3fd5db4cd2aa002b03db614469939ef
2 AC_INIT([qbittorrent], [v4.4.0alpha], [bugs.qbittorrent.org], [], [https://www.qbittorrent.org/])
3 AC_CONFIG_AUX_DIR([build-aux])
4 AC_CONFIG_MACRO_DIR([m4])
5 : ${CFLAGS=""}
6 : ${CXXFLAGS=""}
7 AC_PROG_CC
8 AC_PROG_CXX
9 AC_PROG_SED
10 AC_LANG(C++)
11 AC_CANONICAL_HOST
12 AM_INIT_AUTOMAKE
14 # use compiler from env variables if available
15 QBT_CC="$CC"
16 QBT_CXX="$CXX"
18 # Define --wth-* and --enable-* arguments
20 AC_ARG_ENABLE(debug,
21               [AS_HELP_STRING([--enable-debug],
22                               [Enable debug build])],
23               [],
24               [enable_debug=no])
26 AC_ARG_ENABLE(stacktrace,
27               [AS_HELP_STRING([--enable-stacktrace],
28                               [Enable stacktrace feature (default=auto)])],
29               [],
30               [enable_stacktrace=auto])
32 AC_ARG_ENABLE(gui,
33               [AS_HELP_STRING([--disable-gui],
34                               [Disable the GUI for headless running. Disables QtDBus and the GeoIP Database.])],
35               [],
36               [enable_gui=yes])
38 AC_ARG_ENABLE(systemd,
39               [AS_HELP_STRING([--enable-systemd],
40                               [Install the systemd service file (headless only).])],
41               [],
42               [enable_systemd=no])
44 AC_ARG_ENABLE(webui,
45               [AS_HELP_STRING([--disable-webui],
46                               [Disable the WebUI.])],
47               [],
48               [enable_webui=yes])
50 AC_ARG_ENABLE(qt-dbus,
51               [AS_HELP_STRING([--disable-qt-dbus],
52                               [Disable use of QtDBus (GUI only)])],
53               [],
54               [enable_qt_dbus=yes])
56 # Detect OS
57 AC_MSG_CHECKING([whether OS is FreeBSD])
58 AS_IF([expr "$host_os" : ".*freebsd.*" > /dev/null],
59       [AC_MSG_RESULT([yes])
60       LIBS="-lexecinfo $LIBS"],
61       [AC_MSG_RESULT([no])])
63 AC_MSG_CHECKING([whether OS is macOS])
64 AS_IF([expr "$host_os" : ".*darwin.*" > /dev/null],
65       [AC_MSG_RESULT([yes])
66       enable_qt_dbus=no],
67       [AC_MSG_RESULT([no])])
69 # Require 0.23 pkg-config
70 PKG_PROG_PKG_CONFIG([0.23])
71 AS_IF([test "x$PKG_CONFIG" = "x"],
72       [AC_MSG_ERROR([Could not find pkg-config])])
74 # Check which arguments were set and act accordingly
75 AC_MSG_CHECKING([whether to enable the Debug build])
76 AS_CASE(["x$enable_debug"],
77         ["xno"],
78               [AC_MSG_RESULT([no])
79               QBT_ADD_CONFIG="$QBT_ADD_CONFIG release"
80               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG debug"],
81         ["xyes"],
82                [AC_MSG_RESULT([yes])
83                QBT_ADD_CONFIG="$QBT_ADD_CONFIG debug"
84                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG release"],
85         [AC_MSG_RESULT([$enable_debug])
86         AC_MSG_ERROR([Unknown option "$enable_debug". Use either "yes" or "no".])])
88 AC_MSG_CHECKING([whether to enable the stacktrace feature])
89 AS_CASE(["x$enable_stacktrace"],
90         ["xno"],
91               [AC_MSG_RESULT([no])
92               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"],
93         ["xyes"],
94                [AC_MSG_RESULT([yes])
95                QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
96         ["xauto"],
97                 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <execinfo.h>]])],
98                 [AC_MSG_RESULT([yes])
99                 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
100                 [AC_MSG_RESULT([no])
101                 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"])],
102         [AC_MSG_RESULT([$enable_stacktrace])
103         AC_MSG_ERROR([Unknown option "$enable_stacktrace". Use either "yes" or "no".])])
105 AC_MSG_CHECKING([whether to enable the GUI])
106 AS_CASE(["x$enable_gui"],
107         ["xyes"],
108                [AC_MSG_RESULT([yes])
109                enable_systemd=[no]
110                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nogui"],
111         ["xno"],
112               [AC_MSG_RESULT([no])
113               enable_qt_dbus=[no]
114               QBT_ADD_CONFIG="$QBT_ADD_CONFIG nogui"],
115         [AC_MSG_RESULT([$enable_gui])
116         AC_MSG_ERROR([Unknown option "$enable_gui". Use either "yes" or "no".])])
118 AC_MSG_CHECKING([whether to install the systemd service file])
119 AS_CASE(["x$enable_systemd"],
120         ["xyes"],
121                [AC_MSG_RESULT([yes])
122                QBT_ADD_CONFIG="$QBT_ADD_CONFIG systemd"],
123         ["xno"],
124               [AC_MSG_RESULT([no])
125               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG systemd"],
126         [AC_MSG_RESULT([$enable_systemd])
127         AC_MSG_ERROR([Unknown option "$enable_systemd". Use either "yes" or "no".])])
129 AC_MSG_CHECKING([whether to enable the WebUI])
130 AS_CASE(["x$enable_webui"],
131         ["xyes"],
132                [AC_MSG_RESULT([yes])
133                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nowebui"],
134         ["xno"],
135               [AC_MSG_RESULT([no])
136               QBT_ADD_CONFIG="$QBT_ADD_CONFIG nowebui"],
137         [AC_MSG_RESULT([$enable_webui])
138         AC_MSG_ERROR([Unknown option "$enable_webui". Use either "yes" or "no".])])
140 FIND_QT5()
141 AS_IF([test "x$QT_QMAKE" = "x"],
142       [AC_MSG_ERROR([Could not find qmake])
143       ])
144 AS_IF([test "x$enable_gui" = "xyes"],
145       [PKG_CHECK_MODULES(Qt5Svg, [Qt5Svg >= 5.15.2])
146       ])
147 AC_MSG_CHECKING([whether QtDBus should be enabled])
148 AS_CASE(["x$enable_qt_dbus"],
149         ["xyes"],
150                [AC_MSG_RESULT([yes])
151                FIND_QTDBUS()
152                AS_IF([test "x$HAVE_QTDBUS" = "xfalse"],
153                      [AC_MSG_ERROR([Could not find QtDBus])],
154                      [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus"]
155                     )],
156         ["xno"],
157               [AC_MSG_RESULT([no])
158               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG dbus"],
159         [AC_MSG_RESULT([$enable_qt_dbus])
160         AC_MSG_ERROR([Unknown option "$enable_qt_dbus". Use either "yes" or "no".])])
163 AX_BOOST_BASE([1.65],
164               [AC_MSG_NOTICE([Boost CXXFLAGS: "$BOOST_CPPFLAGS"])
165                AC_MSG_NOTICE([Boost LDFLAGS: "$BOOST_LDFLAGS"])],
166               [AC_MSG_ERROR([Could not find Boost])])
167 CXXFLAGS="$BOOST_CPPFLAGS $CXXFLAGS"
168 LDFLAGS="$BOOST_LDFLAGS $LDFLAGS"
170 # add workaround for problematic boost version
171 # taken from ax_boost_base.m4
172 m4_define([DETECT_BOOST_VERSION_PROGRAM],
173     [AC_LANG_PROGRAM([[#include <boost/version.hpp>]],
174                      [[(void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))]));]])])
176 AC_COMPILE_IFELSE([DETECT_BOOST_VERSION_PROGRAM(106000)], [],
177     [QBT_ADD_DEFINES="$QBT_ADD_DEFINES BOOST_NO_CXX11_RVALUE_REFERENCES"])
179 PKG_CHECK_MODULES(libtorrent,
180                   [libtorrent-rasterbar >= 2.0.4],
181                   [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS" QBT_ADD_DEFINES="$QBT_ADD_DEFINES QBT_USES_LIBTORRENT2"],
182                   [PKG_CHECK_MODULES(libtorrent,
183                                      [libtorrent-rasterbar >= 1.2.14 libtorrent-rasterbar < 2],
184                                      [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS" LIBS="$libtorrent_LIBS $LIBS"])])
186 PKG_CHECK_MODULES(openssl,
187                   [openssl >= 1.1.1],
188                   [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
189                   LIBS="$openssl_LIBS $LIBS"])
191 PKG_CHECK_MODULES(zlib,
192                  [zlib >= 1.2.11],
193                  [CXXFLAGS="$zlib_CFLAGS $CXXFLAGS"
194                  LIBS="$zlib_LIBS $LIBS"])
196 # Check if already in >= C++17 mode because of the flags returned by one of the above packages
197 TMP_CXXFLAGS="$CXXFLAGS"
198 CXXFLAGS=""
199 AC_MSG_CHECKING([if compiler defaults to C++17 or later mode])
200 AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
201                   [AC_MSG_RESULT([yes])
202                    QBT_CXX17_FOUND="yes"],
203                   [AC_MSG_RESULT([no])
204                    QBT_CXX17_FOUND="no"])
206 # In case of no, check if the compiler can support at least C++17
207 # and if yes, enable it leaving a warning to the user
208 AS_IF([test "x$QBT_CXX17_FOUND" = "xno"],
209       [AC_MSG_CHECKING([if compiler supports C++17])
210        CXXFLAGS="-std=c++17"
211        AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
212                         [AC_MSG_RESULT([yes])
213                          AC_MSG_CHECKING([if C++17 is disabled by the set compiler flags])
214                          # prepend the flag so it won't override conflicting user defined flags
215                          CXXFLAGS="-std=c++17 $TMP_CXXFLAGS"
216                          AC_COMPILE_IFELSE([DETECT_CPP17_PROGRAM()],
217                                            [AC_MSG_RESULT([no])
218                                             QBT_ADD_CONFIG="$QBT_ADD_CONFIG c++17"
219                                             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.])],
220                                            [AC_MSG_RESULT([yes])
221                                             AC_MSG_ERROR([The compiler supports C++17 but the user or a dependency has explicitly enabled a lower mode.])])],
222                         [AC_MSG_RESULT([no])
223                          AC_MSG_ERROR([A compiler supporting C++17 is required.])])
224       ])
225 CXXFLAGS="$TMP_CXXFLAGS"
227 # These are required because autoconf doesn't expand these **particular**
228 # vars automatically. And qmake cannot autoexpand them.
229 AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])
230 AX_DEFINE_DIR([EXPAND_BINDIR], [bindir])
231 AX_DEFINE_DIR([EXPAND_DATADIR], [datadir])
232 AX_DEFINE_DIR([EXPAND_MANDIR], [mandir])
234 # Original extract() function contributed by pmzqla
235 # $*: Strings to parse
236 # Set $QBT_CONF_DEFINES, $QBT_CONF_INCLUDES, $QBT_CONF_EXTRA_CFLAGS
237 extract() {
238   if [[ -z "$*" ]]; then
239     echo "Input string required"
240     return 1
241   fi
243   # BSD sed needs an actual newline character in the substitute command
244   new_line='
246   # Convert " -" to "\n" if not between quotes and remove possible leading white spaces
247   string=$(echo " $*" | $SED -e "s: -:\\${new_line}:g" -e 's:"\(.*\)\n\(.*\)":\"\1 -\2":g' -e "s:'\(.*\)\n\(.*\)':\'\1 -\2':g" -e 's/^[[[:space:]]]*//')
248   SAVEIFS=$IFS
249   IFS=$(printf "\n\b")
250   for i in $string; do
251     case "$(echo "$i" | cut -c1)" in
252       '') ;;
253       D) QBT_CONF_DEFINES="$QBT_CONF_DEFINES $(echo $i | cut -c2-)";;
254       I) QBT_CONF_INCLUDES="$QBT_CONF_INCLUDES $(echo $i | cut -c2-)";;
255       *) QBT_CONF_EXTRA_CFLAGS="$QBT_CONF_EXTRA_CFLAGS -$i";;
256     esac
257   done
258   IFS=$SAVEIFS
261 extract "$CFLAGS $CXXFLAGS"
262 QBT_ADD_DEFINES="$QBT_ADD_DEFINES $QBT_CONF_DEFINES"
264 # Substitute the values of these vars in conf.pri.in
265 AC_SUBST(QBT_CC)
266 AC_SUBST(QBT_CXX)
267 AC_SUBST(QBT_CONF_INCLUDES)
268 AC_SUBST(QBT_CONF_EXTRA_CFLAGS)
269 AC_SUBST(QBT_ADD_CONFIG)
270 AC_SUBST(QBT_REMOVE_CONFIG)
271 AC_SUBST(QBT_ADD_DEFINES)
272 AC_SUBST(QBT_REMOVE_DEFINES)
274 QBT_CONFIG_FILES="conf.pri"
276 AS_IF([test "x$enable_systemd" = "xyes"],
277       [QBT_CONFIG_FILES="$QBT_CONFIG_FILES dist/unix/systemd/qbittorrent-nox@.service"])
279 AC_CONFIG_FILES(["$QBT_CONFIG_FILES"])
280 AC_OUTPUT
282 AC_MSG_NOTICE([Running qmake to generate the makefile...])
283 TOPDIR="$(cd "$(dirname "$0")" && pwd)"
284 $QT_QMAKE -r "$TOPDIR/qbittorrent.pro" "QMAKE_LRELEASE=$QMAKE_LRELEASE"
285 qmake_ret="$?"
287 AS_ECHO()
288 AS_IF([test "x$qmake_ret" != "x0"],
289       [AC_MSG_ERROR([$QT_QMAKE failed to generate the makefile])])
291 AC_MSG_NOTICE([Good, the configure finished.])
292 AS_ECHO()