blob: 38371164af30ec6748638f97fb3ae60f52a32c77 [file] [log] [blame]
William A. Kennington III4460f262018-11-02 17:20:52 -07001# Initialization
2AC_PREREQ([2.69])
3AC_INIT([stdplus], [0.1], [https://github.com/openbmc/stdplus/issues])
4AC_CONFIG_HEADERS([config.h])
5AC_CONFIG_MACRO_DIRS([m4])
6AC_CONFIG_AUX_DIR([build-aux])
7AM_INIT_AUTOMAKE([nostdinc foreign subdir-objects -Wall -Werror dist-xz tar-ustar])
8AM_SILENT_RULES([yes])
9AC_LANG([C++])
10
11# Make sure the default CFLAGS of `-O2 -g` don't override CODE_COVERAGE_CFLAGS
12# It is important that this comes before AC_PROG_C{C,XX}, as we are attempting
13# to stop them from populating default CFLAGS and CXXFLAGS.
14AS_IF([test "x$enable_tests" = "xno"], [enable_code_coverage=no])
15AS_IF([test "x$enable_code_coverage" != "xno"], [
16 AS_IF([test "x${CXXFLAGS+set}" != "xset"], [
17 AC_SUBST(CXXFLAGS, [""])
18 ])
19 AS_IF([test "x${CFLAGS+set}" != "xset"], [
20 AC_SUBST(CFLAGS, [""])
21 ])
22])
23
24# Checks for programs.
25AC_PROG_CXX
26AC_PROG_CC
27AM_PROG_AR
28AC_PROG_INSTALL
29AC_PROG_MAKE_SET
30
31# Checks for libtool
32LT_INIT # Removes 'unrecognized options: --with-libtool-sysroot'
33
34# Make sure the pkgconfigdata is configured for automake
35PKG_INSTALLDIR
36
37# Checks for typedefs, structures, and compiler characteristics.
38AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
39AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CFLAGS])
40AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CXXFLAGS])
41
42# Make it possible for users to choose to disable examples
43AC_ARG_ENABLE([examples], AC_HELP_STRING([--disable-examples],
44 [Build example programs]))
45AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" != "xno"])
46
47# Make it possible for users to choose if they want test support
48# explicitly or not at all
49AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
50 [Build test cases]))
51
52# Check/set gtest specific functions.
53AS_IF([test "x$enable_tests" != "xno"], [
54 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
55 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
56 AX_PTHREAD
57
58 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
59 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
60 AC_CHECK_HEADERS([gtest/gtest.h], [
61 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
62 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
63 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
64 ], [
65 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
66 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
67 ])
68 ])
69 ], [
70 AS_IF([test "x$enable_tests" = "xyes"], [
71 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
72 ])
73 ])
74 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
75
76 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
77 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
78 AC_CHECK_HEADERS([gmock/gmock.h], [], [
79 AS_IF([test "x$enable_tests" = "xyes"], [
80 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
81 ])
82 ])
83 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
84
85 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
86 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
87 AC_CHECK_LIB([gtest], [main], [
88 AS_IF([test "x$GTEST_LIBS" = "x"], [
89 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
90 ])
91 ], [
92 AS_IF([test "x$enable_tests" = "xyes"], [
93 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
94 ])
95 ])
96 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
97
98 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
99 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
100 AC_CHECK_LIB([gmock], [main], [
101 AS_IF([test "x$GMOCK_LIBS" = "x"], [
102 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
103 ])
104 ], [
105 AS_IF([test "x$enable_tests" = "xyes"], [
106 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
107 ])
108 ])
109 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
110])
111
112# Check for valgrind
113AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
114m4_foreach([vgtool], [valgrind_tool_list],
115 [AX_VALGRIND_DFLT(vgtool, [off])])
116AX_VALGRIND_DFLT([memcheck], [on])
117AX_VALGRIND_CHECK
118AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
119m4_foreach([vgtool], [valgrind_tool_list],
120 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
121
122# Code coverage
123AX_CODE_COVERAGE
124AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
125AS_IF([test "x$CODE_COVERAGE_ENABLED" = "xyes"], [
126 AX_APPEND_COMPILE_FLAGS([-DHAVE_GCOV], [CODE_COVERAGE_CPPFLAGS])
127])
128
129# Append -Werror after doing autoconf compiler checks
130# Otherwise some perfectly valid checks can fail and cause our
131# final configuratin to be broken.
132AC_ARG_ENABLE([werror], AC_HELP_STRING([--disable-werror], [Whether to automatically add -Werror CFLAGS]))
133AS_IF([test "x$enable_tests" != "xno"], [
134 AX_APPEND_COMPILE_FLAGS([-Werror], [CFLAGS])
135 AX_APPEND_COMPILE_FLAGS([-Werror], [CXXFLAGS])
136])
137
138# Create configured output
139AC_CONFIG_FILES([Makefile example/Makefile src/Makefile test/Makefile])
140AC_CONFIG_FILES([src/stdplus.pc])
141AC_OUTPUT