blob: a2ae7a6f126cb09fe8b74e3fcf0e3b33f09f0981 [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])
William A. Kennington III15ac2222018-07-19 15:27:58 -07008AM_INIT_AUTOMAKE([nostdinc foreign subdir-objects -Wall -Werror dist-xz tar-ustar])
William A. Kennington III8f90e282018-07-17 14:40:14 -07009AM_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.
William A. Kennington IIIcf1f4f92018-08-16 14:27:49 -070014AS_IF([test "x$enable_tests" = "xno"], [enable_code_coverage=no])
William A. Kennington III8f90e282018-07-17 14:40:14 -070015AS_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
William A. Kennington III20832de2018-08-14 11:18:51 -070032LT_INIT
William A. Kennington III8f90e282018-07-17 14:40:14 -070033
34# Make sure the pkgconfigdata is configured for automake
35PKG_INSTALLDIR
36
37# Checks for typedefs, structures, and compiler characteristics.
William A. Kennington III5f3cdfa2018-09-11 23:02:38 -070038AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
William A. Kennington III8f90e282018-07-17 14:40:14 -070039AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CFLAGS])
40AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CXXFLAGS])
41
42# We require systemd unconditionally
43AX_PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 218])
44
45AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
46AX_APPEND_COMPILE_FLAGS([$SYSTEMD_CFLAGS], [CPPFLAGS])
William A. Kennington III20832de2018-08-14 11:18:51 -070047AC_CHECK_HEADERS([systemd/sd-event.h], [], [
48 AC_MSG_ERROR([Could not find systemd/sd-event.h])
49])
William A. Kennington III8f90e282018-07-17 14:40:14 -070050AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
51
52AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
53AX_APPEND_COMPILE_FLAGS([$SYSTEMD_LIBS], [LDFLAGS])
54AC_CHECK_LIB([systemd], [sd_event_default], [], [
55 AC_MSG_ERROR([Could not find sd_event_default in libsystemd])
56])
57AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
58
William A. Kennington III321ed012018-07-17 14:40:14 -070059# Make it possible for users to choose to disable examples
60AC_ARG_ENABLE([examples], AC_HELP_STRING([--disable-examples],
61 [Build example programs]))
62AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" != "xno"])
63
William A. Kennington III8f90e282018-07-17 14:40:14 -070064# Make it possible for users to choose if they want test support
65# explicitly or not at all
William A. Kennington IIId6d53142018-07-17 14:40:14 -070066AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
67 [Build test cases]))
William A. Kennington III8f90e282018-07-17 14:40:14 -070068
69# Check/set gtest specific functions.
70AS_IF([test "x$enable_tests" != "xno"], [
71 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
72 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
73 AX_PTHREAD
74
75 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
76 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
77 AC_LANG_PUSH([C++])
78 AC_CHECK_HEADERS([gtest/gtest.h], [
79 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
80 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
81 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
82 ], [
83 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
84 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
85 ])
86 ])
87 ], [
88 AS_IF([test "x$enable_tests" = "xyes"], [
89 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
90 ])
91 ])
92 AC_LANG_POP([C++])
93 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
94
95 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
96 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
97 AC_LANG_PUSH([C++])
98 AC_CHECK_HEADERS([gmock/gmock.h], [], [
99 AS_IF([test "x$enable_tests" = "xyes"], [
100 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
101 ])
102 ])
103 AC_LANG_POP([C++])
104 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
105
106 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
107 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
108 AC_CHECK_LIB([gtest], [main], [
109 AS_IF([test "x$GTEST_LIBS" = "x"], [
110 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
111 ])
112 ], [
113 AS_IF([test "x$enable_tests" = "xyes"], [
114 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
115 ])
116 ])
117 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
118
119 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
120 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
121 AC_CHECK_LIB([gmock], [main], [
122 AS_IF([test "x$GMOCK_LIBS" = "x"], [
123 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
124 ])
125 ], [
126 AS_IF([test "x$enable_tests" = "xyes"], [
127 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
128 ])
129 ])
130 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
131])
132
133# Check for valgrind
William A. Kennington III90dbcd72018-08-16 13:54:35 -0700134AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
135m4_foreach([vgtool], [valgrind_tool_list],
William A. Kennington IIId38b8ff2018-08-23 19:13:40 -0700136 [AX_VALGRIND_DFLT(vgtool, [off])])
William A. Kennington III90dbcd72018-08-16 13:54:35 -0700137AX_VALGRIND_DFLT([memcheck], [on])
138AX_VALGRIND_CHECK
139AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
140m4_foreach([vgtool], [valgrind_tool_list],
William A. Kennington IIId38b8ff2018-08-23 19:13:40 -0700141 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
William A. Kennington III8f90e282018-07-17 14:40:14 -0700142
143# Code coverage
William A. Kennington III90dbcd72018-08-16 13:54:35 -0700144AX_CODE_COVERAGE
145AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
William A. Kennington III8f90e282018-07-17 14:40:14 -0700146
147# Append -Werror after doing autoconf compiler checks
148# Otherwise some perfectly valid checks can fail and cause our
149# final configuratin to be broken.
William A. Kennington IIId6d53142018-07-17 14:40:14 -0700150AC_ARG_ENABLE([werror], AC_HELP_STRING([--disable-werror], [Whether to automatically add -Werror CFLAGS]))
William A. Kennington III8f90e282018-07-17 14:40:14 -0700151AS_IF([test "x$enable_tests" != "xno"], [
152 AX_APPEND_COMPILE_FLAGS([-Werror], [CFLAGS])
153 AX_APPEND_COMPILE_FLAGS([-Werror], [CXXFLAGS])
154])
155
156# Create configured output
157AC_CONFIG_FILES([Makefile example/Makefile src/Makefile test/Makefile])
158AC_CONFIG_FILES([src/sdeventplus.pc])
159AC_OUTPUT