Add ./configure check for vsnprintf returning negative on error
[folly.git] / folly / configure.ac
1
2 #                                               -*- Autoconf -*-
3 # Process this file with autoconf to produce a configure script.
4
5 AC_PREREQ(2.59)
6
7 m4_define([folly_version_str], m4_esyscmd_s([cat VERSION]))
8
9 AC_INIT([folly], m4_translit(folly_version_str, [:], [.]), [folly@fb.com])
10
11 # We assume all revisions are backwards incompatible.
12 LT_VERSION=folly_version_str:0
13 AC_SUBST([LT_VERSION])
14
15 AC_CONFIG_SRCDIR([Likely.h])
16 AC_CONFIG_HEADERS([config.h])
17 AX_PREFIX_CONFIG_H([folly-config.h], [folly], [config.h])
18 AC_CONFIG_AUX_DIR([build-aux])
19
20 AM_INIT_AUTOMAKE([foreign dist-bzip2 nostdinc subdir-objects])
21
22 AC_CONFIG_MACRO_DIR([m4])
23
24 AX_CONFIG_FEATURE_DEFAULT_DISABLED
25 AX_CONFIG_FEATURE(
26         [deprecated-assoc],
27         [supports deprecated associative containers (hash_map/hash_set)],
28         [HAVE_DEPRECATED_ASSOC],
29         [Define if you want to support deprecated associative containers])
30
31 AC_PROG_INSTALL
32 AM_PROG_LIBTOOL
33
34 AC_LANG([C++])
35
36 # Checks for programs.
37 AC_PROG_CXX
38 AC_PROG_CC
39 AC_CXX_COMPILE_STDCXX_0X
40
41 # Be sure to add any -std option to CXXFLAGS before we invoke any
42 # AC_COMPILE_IFELSE() or similar macros. Any such macros that are invoked
43 # before we update CXXFLAGS will not be run with the same options that we use
44 # during the real build.
45 STD=""
46 if test "x$ac_cv_cxx_compile_cxx0x_cxx" = xyes; then
47    STD="-std=c++0x"
48 fi
49 if test "x$ac_cv_cxx_compile_cxx0x_gxx" = xyes; then
50    STD="-std=gnu++0x"
51 fi
52
53 CXXFLAGS="$STD $CXXFLAGS"
54
55 # Checks for libraries.
56 AC_CHECK_LIB([glog],[openlog],[],[AC_MSG_ERROR(
57              [Please install google-glog library])])
58 AC_CHECK_LIB([gflags],[getenv],[],[AC_MSG_ERROR(
59              [Please install google-gflags library])])
60
61 AC_CHECK_LIB(ssl,
62         SSL_ctrl,
63         [],
64         [AC_MSG_ERROR(["Error: libssl required"])])
65
66 # check for boost libs
67 AX_BOOST_BASE([1.51.0], [], [AC_MSG_ERROR(
68               [Please install boost >= 1.51.0 (context, thread, regex, and system)])])
69 AX_BOOST_CONTEXT
70 AX_BOOST_THREAD
71 AX_BOOST_REGEX
72 AX_BOOST_SYSTEM
73 AX_BOOST_FILESYSTEM
74
75 # Check for python interpreter
76 AM_PATH_PYTHON
77
78 # Checks for header files.
79 AC_HEADER_STDC
80 AC_CHECK_HEADERS([fcntl.h features.h inttypes.h limits.h stdint.h stdlib.h string.h sys/time.h unistd.h mutex.h malloc.h emmintrin.h byteswap.h bits/functexcept.h bits/c++config.h])
81
82 AC_CHECK_HEADER(double-conversion/double-conversion.h, [], [AC_MSG_ERROR(
83                 [Couldn't find double-conversion.h, please download from \
84                  https://github.com/google/double-conversion/])], [])
85 AC_CHECK_LIB([double-conversion],[ceil],[],[AC_MSG_ERROR(
86              [Please install double-conversion library])])
87
88 AC_CHECK_LIB([event], [event_set], [], [AC_MSG_ERROR([Unable to find libevent])])
89
90 AC_CHECK_LIB([jemalloc], [xallocx])
91
92 # Checks for typedefs, structures, and compiler characteristics.
93 AC_HEADER_STDBOOL
94 AC_C_CONST
95 AC_C_INLINE
96 AC_TYPE_SIZE_T
97 AC_HEADER_TIME
98 AC_C_VOLATILE
99 AC_CHECK_TYPE([__int128], AC_DEFINE([HAVE_INT128_T], [1], [Define if we have __int128]))
100 AC_CHECK_TYPES([ptrdiff_t, pthread_spinlock_t])
101
102 AC_CACHE_CHECK(
103   [for ifunc support],
104   [folly_cv_prog_cc_ifunc],
105   [AC_COMPILE_IFELSE(
106     [AC_LANG_SOURCE[
107       #pragma GCC diagnostic error "-Wattributes"
108       extern "C" void (*test_ifunc(void))() { return 0; }
109       void func() __attribute__((ifunc("test_ifunc")));]
110     ],
111     [folly_cv_prog_cc_ifunc=yes],
112     [folly_cv_prog_cc_ifunc=no])])
113
114 if test "$folly_cv_prog_cc_ifunc" = "yes"; then
115   AC_DEFINE([HAVE_IFUNC], [1], [Define to 1 if the compiler supports ifunc])
116 fi
117
118 AC_CACHE_CHECK(
119   [for final and override support],
120   [folly_cv_c_final_override],
121   [AC_COMPILE_IFELSE(
122     [AC_LANG_SOURCE[class C { virtual void f() final {} virtual void g() {} };
123                     class D : public C { virtual void g() override {} };]],
124     [folly_cv_c_final_override=yes],
125     [folly_cv_c_final_override=no])])
126
127 if test "$folly_cv_c_final_override" = "yes"; then
128   final_val=final
129   override_val=override
130 else
131   final_val=
132   override_val=
133 fi
134
135 AC_DEFINE_UNQUOTED(
136   [FINAL], [$final_val],
137   [Define to "final" if the compiler supports C++11 "final"])
138 AC_DEFINE_UNQUOTED(
139   [OVERRIDE], [$override_val],
140   [Define to "override" if the compiler supports C++11 "override"])
141
142 AC_CACHE_CHECK(
143   [for std::this_thread::sleep_for],
144   [folly_cv_func_this_thread_sleep_for],
145   [AC_COMPILE_IFELSE(
146     [AC_LANG_SOURCE[
147       #include <thread>
148       #include <chrono>
149       void func() { std::this_thread::sleep_for(std::chrono::seconds(1)); }]],
150     [folly_cv_func_this_thread_sleep_for=yes],
151     [folly_cv_func_this_thread_sleep_for=no])])
152
153 if test "$folly_cv_func_this_thread_sleep_for" = yes; then
154     AC_DEFINE([HAVE_STD__THIS_THREAD__SLEEP_FOR], [1],
155               [Define to 1 if std::this_thread::sleep_for() is defined.])
156 fi
157
158 AC_CACHE_CHECK(
159   [for constexpr strlen],
160   [folly_cv_func_constexpr_strlen],
161   [AC_COMPILE_IFELSE(
162     [AC_LANG_SOURCE[
163       #include <cstring>
164       static constexpr int val = strlen("foo");]],
165     [folly_cv_func_constexpr_strlen=yes],
166     [folly_cv_func_constexpr_strlen=no])])
167
168 if test "$folly_cv_func_constexpr_strlen" = yes; then
169     AC_DEFINE([HAVE_CONSTEXPR_STRLEN], [1],
170               [Define to 1 if strlen(3) is constexpr.])
171 fi
172
173 AC_CACHE_CHECK(
174   [for libc++],
175   [folly_cv_lib_libcpp],
176   [AC_COMPILE_IFELSE(
177     [AC_LANG_SOURCE[
178       #include <type_traits>
179       #if !_LIBCPP_VERSION
180       #error No libc++
181       #endif
182       void func() {}]
183     ],
184     [folly_cv_lib_libcpp=yes],
185     [folly_cv_lib_libcpp=no])])
186
187 if test "$folly_cv_lib_libcpp" = yes; then
188   AC_DEFINE([USE_LIBCPP], [1], [Define to 1 if we're using libc++.])
189 fi
190
191 AC_CACHE_CHECK(
192   [for usable std::is_trivially_copyable],
193   [folly_cv_decl_std_is_trivially_copyable],
194   [AC_COMPILE_IFELSE(
195     [AC_LANG_SOURCE[
196       #include <type_traits>
197       const bool val = std::is_trivially_copyable<bool>::value;]
198     ],
199     [folly_cv_decl_std_is_trivially_copyable=yes],
200     [folly_cv_decl_std_is_trivially_copyable=no])])
201
202 if test "$folly_cv_decl_std_is_trivially_copyable" = yes; then
203   AC_DEFINE([HAVE_STD__IS_TRIVIALLY_COPYABLE], [1],
204             [Define to 1 if we have a usable std::is_trivially_copyable<T>
205              implementation.])
206 fi
207
208 AC_CACHE_CHECK(
209   [gflags namespace],
210   [folly_cv_decl_gflags_namespace],
211   [AC_COMPILE_IFELSE(
212     [AC_LANG_SOURCE[
213       #include <gflags/gflags.h>
214       void foo() { gflags::GetArgv(); }]
215     ],
216     [folly_cv_decl_gflags_namespace=gflags],
217     [AC_COMPILE_IFELSE(
218       [AC_LANG_SOURCE[
219         #include <gflags/gflags.h>
220         void foo() { google::GetArgv(); }]
221       ],
222       [folly_cv_decl_gflags_namespace=google],
223       [folly_cv_decl_gflags_namespace=error])])])
224
225 if test "$folly_cv_decl_gflags_namespace" = error; then
226   AC_MSG_ERROR([Cannot determine gflags namespace])
227 else
228   AC_DEFINE_UNQUOTED(
229     [GFLAGS_NAMESPACE], [$folly_cv_decl_gflags_namespace],
230     [Define to gflags namespace (usually "google" or "gflags")])
231   if test "$folly_cv_decl_gflags_namespace" != gflags; then
232      AC_DEFINE([UNUSUAL_GFLAGS_NAMESPACE], [1],
233                [Define to 1 if the gflags namespace is not "gflags"])
234   fi
235 fi
236
237 # Figure out if we support weak symbols. If not, we will link in some null
238 # stubs for functions that would otherwise be weak.
239 AC_CACHE_CHECK(
240   [for weak symbol support],
241   [folly_cv_prog_cc_weak_symbols],
242   [AC_LINK_IFELSE(
243     [AC_LANG_SOURCE[
244       extern "C" void configure_link_extern_weak_test() __attribute__((weak));
245       int main(int argc, char** argv) {
246           return configure_link_extern_weak_test == nullptr;
247       }]],
248     [folly_cv_prog_cc_weak_symbols="yes"],
249     [folly_cv_prog_cc_weak_symbols="no"])])
250
251 if test "$folly_cv_prog_cc_weak_symbols" = yes; then
252   AC_DEFINE([HAVE_WEAK_SYMBOLS], [1],
253             [Define to 1 if the linker supports weak symbols.])
254 fi
255
256 AC_CACHE_CHECK(
257   [for vsnprintf reporting bad format strings],
258   [folly_cv_prog_vsnprintf_bad_format],
259   [AC_RUN_IFELSE(
260     [AC_LANG_SOURCE[
261       #include <stdio.h>
262
263       int main(int argc, char** argv) {
264           char buf[256];
265           return vsnprintf(buf, sizeof(buf), "%", 1) < 0 ? 0 : 1;
266       }]],
267     [folly_cv_prog_vsnprintf_bad_format="yes"],
268     [folly_cv_prog_vsnprintf_bad_format="no"])])
269
270 if test "$folly_cv_prog_vsnprintf_bad_format" = yes; then
271   AC_DEFINE([HAVE_VSNPRINTF_ERRORS], [1],
272             [Define to 1 if the vsnprintf supports returning errors on bad format strings.])
273 fi
274
275 AC_SEARCH_LIBS([cplus_demangle_v3_callback], [iberty_pic iberty])
276 if test "$ac_cv_search_cplus_demangle_v3_callback" != "no" ; then
277   AC_DEFINE([HAVE_CPLUS_DEMANGLE_V3_CALLBACK], [1],
278             [Define to 1 if we have cplus_demangle_v3_callback.])
279 fi
280
281 # Check for clock_gettime(2). This is not in an AC_CHECK_FUNCS() because we
282 # want to link with librt if necessary.
283 AC_SEARCH_LIBS([clock_gettime], [rt],
284   AC_DEFINE(
285     [HAVE_CLOCK_GETTIME],
286     [1],
287     [Define to 1 if we support clock_gettime(2).]),
288   [])
289
290 # Check for pthread_atfork(3). This is not in an AC_CHECK_FUNCS() because we
291 # want to include pthread.h if necessary.
292 AC_CACHE_CHECK(
293   [for pthread_atfork support],
294   [folly_cv_prog_cc_pthread_atfork],
295   [AC_COMPILE_IFELSE(
296     [AC_LANG_SOURCE[
297       #include <pthread.h>
298       void func() {pthread_atfork(NULL, NULL, NULL);}]
299     ],
300     [folly_cv_prog_cc_pthread_atfork=yes],
301     [folly_cv_prog_cc_pthread_atfork=no])])
302
303 if test "$folly_cv_prog_cc_pthread_atfork" = "yes"; then
304   AC_DEFINE([HAVE_PTHREAD_ATFORK], [1], [Define to 1 if the compiler supports pthread_atfork])
305 fi
306
307 # Checks for library functions.
308 AC_CHECK_FUNCS([getdelim \
309                 gettimeofday \
310                 memmove \
311                 memset \
312                 pow \
313                 strerror \
314                 pthread_yield \
315                 malloc_size \
316                 malloc_usable_size \
317                 memrchr \
318                 pipe2])
319
320 if test "$ac_cv_func_pthread_yield" = "no"; then
321    AC_CHECK_HEADERS([sched.h])
322    AC_CHECK_FUNCS([sched_yield])
323 fi
324
325 AC_CHECK_HEADER([lz4.h], AC_CHECK_LIB([lz4], [LZ4_decompress_safe]))
326 AC_CHECK_HEADER([snappy.h], AC_CHECK_LIB([snappy], [main]))
327 AC_CHECK_HEADER([zlib.h], AC_CHECK_LIB([z], [main]))
328 AC_CHECK_HEADER([lzma.h], AC_CHECK_LIB([lzma], [main]))
329
330 # Include directory that contains "folly" so #include <folly/Foo.h> works
331 AM_CPPFLAGS='-I$(top_srcdir)/..'
332 AM_CPPFLAGS="$AM_CPPFLAGS $BOOST_CPPFLAGS"
333 AM_LDFLAGS="$AM_LDFLAGS $BOOST_CONTEXT_LIB $BOOST_THREAD_LIB $BOOST_FILESYSTEM_LIB"
334 AM_LDFLAGS="$AM_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_REGEX_LIB -lpthread"
335
336 AC_SUBST([AM_CPPFLAGS])
337 AC_SUBST([AM_LDFLAGS])
338
339 AM_CONDITIONAL([HAVE_STD_THREAD], [test "$ac_cv_header_features" = "yes"])
340 AM_CONDITIONAL([HAVE_X86_64], [test "$build_cpu" = "x86_64"])
341 AM_CONDITIONAL([HAVE_LINUX], [test "$build_os" == "linux-gnu"])
342 AM_CONDITIONAL([HAVE_WEAK_SYMBOLS],
343                [test "$folly_cv_prog_cc_weak_symbols" = "yes"])
344 AM_CONDITIONAL([HAVE_BITS_FUNCTEXCEPT], [test "$ac_cv_header_bits_functexcept_h" = "yes"])
345
346 # Output
347 AC_CONFIG_FILES([Makefile
348                  test/Makefile
349                  test/function_benchmark/Makefile])
350 AC_OUTPUT