Detect C++ implementations that support constexpr strlen()
[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 AC_INIT(folly, 0.1, folly@fb.com)
7 AC_CONFIG_SRCDIR([Likely.h])
8 AC_CONFIG_HEADERS([config.h])
9 AX_PREFIX_CONFIG_H([folly-config.h], [folly], [config.h])
10 AC_CONFIG_AUX_DIR([build-aux])
11
12 AM_INIT_AUTOMAKE([foreign dist-bzip2 nostdinc])
13
14 AC_CONFIG_MACRO_DIR([m4])
15
16 AC_PROG_INSTALL
17 AM_PROG_LIBTOOL
18
19 AC_LANG([C++])
20
21 # Checks for programs.
22 AC_PROG_CXX
23 AC_PROG_CC
24 AC_CXX_COMPILE_STDCXX_0X
25
26 # Checks for libraries.
27 AC_CHECK_LIB([glog],[openlog],[],[AC_MSG_ERROR(
28              [Please install google-glog library])])
29 AC_CHECK_LIB([gflags],[getenv],[],[AC_MSG_ERROR(
30              [Please install google-gflags library])])
31
32 # check for boost libs
33 AX_BOOST_BASE([1.20.0], [], [AC_MSG_ERROR(
34               [Please install boost >= 1.20.0 (thread, regex, and system)])])
35 AX_BOOST_THREAD
36 AX_BOOST_REGEX
37 AX_BOOST_SYSTEM
38
39 # Checks for header files.
40 AC_HEADER_STDC
41 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])
42
43 AC_CHECK_HEADER(double-conversion.h, [], [AC_MSG_ERROR(
44                 [Couldn't find double-conversion.h, please download from \
45                 http://code.google.com/p/double-conversion/])], [])
46 AC_CHECK_LIB([double_conversion_pic],[ceil],[],[AC_MSG_ERROR(
47              [Please install double-conversion library])])
48
49 # Checks for typedefs, structures, and compiler characteristics.
50 AC_HEADER_STDBOOL
51 AC_C_CONST
52 AC_C_INLINE
53 AC_TYPE_SIZE_T
54 AC_HEADER_TIME
55 AC_C_VOLATILE
56 AC_CHECK_TYPE([__int128],
57   [AC_DEFINE([HAVE_INT128_T], [1], [Define if __int128 exists])],
58   [AC_DEFINE([HAVE_INT128_T], [0], [Define if __int128 does not exist])])
59 AC_CHECK_TYPES([ptrdiff_t])
60 AC_COMPILE_IFELSE(
61   [AC_LANG_SOURCE[
62     #pragma GCC diagnostic error "-Wattributes"
63     extern "C" void (*test_ifunc(void))() { return 0; }
64     void func() __attribute__((ifunc("test_ifunc")));]
65   ],
66   [AC_DEFINE([HAVE_IFUNC], [1], [Define to 1 if the compiler supports ifunc])],
67   [AC_DEFINE([HAVE_IFUNC], [0], [Define to 0 if the compiler doesn't support ifunc])]
68 )
69 AC_COMPILE_IFELSE(
70   [AC_LANG_SOURCE[class C { virtual void f() final {} virtual void g() {} };
71                   class D : public C { virtual void g() override {} };]],
72   [AC_DEFINE([FINAL], [final],
73              [Define to "final" if the compiler supports C++11 "final"]),
74    AC_DEFINE([OVERRIDE], [override],
75              [Define to "override" if the compiler supports C++11 "override"])],
76   [AC_DEFINE([FINAL], [],
77              [Define to "final" if the compiler supports C++11 "final"]),
78    AC_DEFINE([OVERRIDE], [],
79              [Define to "override" if the compiler supports C++11 "override"])]
80 )
81
82 AC_COMPILE_IFELSE(
83   [AC_LANG_SOURCE[
84     #include <thread>
85     #include <chrono>
86     void func() { std::this_thread::sleep_for(std::chrono::seconds(1)); }]],
87   [AC_DEFINE([HAVE_STD__THIS_THREAD__SLEEP_FOR], [1],
88              [Define to 1 if std::this_thread::sleep_for() is defined.])])
89
90 AC_COMPILE_IFELSE(
91   [AC_LANG_SOURCE[
92     #include <cstring>
93     static constexpr int val = strlen("foo");]],
94   [AC_DEFINE([HAVE_CONSTEXPR_STRLEN], [1],
95              [Define to 1 if strlen(3) is constexpr.])])
96
97 AC_COMPILE_IFELSE(
98   [AC_LANG_SOURCE[
99     #include <type_traits>
100     #if !_LIBCPP_VERSION
101     #error No libc++
102     #endif
103     void func() {}]
104   ],
105   [AC_DEFINE([USE_LIBCPP], [1], [Define to 1 if we're using libc++.])])
106
107 # Check for clock_gettime(2). This is not in an AC_CHECK_FUNCS() because we
108 # want to link with librt if necessary.
109 AC_SEARCH_LIBS([clock_gettime], [rt],
110   AC_DEFINE(
111     [HAVE_CLOCK_GETTIME],
112     [1],
113     [Define to 1 if we support clock_gettime(2).]),
114   [])
115
116 # Checks for library functions.
117 AC_CHECK_FUNCS([getdelim \
118                 gettimeofday \
119                 memmove \
120                 memset \
121                 pow \
122                 strerror \
123                 pthread_yield \
124                 rallocm \
125                 malloc_size \
126                 malloc_usable_size \
127                 memrchr])
128
129 if test "$ac_cv_func_pthread_yield" = "no"; then
130    AC_CHECK_HEADERS([sched.h])
131    AC_CHECK_FUNCS([sched_yield])
132 fi
133
134 CXX_FLAGS=""
135 if test "$ac_cv_cxx_compile_cxx0x_cxx" = yes; then
136    CXX_FLAGS="-std=c++0x"
137 fi
138 if test "$ac_cv_cxx_compile_cxx0x_gxx" = yes; then
139    CXX_FLAGS="-std=gnu++0x"
140 fi
141
142 AC_SUBST(AM_CPPFLAGS, '-I../$(top_srcdir)'" "'-I$(top_srcdir)/io'" "'-I$(top_srcdir)/test'" $CXX_FLAGS $BOOST_CPPFLAGS")
143 AC_SUBST(AM_LDFLAGS, "$BOOST_LDFLAGS $BOOST_THREAD_LIB $BOOST_SYSTEM_LIB $BOOST_REGEX_LIB -lpthread")
144
145 AM_CONDITIONAL([HAVE_STD_THREAD], [test "$ac_cv_header_features" = "yes"])
146 AM_CONDITIONAL([HAVE_X86_64], [test "$build_cpu" = "x86_64"])
147 AM_CONDITIONAL([HAVE_LINUX], [test "$build_os" == "linux-gnu"])
148
149 # Output
150 AC_CONFIG_FILES([Makefile
151                  test/Makefile
152                  test/function_benchmark/Makefile])
153 AC_OUTPUT