Sync translations from Transifex and run lupdate
[qBittorrent.git] / configure.ac
blob324bbfce60eaf0c81ecd68d241026786aa4bb13a
1 AC_INIT([qbittorrent], [v4.4.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 OS is FreeBSD])
57 AS_IF([expr "$host_os" : ".*freebsd.*" > /dev/null],
58       [AC_MSG_RESULT([yes])
59       LIBS="-lexecinfo $LIBS"],
60       [AC_MSG_RESULT([no])])
62 AC_MSG_CHECKING([whether OS is macOS])
63 AS_IF([expr "$host_os" : ".*darwin.*" > /dev/null],
64       [AC_MSG_RESULT([yes])
65       enable_qt_dbus=no],
66       [AC_MSG_RESULT([no])])
68 # Require 0.23 pkg-config
69 PKG_PROG_PKG_CONFIG([0.23])
70 AS_IF([test "x$PKG_CONFIG" = "x"],
71       [AC_MSG_ERROR([Could not find pkg-config])])
73 # Check which arguments were set and act accordingly
74 AC_MSG_CHECKING([whether to enable the Debug build])
75 AS_CASE(["x$enable_debug"],
76         ["xno"],
77               [AC_MSG_RESULT([no])
78               QBT_ADD_CONFIG="$QBT_ADD_CONFIG release"
79               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG debug"],
80         ["xyes"],
81                [AC_MSG_RESULT([yes])
82                QBT_ADD_CONFIG="$QBT_ADD_CONFIG debug"
83                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG release"],
84         [AC_MSG_RESULT([$enable_debug])
85         AC_MSG_ERROR([Unknown option "$enable_debug". Use either "yes" or "no".])])
87 AC_MSG_CHECKING([whether to enable the stacktrace feature])
88 AS_CASE(["x$enable_stacktrace"],
89         ["xno"],
90               [AC_MSG_RESULT([no])
91               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"],
92         ["xyes"],
93                [AC_MSG_RESULT([yes])
94                QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
95         ["xauto"],
96                 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <execinfo.h>]])],
97                 [AC_MSG_RESULT([yes])
98                 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
99                 [AC_MSG_RESULT([no])
100                 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"])],
101         [AC_MSG_RESULT([$enable_stacktrace])
102         AC_MSG_ERROR([Unknown option "$enable_stacktrace". Use either "yes" or "no".])])
104 AC_MSG_CHECKING([whether to enable the GUI])
105 AS_CASE(["x$enable_gui"],
106         ["xyes"],
107                [AC_MSG_RESULT([yes])
108                enable_systemd=[no]
109                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nogui"],
110         ["xno"],
111               [AC_MSG_RESULT([no])
112               enable_qt_dbus=[no]
113               QBT_ADD_CONFIG="$QBT_ADD_CONFIG nogui"],
114         [AC_MSG_RESULT([$enable_gui])
115         AC_MSG_ERROR([Unknown option "$enable_gui". Use either "yes" or "no".])])
117 AC_MSG_CHECKING([whether to install the systemd service file])
118 AS_CASE(["x$enable_systemd"],
119         ["xyes"],
120                [AC_MSG_RESULT([yes])
121                QBT_ADD_CONFIG="$QBT_ADD_CONFIG systemd"],
122         ["xno"],
123               [AC_MSG_RESULT([no])
124               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG systemd"],
125         [AC_MSG_RESULT([$enable_systemd])
126         AC_MSG_ERROR([Unknown option "$enable_systemd". Use either "yes" or "no".])])
128 AC_MSG_CHECKING([whether to enable the WebUI])
129 AS_CASE(["x$enable_webui"],
130         ["xyes"],
131                [AC_MSG_RESULT([yes])
132                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nowebui"],
133         ["xno"],
134               [AC_MSG_RESULT([no])
135               QBT_ADD_CONFIG="$QBT_ADD_CONFIG nowebui"],
136         [AC_MSG_RESULT([$enable_webui])
137         AC_MSG_ERROR([Unknown option "$enable_webui". Use either "yes" or "no".])])
139 FIND_QT5()
140 AS_IF([test "x$QT_QMAKE" = "x"],
141       [AC_MSG_ERROR([Could not find qmake])
142       ])
143 AS_IF([test "x$enable_gui" = "xyes"],
144       [PKG_CHECK_MODULES(Qt5Svg, [Qt5Svg >= 5.5.1])
145       ])
146 AC_MSG_CHECKING([whether QtDBus should be enabled])
147 AS_CASE(["x$enable_qt_dbus"],
148         ["xyes"],
149                [AC_MSG_RESULT([yes])
150                FIND_QTDBUS()
151                AS_IF([test "x$HAVE_QTDBUS" = "xfalse"],
152                      [AC_MSG_ERROR([Could not find QtDBus])],
153                      [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus"]
154                     )],
155         ["xno"],
156               [AC_MSG_RESULT([no])
157               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG dbus"],
158         [AC_MSG_RESULT([$enable_qt_dbus])
159         AC_MSG_ERROR([Unknown option "$enable_qt_dbus". Use either "yes" or "no".])])
162 AX_BOOST_BASE([1.65],
163               [AC_MSG_NOTICE([Boost CXXFLAGS: "$BOOST_CPPFLAGS"])
164                AC_MSG_NOTICE([Boost LDFLAGS: "$BOOST_LDFLAGS"])],
165               [AC_MSG_ERROR([Could not find Boost])])
166 CXXFLAGS="$BOOST_CPPFLAGS $CXXFLAGS"
167 LDFLAGS="$BOOST_LDFLAGS $LDFLAGS"
169 # add workaround for problematic boost version
170 # taken from ax_boost_base.m4
171 m4_define([DETECT_BOOST_VERSION_PROGRAM],
172     [AC_LANG_PROGRAM([[#include <boost/version.hpp>]],
173                      [[(void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))]));]])])
175 AC_COMPILE_IFELSE([DETECT_BOOST_VERSION_PROGRAM(106000)], [],
176     [QBT_ADD_DEFINES="$QBT_ADD_DEFINES BOOST_NO_CXX11_RVALUE_REFERENCES"])
178 AX_BOOST_SYSTEM()
179 AC_MSG_NOTICE([Boost.System LIB: "$BOOST_SYSTEM_LIB"])
180 LIBS="$BOOST_SYSTEM_LIB $LIBS"
182 PKG_CHECK_MODULES(libtorrent,
183                   [libtorrent-rasterbar >= 1.2.11],
184                   [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS"
185                   LIBS="$libtorrent_LIBS $LIBS"])
187 PKG_CHECK_MODULES(openssl,
188                   [openssl >= 1.1.1],
189                   [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
190                   LIBS="$openssl_LIBS $LIBS"])
192 PKG_CHECK_MODULES(zlib,
193                  [zlib >= 1.2.11],
194                  [CXXFLAGS="$zlib_CFLAGS $CXXFLAGS"
195                  LIBS="$zlib_LIBS $LIBS"])
197 # Check if already in >= C++14 mode because of the flags returned by one of the above packages
198 TMP_CXXFLAGS="$CXXFLAGS"
199 CXXFLAGS=""
200 AC_MSG_CHECKING([if compiler defaults to C++14 or later mode])
201 AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
202                   [AC_MSG_RESULT([yes])
203                    QBT_CXX14_FOUND="yes"],
204                   [AC_MSG_RESULT([no])
205                    QBT_CXX14_FOUND="no"])
207 # In case of no, check if the compiler can support at least C++14
208 # and if yes, enable it leaving a warning to the user
209 AS_IF([test "x$QBT_CXX14_FOUND" = "xno"],
210       [AC_MSG_CHECKING([if compiler supports C++14])
211        CXXFLAGS="-std=c++14"
212        AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
213                         [AC_MSG_RESULT([yes])
214                          AC_MSG_CHECKING([if C++14 is disabled by the set compiler flags])
215                          # prepend the flag so it won't override conflicting user defined flags
216                          CXXFLAGS="-std=c++14 $TMP_CXXFLAGS"
217                          AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
218                                            [AC_MSG_RESULT([no])
219                                             QBT_ADD_CONFIG="$QBT_ADD_CONFIG c++14"
220                                             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.])],
221                                            [AC_MSG_RESULT([yes])
222                                             AC_MSG_ERROR([The compiler supports C++14 but the user or a dependency has explicitly enabled a lower mode.])])],
223                         [AC_MSG_RESULT([no])
224                          AC_MSG_ERROR([A compiler supporting C++14 is required.])])
225       ])
226 CXXFLAGS="$TMP_CXXFLAGS"
228 # These are required because autoconf doesn't expand these **particular**
229 # vars automatically. And qmake cannot autoexpand them.
230 AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])
231 AX_DEFINE_DIR([EXPAND_BINDIR], [bindir])
232 AX_DEFINE_DIR([EXPAND_DATADIR], [datadir])
233 AX_DEFINE_DIR([EXPAND_MANDIR], [mandir])
235 # Original extract() function contributed by pmzqla
236 # $*: Strings to parse
237 # Set $QBT_CONF_DEFINES, $QBT_CONF_INCLUDES, $QBT_CONF_EXTRA_CFLAGS
238 extract() {
239   if [[ -z "$*" ]]; then
240     echo "Input string required"
241     return 1
242   fi
244   # BSD sed needs an actual newline character in the substitute command
245   new_line='
247   # Convert " -" to "\n" if not between quotes and remove possible leading white spaces
248   string=$(echo " $*" | $SED -e "s: -:\\${new_line}:g" -e 's:"\(.*\)\n\(.*\)":\"\1 -\2":g' -e "s:'\(.*\)\n\(.*\)':\'\1 -\2':g" -e 's/^[[[:space:]]]*//')
249   SAVEIFS=$IFS
250   IFS=$(printf "\n\b")
251   for i in $string; do
252     case "$(echo "$i" | cut -c1)" in
253       '') ;;
254       D) QBT_CONF_DEFINES="$QBT_CONF_DEFINES $(echo $i | cut -c2-)";;
255       I) QBT_CONF_INCLUDES="$QBT_CONF_INCLUDES $(echo $i | cut -c2-)";;
256       *) QBT_CONF_EXTRA_CFLAGS="$QBT_CONF_EXTRA_CFLAGS -$i";;
257     esac
258   done
259   IFS=$SAVEIFS
262 extract "$CFLAGS $CXXFLAGS"
263 QBT_ADD_DEFINES="$QBT_ADD_DEFINES $QBT_CONF_DEFINES"
265 # Substitute the values of these vars in conf.pri.in
266 AC_SUBST(QBT_CC)
267 AC_SUBST(QBT_CXX)
268 AC_SUBST(QBT_CONF_INCLUDES)
269 AC_SUBST(QBT_CONF_EXTRA_CFLAGS)
270 AC_SUBST(QBT_ADD_CONFIG)
271 AC_SUBST(QBT_REMOVE_CONFIG)
272 AC_SUBST(QBT_ADD_DEFINES)
273 AC_SUBST(QBT_REMOVE_DEFINES)
275 AC_OUTPUT(conf.pri)
276 AS_IF([test "x$enable_systemd" = "xyes"],
277       [AC_OUTPUT(dist/unix/systemd/qbittorrent-nox@.service)])
279 AC_MSG_NOTICE([Running qmake to generate the makefile...])
280 TOPDIR="$(cd "$(dirname "$0")" && pwd)"
281 $QT_QMAKE -r "$TOPDIR/qbittorrent.pro" "QMAKE_LRELEASE=$QMAKE_LRELEASE"
282 qmake_ret="$?"
284 AS_ECHO()
285 AS_IF([test "x$qmake_ret" != "x0"],
286       [AC_MSG_ERROR([$QT_QMAKE failed to generate the makefile])])
288 AC_MSG_NOTICE([Good, the configure finished.])
289 AS_ECHO()