blob: f0e2e861c9f7aaf869ab7aeb5d889dc926ecb969 [file] [log] [blame]
William A. Kennington III8f90e282018-07-17 14:40:14 -07001# Initialization
2AC_PREREQ([2.69])
3AC_INIT([sdeventplus], [0.1], [https://github.com/openbmc/sdeventplus/issues])
4AC_LANG([C++])
5AC_CONFIG_HEADERS([config.h])
6AC_CONFIG_MACRO_DIRS([m4])
7AC_CONFIG_AUX_DIR([build-aux])
8AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror dist-xz tar-ustar])
9AM_SILENT_RULES([yes])
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_code_coverage" != "xno"], [
15 AS_IF([test "x${CXXFLAGS+set}" != "xset"], [
16 AC_SUBST(CXXFLAGS, [""])
17 ])
18 AS_IF([test "x${CFLAGS+set}" != "xset"], [
19 AC_SUBST(CFLAGS, [""])
20 ])
21])
22
23# Checks for programs.
24AC_PROG_CXX
25AC_PROG_CC
26AM_PROG_AR
27AC_PROG_INSTALL
28AC_PROG_MAKE_SET
29
30# Checks for libtool
31LT_INIT # Removes 'unrecognized options: --with-libtool-sysroot'
32
33# Make sure the pkgconfigdata is configured for automake
34PKG_INSTALLDIR
35
36# Checks for typedefs, structures, and compiler characteristics.
37AX_CXX_COMPILE_STDCXX([14], [noext], [mandatory])
38AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CFLAGS])
39AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CXXFLAGS])
40
41# We require systemd unconditionally
42AX_PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 218])
43
44AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
45AX_APPEND_COMPILE_FLAGS([$SYSTEMD_CFLAGS], [CPPFLAGS])
46AC_CHECK_HEADERS([systemd/sd-event.h], [],
47 [AC_MSG_ERROR([Could not find systemd/sd-event.h])])
48AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
49
50AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
51AX_APPEND_COMPILE_FLAGS([$SYSTEMD_LIBS], [LDFLAGS])
52AC_CHECK_LIB([systemd], [sd_event_default], [], [
53 AC_MSG_ERROR([Could not find sd_event_default in libsystemd])
54])
55AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
56
William A. Kennington III321ed012018-07-17 14:40:14 -070057# Make it possible for users to choose to disable examples
58AC_ARG_ENABLE([examples], AC_HELP_STRING([--disable-examples],
59 [Build example programs]))
60AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" != "xno"])
61
William A. Kennington III8f90e282018-07-17 14:40:14 -070062# Make it possible for users to choose if they want test support
63# explicitly or not at all
William A. Kennington IIId6d53142018-07-17 14:40:14 -070064AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
65 [Build test cases]))
William A. Kennington III8f90e282018-07-17 14:40:14 -070066
67# Check/set gtest specific functions.
68AS_IF([test "x$enable_tests" != "xno"], [
69 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
70 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
71 AX_PTHREAD
72
73 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
74 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
75 AC_LANG_PUSH([C++])
76 AC_CHECK_HEADERS([gtest/gtest.h], [
77 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
78 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
79 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
80 ], [
81 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
82 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
83 ])
84 ])
85 ], [
86 AS_IF([test "x$enable_tests" = "xyes"], [
87 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
88 ])
89 ])
90 AC_LANG_POP([C++])
91 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
92
93 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
94 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
95 AC_LANG_PUSH([C++])
96 AC_CHECK_HEADERS([gmock/gmock.h], [], [
97 AS_IF([test "x$enable_tests" = "xyes"], [
98 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
99 ])
100 ])
101 AC_LANG_POP([C++])
102 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
103
104 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
105 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
106 AC_CHECK_LIB([gtest], [main], [
107 AS_IF([test "x$GTEST_LIBS" = "x"], [
108 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
109 ])
110 ], [
111 AS_IF([test "x$enable_tests" = "xyes"], [
112 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
113 ])
114 ])
115 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
116
117 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
118 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
119 AC_CHECK_LIB([gmock], [main], [
120 AS_IF([test "x$GMOCK_LIBS" = "x"], [
121 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
122 ])
123 ], [
124 AS_IF([test "x$enable_tests" = "xyes"], [
125 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
126 ])
127 ])
128 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
129])
130
131# Check for valgrind
132AS_IF([test "x$enable_tests" != "xno"], [
133 m4_foreach([vgtool], [valgrind_tool_list],
134 [AX_VALGRIND_DFLT(vgtool, [off])])
135 AX_VALGRIND_DFLT([memcheck], [on])
136 AX_VALGRIND_CHECK
137 AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
138 m4_foreach([vgtool], [valgrind_tool_list],
139 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
140])
141
142# Code coverage
143AS_IF([test "x$enable_tests" != "xno"], [
144 AX_CODE_COVERAGE
145 AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
146])
147
148# Append -Werror after doing autoconf compiler checks
149# Otherwise some perfectly valid checks can fail and cause our
150# final configuratin to be broken.
William A. Kennington IIId6d53142018-07-17 14:40:14 -0700151AC_ARG_ENABLE([werror], AC_HELP_STRING([--disable-werror], [Whether to automatically add -Werror CFLAGS]))
William A. Kennington III8f90e282018-07-17 14:40:14 -0700152AS_IF([test "x$enable_tests" != "xno"], [
153 AX_APPEND_COMPILE_FLAGS([-Werror], [CFLAGS])
154 AX_APPEND_COMPILE_FLAGS([-Werror], [CXXFLAGS])
155])
156
157# Create configured output
158AC_CONFIG_FILES([Makefile example/Makefile src/Makefile test/Makefile])
159AC_CONFIG_FILES([src/sdeventplus.pc])
160AC_OUTPUT