blob: b7f743f7813dd3ae089d7cd91efd60d59de60999 [file] [log] [blame]
Patrick Venturee6206562018-03-08 15:36:53 -08001# Initialization
2AC_PREREQ([2.69])
Patrick Ventured7523572018-11-26 09:01:54 -08003AC_INIT([swampd], [0.1], [https://github.com/openbmc/phosphor-pid-control/issues])
Patrick Venturee6206562018-03-08 15:36:53 -08004AC_LANG([C++])
5AC_CONFIG_HEADERS([config.h])
6AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
7AM_SILENT_RULES([yes])
8
Patrick Venture94feffa2019-03-06 09:54:49 -08009# Make sure the default CFLAGS of `-O2 -g` don't override CODE_COVERAGE_CFLAGS
10# It is important that this comes before AC_PROG_C{C,XX}, as we are attempting
11# to stop them from populating default CFLAGS and CXXFLAGS.
12AS_IF([test "x$enable_tests" = "xno"], [enable_code_coverage=no])
13AS_IF([test "x$enable_code_coverage" != "xno"], [
14 AS_IF([test "x${CXXFLAGS+set}" != "xset"], [
15 AC_SUBST(CXXFLAGS, [""])
16 ])
17 AS_IF([test "x${CFLAGS+set}" != "xset"], [
18 AC_SUBST(CFLAGS, [""])
19 ])
20])
21
Patrick Venturee6206562018-03-08 15:36:53 -080022# Checks for programs.
23AC_PROG_CXX
24AM_PROG_AR
25AC_PROG_INSTALL
26AC_PROG_MAKE_SET
27
Patrick Venturee6206562018-03-08 15:36:53 -080028# Checks for typedefs, structures, and compiler characteristics.
Patrick Venture54c2e5e2018-09-10 13:06:38 -070029AX_CXX_COMPILE_STDCXX_17([noext])
Patrick Ventureab28cb32018-06-20 18:37:48 -070030AX_APPEND_COMPILE_FLAGS([-fpic -Wall -Werror], [CXXFLAGS])
Patrick Venturee6206562018-03-08 15:36:53 -080031
32# Checks for libraries.
Patrick Venturee54c7ff2018-11-21 21:30:56 -080033PKG_CHECK_MODULES(
34 [SYSTEMD],
35 [libsystemd >= 221],
36 [],
37 [AC_MSG_ERROR(["systemd required and not found"])]
38)
Patrick Venturef72ad442019-02-13 07:28:58 -080039PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus])
40PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging])
41PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces])
William A. Kennington III331143c2019-02-07 15:52:44 -080042PKG_CHECK_MODULES(
43 [LIBIPMID],
44 [libipmid],
45 [],
46 [AC_MSG_ERROR([Could not find libipmid...openbmc/phosphor-host-ipmid package required])]
Patrick Venturee54c7ff2018-11-21 21:30:56 -080047)
48AC_CHECK_HEADER(
Patrick Venture31eebcd2019-02-12 07:23:42 -080049 nlohmann/json.hpp,
50 [],
51 [AC_MSG_ERROR([Could not find nlohmann/json.hpp])]
52)
Patrick Venture2e3ecb52018-06-22 08:18:19 -070053AX_PTHREAD([], [AC_MSG_ERROR(["pthread required and not found"])])
Patrick Venturee6206562018-03-08 15:36:53 -080054
55# Checks for library functions.
56LT_INIT # Required for systemd linking
57
Patrick Venture90f9bb52019-03-06 09:39:11 -080058# Make it possible for users to choose if they want test support
59# explicitly or not at all
60AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
61 [Build test cases]))
62
Patrick Venturee6206562018-03-08 15:36:53 -080063# Check/set gtest specific functions.
Patrick Venture90f9bb52019-03-06 09:39:11 -080064AS_IF([test "x$enable_tests" != "xno"], [
65 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
66 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
67 AX_PTHREAD
68
69 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
70 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
71 AC_LANG_PUSH([C++])
72 AC_CHECK_HEADERS([gtest/gtest.h], [
73 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
74 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
75 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
76 ], [
77 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
78 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
79 ])
80 ])
81 ], [
82 AS_IF([test "x$enable_tests" = "xyes"], [
83 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
84 ])
85 ])
86 AC_LANG_POP([C++])
87 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
88
89 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
90 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
91 AC_LANG_PUSH([C++])
92 AC_CHECK_HEADERS([gmock/gmock.h], [], [
93 AS_IF([test "x$enable_tests" = "xyes"], [
94 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
95 ])
96 ])
97 AC_LANG_POP([C++])
98 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
99
100 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
101 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
102 AC_CHECK_LIB([gtest], [main], [
103 AS_IF([test "x$GTEST_LIBS" = "x"], [
104 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
105 ])
106 ], [
107 AS_IF([test "x$enable_tests" = "xyes"], [
108 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
109 ])
110 ])
111 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
112
113 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
114 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
115 AC_CHECK_LIB([gmock], [main], [
116 AS_IF([test "x$GMOCK_LIBS" = "x"], [
117 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
118 ])
119 ], [
120 AS_IF([test "x$enable_tests" = "xyes"], [
121 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
122 ])
123 ])
124 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
125])
Patrick Venturee6206562018-03-08 15:36:53 -0800126
Patrick Venture94feffa2019-03-06 09:54:49 -0800127# Code coverage
128AX_CODE_COVERAGE
129AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
130AS_IF([test "x$CODE_COVERAGE_ENABLED" = "xyes"], [
131 AX_APPEND_COMPILE_FLAGS([-DHAVE_GCOV], [CODE_COVERAGE_CPPFLAGS])
132])
133
Patrick Venturee6206562018-03-08 15:36:53 -0800134AC_ARG_ENABLE([oe-sdk],
Patrick Venturef77ecc72018-11-26 09:08:49 -0800135 AS_HELP_STRING(
136 [--enable-oe-sdk],
137 [Link testcases absolutely against OE SDK so they can be ran within it.]
138 )
Patrick Venturee6206562018-03-08 15:36:53 -0800139)
140AC_ARG_VAR(OECORE_TARGET_SYSROOT,
Patrick Venturef77ecc72018-11-26 09:08:49 -0800141 [Path to the OE SDK SYSROOT]
142)
Patrick Venturee6206562018-03-08 15:36:53 -0800143AS_IF([test "x$enable_oe_sdk" == "xyes"],
144 AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
145 AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
146 )
147 AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
148 [
149 testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
150 testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
151 testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
152 ]
153 AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
154)
155
James Feist7136a5a2018-07-19 09:52:05 -0700156AC_ARG_ENABLE([configure-dbus],
Patrick Venturef77ecc72018-11-26 09:08:49 -0800157 AS_HELP_STRING(
158 [--enable-configure-dbus], [Enable configuring pid from D-Bus.]
159 )
160)
James Feist7136a5a2018-07-19 09:52:05 -0700161AM_CONDITIONAL(CONFIGURE_DBUS, [test "x$enable_configure_dbus" = "xyes"])
162AS_IF([test "x$enable_configure_dbus" = "xyes"],
James Feistce15e022018-09-26 10:01:33 -0700163 [AC_DEFINE(CONFIGURE_DBUS, [1], [Read configuration from D-Bus.])],
164 [AC_DEFINE(CONFIGURE_DBUS, [0], [Do not read configuration from D-Bus.])]
James Feist7136a5a2018-07-19 09:52:05 -0700165)
166
Patrick Venturee6206562018-03-08 15:36:53 -0800167# Create configured output
Patrick Venture7a841b62018-06-13 09:39:46 -0700168AC_CONFIG_FILES([Makefile test/Makefile])
Patrick Venturee6206562018-03-08 15:36:53 -0800169AC_OUTPUT