Update transifex config file
[qBittorrent.git] / configure.ac
blob4591467d885bf60e06039c5f4e0640a069b6b227
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])
4 AC_PROG_CC
5 AC_PROG_CXX
6 AC_PROG_SED
7 AC_LANG(C++)
8 AC_CANONICAL_HOST
9 AM_INIT_AUTOMAKE
11 # use compiler from env variables if available
12 QBT_CC="$CC"
13 QBT_CXX="$CXX"
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)])],
20             [],
21             [with_qtsingleapplication=shipped])
23 AC_ARG_ENABLE(debug,
24               [AS_HELP_STRING([--enable-debug],
25                               [Enable debug build])],
26               [],
27               [enable_debug=no])
29 AC_ARG_ENABLE(stacktrace,
30               [AS_HELP_STRING([--enable-stacktrace],
31                               [Enable stacktrace feature (default=auto)])],
32               [],
33               [enable_stacktrace=auto])
35 AC_ARG_ENABLE(gui,
36               [AS_HELP_STRING([--disable-gui],
37                               [Disable the GUI for headless running. Disables QtDBus and the GeoIP Database.])],
38               [],
39               [enable_gui=yes])
41 AC_ARG_ENABLE(systemd,
42               [AS_HELP_STRING([--enable-systemd],
43                               [Install the systemd service file (headless only).])],
44               [],
45               [enable_systemd=no])
47 AC_ARG_ENABLE(webui,
48               [AS_HELP_STRING([--disable-webui],
49                               [Disable the WebUI.])],
50               [],
51               [enable_webui=yes])
53 AC_ARG_ENABLE(qt-dbus,
54               [AS_HELP_STRING([--disable-qt-dbus],
55                               [Disable use of QtDBus (GUI only)])],
56               [],
57               [enable_qt_dbus=yes])
59 # Detect OS
60 AC_MSG_CHECKING([whether OS is FreeBSD])
61 AS_IF([expr "$host_os" : ".*freebsd.*" > /dev/null],
62       [AC_MSG_RESULT([yes])
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],
68       [AC_MSG_RESULT([yes])
69       enable_qt_dbus=no],
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"],
80         ["xno"],
81               [AC_MSG_RESULT([no])
82               QBT_ADD_CONFIG="$QBT_ADD_CONFIG release"
83               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG debug"],
84         ["xyes"],
85                [AC_MSG_RESULT([yes])
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"],
93         ["xno"],
94               [AC_MSG_RESULT([no])
95               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"],
96         ["xyes"],
97                [AC_MSG_RESULT([yes])
98                QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
99         ["xauto"],
100                 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <execinfo.h>]])],
101                 [AC_MSG_RESULT([yes])
102                 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
103                 [AC_MSG_RESULT([no])
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"],
110         ["xyes"],
111                [AC_MSG_RESULT([yes])
112                enable_systemd=[no]
113                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nogui"],
114         ["xno"],
115               [AC_MSG_RESULT([no])
116               enable_qt_dbus=[no]
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"],
123         ["xyes"],
124                [AC_MSG_RESULT([yes])
125                QBT_ADD_CONFIG="$QBT_ADD_CONFIG systemd"],
126         ["xno"],
127               [AC_MSG_RESULT([no])
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"],
134         ["xyes"],
135                [AC_MSG_RESULT([yes])
136                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nowebui"],
137         ["xno"],
138               [AC_MSG_RESULT([no])
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".])])
143 FIND_QT5()
144 AS_IF([test "x$QT_QMAKE" = "x"],
145       [AC_MSG_ERROR([Could not find qmake])
146       ])
147 AS_IF([test "x$enable_gui" = "xyes"],
148       [PKG_CHECK_MODULES(Qt5Svg, [Qt5Svg >= 5.5.1])
149       ])
150 AC_MSG_CHECKING([whether QtDBus should be enabled])
151 AS_CASE(["x$enable_qt_dbus"],
152         ["xyes"],
153                [AC_MSG_RESULT([yes])
154                FIND_QTDBUS()
155                AS_IF([test "x$HAVE_QTDBUS" = "xfalse"],
156                      [AC_MSG_ERROR([Could not find QtDBus])],
157                      [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus"]
158                     )],
159         ["xno"],
160               [AC_MSG_RESULT([no])
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"])
182 AX_BOOST_SYSTEM()
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"],
188         ["xshipped"],
189                    [AC_MSG_RESULT([shipped])
190                    QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG usesystemqtsingleapplication"],
191         ["xsystem"],
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,
203                   [openssl >= 1.0],
204                   [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
205                   LIBS="$openssl_LIBS $LIBS"])
207 PKG_CHECK_MODULES(zlib,
208                  [zlib >= 1.2.5.2],
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"],
217                   [AC_MSG_RESULT([no])
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()],
232                                            [AC_MSG_RESULT([no])
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.])])],
240                         [AC_MSG_RESULT([no])
241                          AC_MSG_ERROR([A compiler supporting C++11 is required.])])
242       ])
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
254 extract() {
255   if [[ -z "$*" ]]; then
256     echo "Input string required"
257     return 1
258   fi
260   # BSD sed needs an actual newline character in the substitute command
261   new_line='
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:]]]*//')
265   SAVEIFS=$IFS
266   IFS=$(printf "\n\b")
267   for i in $string; do
268     case "$(echo "$i" | cut -c1)" in
269       '') ;;
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";;
273     esac
274   done
275   IFS=$SAVEIFS
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
282 AC_SUBST(QBT_CC)
283 AC_SUBST(QBT_CXX)
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)
291 AC_OUTPUT(conf.pri)
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"
302 ret="$?"
304 AS_ECHO()
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])])
308 AS_ECHO()