-
Notifications
You must be signed in to change notification settings - Fork 8
/
configure.ac
180 lines (148 loc) · 5.86 KB
/
configure.ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
AC_INIT([utreexo], [0.0.1], [http://github.com/dergoegge/libutreexo])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AC_PREREQ(2.60)
AC_CONFIG_SRCDIR([src/accumulator.cpp])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([build-aux/m4])
AM_INIT_AUTOMAKE([subdir-objects foreign])
LT_INIT
LT_LANG([C++])
AC_LANG([C++])
AC_PATH_PROG(CCACHE,ccache)
AC_ARG_ENABLE([ccache],
[AS_HELP_STRING([--disable-ccache],
[do not use ccache for building (default is to use if found)])],
[use_ccache=$enableval],
[use_ccache=auto])
AC_ARG_ENABLE(tests,
AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
[use_tests=$enableval],
[use_tests=yes])
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug],
[use compiler flags and macros suited for debugging (default is no)])],
[enable_debug=$enableval],
[enable_debug=no])
AC_ARG_ENABLE(bench,
AS_HELP_STRING([--disable-bench],[do not compile benchmarks (default is to compile)]),
[use_bench=$enableval],
[use_bench=yes])
AC_ARG_ENABLE([fuzz],
AS_HELP_STRING([--enable-fuzz],
[build for fuzzing (default no). enabling this will disable all other targets.]),
[enable_fuzz=$enableval],
[enable_fuzz=no])
AC_ARG_ENABLE([fuzz-cov],
AS_HELP_STRING([--enable-fuzz-cov],
[enable fuzz coverage reporting.]),
[enable_fuzz_cov=$enableval],
[enable_fuzz_cov=no])
AX_CHECK_COMPILE_FLAG([-Werror],[CXXFLAG_WERROR="-Werror"],[CXXFLAG_WERROR=""])
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory], [nodefault])
AX_CHECK_COMPILE_FLAG([-Wall],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wall"],,[[$CXXFLAG_WERROR]])
## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
## unknown options if any other warning is produced. Test the -Wfoo case, and
## set the -Wno-foo case if it works.
AX_CHECK_COMPILE_FLAG([-Wshift-count-overflow],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-shift-count-overflow"],,[[$CXXFLAG_WERROR]])
dnl SUPPRESSED_CPPFLAGS=SUPPRESS_WARNINGS([$SOME_CPPFLAGS])
dnl Replace -I with -isystem in $SOME_CPPFLAGS to suppress warnings from
dnl headers from its include directories and return the result.
dnl See -isystem documentation:
dnl https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html
dnl https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-isystem-directory
dnl Do not change "-I/usr/include" to "-isystem /usr/include" because that
dnl is not necessary (/usr/include is already a system directory) and because
dnl it would break GCC's #include_next.
AC_DEFUN([SUPPRESS_WARNINGS],
[$(echo $1 |${SED} -E -e 's/(^| )-I/\1-isystem /g' -e 's;-isystem /usr/include([/ ]|$);-I/usr/include\1;g')])
if test x$enable_fuzz = xyes; then
use_tests=no
use_bench=no
## TODO make these configurable
SANITIZER_LDFLAGS="-fsanitize=fuzzer,address,undefined"
SANITIZER_CXXFLAGS="-fsanitize=fuzzer,address,undefined"
fi
if test x$enable_fuzz_cov = xyes; then
use_tests=no
use_bench=no
CXXFLAGS="$CXXFLAGS -fprofile-instr-generate -fcoverage-mapping"
fi
if test "x$enable_debug" = xyes; then
dnl Clear default -g -O2 flags
## TODO: dont reset CXXFLAGS when they are already set.
CXXFLAGS=""
dnl Disable all optimizations
AX_CHECK_COMPILE_FLAG([-O0], [[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"]],,[[$CXXFLAG_WERROR]])
dnl Prefer -g3, fall back to -g if that is unavailable.
AX_CHECK_COMPILE_FLAG(
[-g3],
[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -g3"]],
[AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -g"]],,[[$CXXFLAG_WERROR]])],
[[$CXXFLAG_WERROR]])
AX_CHECK_PREPROC_FLAG([-DDEBUG],[[DEBUG_CPPFLAGS="$DEBUG_CPPFLAGS -DDEBUG"]],,[[$CXXFLAG_WERROR]])
AX_CHECK_PREPROC_FLAG([-DDEBUG_LOCKORDER],[[DEBUG_CPPFLAGS="$DEBUG_CPPFLAGS -DDEBUG_LOCKORDER"]],,[[$CXXFLAG_WERROR]])
AX_CHECK_PREPROC_FLAG([-DABORT_ON_FAILED_ASSUME],[[DEBUG_CPPFLAGS="$DEBUG_CPPFLAGS -DABORT_ON_FAILED_ASSUME"]],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-ftrapv],[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -ftrapv"],,[[$CXXFLAG_WERROR]])
fi
## Check for boost test framework if test are enabled.
if test x$use_tests = xyes; then
dnl Minimum required Boost version
define(MINIMUM_REQUIRED_BOOST, 1.58.0)
dnl Check for Boost libs
AX_BOOST_BASE([MINIMUM_REQUIRED_BOOST])
if test x$suppress_external_warnings != xno; then
BOOST_CPPFLAGS=SUPPRESS_WARNINGS($BOOST_CPPFLAGS)
fi
AX_BOOST_UNIT_TEST_FRAMEWORK
dnl Determine if -DBOOST_TEST_DYN_LINK is needed
AC_MSG_CHECKING([for dynamic linked boost test])
TEMP_LIBS="$LIBS"
LIBS="$LIBS $BOOST_LDFLAGS $BOOST_UNIT_TEST_FRAMEWORK_LIB"
TEMP_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
AC_LINK_IFELSE([AC_LANG_SOURCE([
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
])],
[AC_MSG_RESULT(yes)]
[TEST_DEFINES="$TEST_DEFINES -DBOOST_TEST_DYN_LINK"],
[AC_MSG_RESULT(no)])
LIBS="$TEMP_LIBS"
CPPFLAGS="$TEMP_CPPFLAGS"
fi
if test "x$use_ccache" != "xno"; then
AC_MSG_CHECKING(if ccache should be used)
if test x$CCACHE = x; then
if test "x$use_ccache" = "xyes"; then
AC_MSG_ERROR([ccache not found.]);
else
use_ccache=no
fi
else
use_ccache=yes
CC="$ac_cv_path_CCACHE $CC"
CXX="$ac_cv_path_CCACHE $CXX"
fi
AC_MSG_RESULT($use_ccache)
fi
if test "x$use_ccache" = "xyes"; then
AX_CHECK_COMPILE_FLAG([-Qunused-arguments],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Qunused-arguments"],,[[$CXXFLAG_WERROR]])
fi
VERIFY_DEFINES=-DUTREEXO_VERIFY
RELEASE_DEFINES=
AC_CONFIG_FILES([
Makefile
])
AC_SUBST(DEBUG_CPPFLAGS)
AC_SUBST(DEBUG_CXXFLAGS)
AC_SUBST(WARN_CXXFLAGS)
AC_SUBST(NOWARN_CXXFLAGS)
AC_SUBST(VERIFY_DEFINES)
AC_SUBST(RELEASE_DEFINES)
AC_SUBST(SANITIZER_LDFLAGS)
AC_SUBST(SANITIZER_CXXFLAGS)
AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
AM_CONDITIONAL([ENABLE_BENCH], [test "$use_bench" = "yes"])
AM_CONDITIONAL([ENABLE_FUZZ], [test x"$enable_fuzz" != x"no"])
AC_OUTPUT