Merge pull request #12269 from maboroshin/master
[qBittorrent.git] / configure.ac
blob55e673b3ef098aec4142f014083607691036e9c0
1 AC_INIT([qbittorrent], [v4.3.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_ENABLE(debug,
18               [AS_HELP_STRING([--enable-debug],
19                               [Enable debug build])],
20               [],
21               [enable_debug=no])
23 AC_ARG_ENABLE(stacktrace,
24               [AS_HELP_STRING([--enable-stacktrace],
25                               [Enable stacktrace feature (default=auto)])],
26               [],
27               [enable_stacktrace=auto])
29 AC_ARG_ENABLE(gui,
30               [AS_HELP_STRING([--disable-gui],
31                               [Disable the GUI for headless running. Disables QtDBus and the GeoIP Database.])],
32               [],
33               [enable_gui=yes])
35 AC_ARG_ENABLE(systemd,
36               [AS_HELP_STRING([--enable-systemd],
37                               [Install the systemd service file (headless only).])],
38               [],
39               [enable_systemd=no])
41 AC_ARG_ENABLE(webui,
42               [AS_HELP_STRING([--disable-webui],
43                               [Disable the WebUI.])],
44               [],
45               [enable_webui=yes])
47 AC_ARG_ENABLE(qt-dbus,
48               [AS_HELP_STRING([--disable-qt-dbus],
49                               [Disable use of QtDBus (GUI only)])],
50               [],
51               [enable_qt_dbus=yes])
53 # Detect OS
54 AC_MSG_CHECKING([whether OS is FreeBSD])
55 AS_IF([expr "$host_os" : ".*freebsd.*" > /dev/null],
56       [AC_MSG_RESULT([yes])
57       LIBS="-lexecinfo $LIBS"],
58       [AC_MSG_RESULT([no])])
60 AC_MSG_CHECKING([whether OS is macOS])
61 AS_IF([expr "$host_os" : ".*darwin.*" > /dev/null],
62       [AC_MSG_RESULT([yes])
63       enable_qt_dbus=no],
64       [AC_MSG_RESULT([no])])
66 # Require 0.23 pkg-config
67 PKG_PROG_PKG_CONFIG([0.23])
68 AS_IF([test "x$PKG_CONFIG" = "x"],
69       [AC_MSG_ERROR([Could not find pkg-config])])
71 # Check which arguments were set and act accordingly
72 AC_MSG_CHECKING([whether to enable the Debug build])
73 AS_CASE(["x$enable_debug"],
74         ["xno"],
75               [AC_MSG_RESULT([no])
76               QBT_ADD_CONFIG="$QBT_ADD_CONFIG release"
77               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG debug"],
78         ["xyes"],
79                [AC_MSG_RESULT([yes])
80                QBT_ADD_CONFIG="$QBT_ADD_CONFIG debug"
81                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG release"],
82         [AC_MSG_RESULT([$enable_debug])
83         AC_MSG_ERROR([Unknown option "$enable_debug". Use either "yes" or "no".])])
85 AC_MSG_CHECKING([whether to enable the stacktrace feature])
86 AS_CASE(["x$enable_stacktrace"],
87         ["xno"],
88               [AC_MSG_RESULT([no])
89               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"],
90         ["xyes"],
91                [AC_MSG_RESULT([yes])
92                QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
93         ["xauto"],
94                 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <execinfo.h>]])],
95                 [AC_MSG_RESULT([yes])
96                 QBT_ADD_CONFIG="$QBT_ADD_CONFIG stacktrace"],
97                 [AC_MSG_RESULT([no])
98                 QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG stacktrace"])],
99         [AC_MSG_RESULT([$enable_stacktrace])
100         AC_MSG_ERROR([Unknown option "$enable_stacktrace". Use either "yes" or "no".])])
102 AC_MSG_CHECKING([whether to enable the GUI])
103 AS_CASE(["x$enable_gui"],
104         ["xyes"],
105                [AC_MSG_RESULT([yes])
106                enable_systemd=[no]
107                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nogui"],
108         ["xno"],
109               [AC_MSG_RESULT([no])
110               enable_qt_dbus=[no]
111               QBT_ADD_CONFIG="$QBT_ADD_CONFIG nogui"],
112         [AC_MSG_RESULT([$enable_gui])
113         AC_MSG_ERROR([Unknown option "$enable_gui". Use either "yes" or "no".])])
115 AC_MSG_CHECKING([whether to install the systemd service file])
116 AS_CASE(["x$enable_systemd"],
117         ["xyes"],
118                [AC_MSG_RESULT([yes])
119                QBT_ADD_CONFIG="$QBT_ADD_CONFIG systemd"],
120         ["xno"],
121               [AC_MSG_RESULT([no])
122               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG systemd"],
123         [AC_MSG_RESULT([$enable_systemd])
124         AC_MSG_ERROR([Unknown option "$enable_systemd". Use either "yes" or "no".])])
126 AC_MSG_CHECKING([whether to enable the WebUI])
127 AS_CASE(["x$enable_webui"],
128         ["xyes"],
129                [AC_MSG_RESULT([yes])
130                QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG nowebui"],
131         ["xno"],
132               [AC_MSG_RESULT([no])
133               QBT_ADD_CONFIG="$QBT_ADD_CONFIG nowebui"],
134         [AC_MSG_RESULT([$enable_webui])
135         AC_MSG_ERROR([Unknown option "$enable_webui". Use either "yes" or "no".])])
137 FIND_QT5()
138 AS_IF([test "x$QT_QMAKE" = "x"],
139       [AC_MSG_ERROR([Could not find qmake])
140       ])
141 AS_IF([test "x$enable_gui" = "xyes"],
142       [PKG_CHECK_MODULES(Qt5Svg, [Qt5Svg >= 5.5.1])
143       ])
144 AC_MSG_CHECKING([whether QtDBus should be enabled])
145 AS_CASE(["x$enable_qt_dbus"],
146         ["xyes"],
147                [AC_MSG_RESULT([yes])
148                FIND_QTDBUS()
149                AS_IF([test "x$HAVE_QTDBUS" = "xfalse"],
150                      [AC_MSG_ERROR([Could not find QtDBus])],
151                      [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus"]
152                     )],
153         ["xno"],
154               [AC_MSG_RESULT([no])
155               QBT_REMOVE_CONFIG="$QBT_REMOVE_CONFIG dbus"],
156         [AC_MSG_RESULT([$enable_qt_dbus])
157         AC_MSG_ERROR([Unknown option "$enable_qt_dbus". Use either "yes" or "no".])])
160 AX_BOOST_BASE([1.40],
161               [AC_MSG_NOTICE([Boost CXXFLAGS: "$BOOST_CPPFLAGS"])
162                AC_MSG_NOTICE([Boost LDFLAGS: "$BOOST_LDFLAGS"])],
163               [AC_MSG_ERROR([Could not find Boost])])
164 CXXFLAGS="$BOOST_CPPFLAGS $CXXFLAGS"
165 LDFLAGS="$BOOST_LDFLAGS $LDFLAGS"
167 # add workaround for problematic boost version
168 # taken from ax_boost_base.m4
169 m4_define([DETECT_BOOST_VERSION_PROGRAM],
170     [AC_LANG_PROGRAM([[#include <boost/version.hpp>]],
171                      [[(void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))]));]])])
173 AC_COMPILE_IFELSE([DETECT_BOOST_VERSION_PROGRAM(106000)], [],
174     [QBT_ADD_DEFINES="$QBT_ADD_DEFINES BOOST_NO_CXX11_RVALUE_REFERENCES"])
176 AX_BOOST_SYSTEM()
177 AC_MSG_NOTICE([Boost.System LIB: "$BOOST_SYSTEM_LIB"])
178 LIBS="$BOOST_SYSTEM_LIB $LIBS"
180 PKG_CHECK_MODULES(libtorrent,
181                   [libtorrent-rasterbar >= 1.1.10],
182                   [CXXFLAGS="$libtorrent_CFLAGS $CXXFLAGS"
183                   LIBS="$libtorrent_LIBS $LIBS"])
185 PKG_CHECK_MODULES(openssl,
186                   [openssl >= 1.0],
187                   [CXXFLAGS="$openssl_CFLAGS $CXXFLAGS"
188                   LIBS="$openssl_LIBS $LIBS"])
190 PKG_CHECK_MODULES(zlib,
191                  [zlib >= 1.2.5.2],
192                  [CXXFLAGS="$zlib_CFLAGS $CXXFLAGS"
193                  LIBS="$zlib_LIBS $LIBS"])
195 # Check if already in >= C++14 mode because of the flags returned by one of the above packages
196 TMP_CXXFLAGS="$CXXFLAGS"
197 CXXFLAGS=""
198 AC_MSG_CHECKING([if compiler defaults to C++14 or later mode])
199 AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
200                   [AC_MSG_RESULT([yes])
201                    QBT_CXX14_FOUND="yes"],
202                   [AC_MSG_RESULT([no])
203                    QBT_CXX14_FOUND="no"])
205 # In case of no, check if the compiler can support at least C++14
206 # and if yes, enable it leaving a warning to the user
207 AS_IF([test "x$QBT_CXX14_FOUND" = "xno"],
208       [AC_MSG_CHECKING([if compiler supports C++14])
209        CXXFLAGS="-std=c++14"
210        AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
211                         [AC_MSG_RESULT([yes])
212                          AC_MSG_CHECKING([if C++14 is disabled by the set compiler flags])
213                          # prepend the flag so it won't override conflicting user defined flags
214                          CXXFLAGS="-std=c++14 $TMP_CXXFLAGS"
215                          AC_COMPILE_IFELSE([DETECT_CPP14_PROGRAM()],
216                                            [AC_MSG_RESULT([no])
217                                             QBT_ADD_CONFIG="$QBT_ADD_CONFIG c++14"
218                                             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.])],
219                                            [AC_MSG_RESULT([yes])
220                                             AC_MSG_ERROR([The compiler supports C++14 but the user or a dependency has explicitly enabled a lower mode.])])],
221                         [AC_MSG_RESULT([no])
222                          AC_MSG_ERROR([A compiler supporting C++14 is required.])])
223       ])
224 CXXFLAGS="$TMP_CXXFLAGS"
226 # These are required because autoconf doesn't expand these **particular**
227 # vars automatically. And qmake cannot autoexpand them.
228 AX_DEFINE_DIR([EXPAND_PREFIX], [prefix])
229 AX_DEFINE_DIR([EXPAND_BINDIR], [bindir])
230 AX_DEFINE_DIR([EXPAND_DATADIR], [datadir])
231 AX_DEFINE_DIR([EXPAND_MANDIR], [mandir])
233 # Original extract() function contributed by pmzqla
234 # $*: Strings to parse
235 # Set $QBT_CONF_DEFINES, $QBT_CONF_INCLUDES, $QBT_CONF_EXTRA_CFLAGS
236 extract() {
237   if [[ -z "$*" ]]; then
238     echo "Input string required"
239     return 1
240   fi
242   # BSD sed needs an actual newline character in the substitute command
243   new_line='
245   # Convert " -" to "\n" if not between quotes and remove possible leading white spaces
246   string=$(echo " $*" | $SED -e "s: -:\\${new_line}:g" -e 's:"\(.*\)\n\(.*\)":\"\1 -\2":g' -e "s:'\(.*\)\n\(.*\)':\'\1 -\2':g" -e 's/^[[[:space:]]]*//')
247   SAVEIFS=$IFS
248   IFS=$(printf "\n\b")
249   for i in $string; do
250     case "$(echo "$i" | cut -c1)" in
251       '') ;;
252       D) QBT_CONF_DEFINES="$QBT_CONF_DEFINES $(echo $i | cut -c2-)";;
253       I) QBT_CONF_INCLUDES="$QBT_CONF_INCLUDES $(echo $i | cut -c2-)";;
254       *) QBT_CONF_EXTRA_CFLAGS="$QBT_CONF_EXTRA_CFLAGS -$i";;
255     esac
256   done
257   IFS=$SAVEIFS
260 extract "$CFLAGS $CXXFLAGS"
261 QBT_ADD_DEFINES="$QBT_ADD_DEFINES $QBT_CONF_DEFINES"
263 # Substitute the values of these vars in conf.pri.in
264 AC_SUBST(QBT_CC)
265 AC_SUBST(QBT_CXX)
266 AC_SUBST(QBT_CONF_INCLUDES)
267 AC_SUBST(QBT_CONF_EXTRA_CFLAGS)
268 AC_SUBST(QBT_ADD_CONFIG)
269 AC_SUBST(QBT_REMOVE_CONFIG)
270 AC_SUBST(QBT_ADD_DEFINES)
271 AC_SUBST(QBT_REMOVE_DEFINES)
273 AC_OUTPUT(conf.pri)
274 AS_IF([test "x$enable_systemd" = "xyes"],
275       [AC_OUTPUT(dist/unix/systemd/qbittorrent-nox@.service)])
277 AC_MSG_NOTICE([Running qmake to generate the makefile...])
278 TOPDIR="$(cd "$(dirname "$0")" && pwd)"
279 $QT_QMAKE -r "$TOPDIR/qbittorrent.pro" "QMAKE_LRELEASE=$QMAKE_LRELEASE"
280 qmake_ret="$?"
282 AS_ECHO()
283 AS_IF([test "x$qmake_ret" != "x0"],
284       [AC_MSG_ERROR([$QT_QMAKE failed to generate the makefile])])
286 AC_MSG_NOTICE([Good, the configure finished.])
287 AS_ECHO()