blob: f77953a0f459baa6031c8ac43c748c4aa9627a21 [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(
49 experimental/filesystem,
50 [],
51 [AC_MSG_ERROR([Could not find experimental/filesystem...libstdc++fs development package required])]
52)
Patrick Venture31eebcd2019-02-12 07:23:42 -080053AC_CHECK_HEADER(
54 nlohmann/json.hpp,
55 [],
56 [AC_MSG_ERROR([Could not find nlohmann/json.hpp])]
57)
Patrick Venture2e3ecb52018-06-22 08:18:19 -070058AX_PTHREAD([], [AC_MSG_ERROR(["pthread required and not found"])])
Patrick Venturee6206562018-03-08 15:36:53 -080059
60# Checks for library functions.
61LT_INIT # Required for systemd linking
62
Patrick Venture90f9bb52019-03-06 09:39:11 -080063# Make it possible for users to choose if they want test support
64# explicitly or not at all
65AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
66 [Build test cases]))
67
Patrick Venturee6206562018-03-08 15:36:53 -080068# Check/set gtest specific functions.
Patrick Venture90f9bb52019-03-06 09:39:11 -080069AS_IF([test "x$enable_tests" != "xno"], [
70 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
71 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
72 AX_PTHREAD
73
74 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
75 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
76 AC_LANG_PUSH([C++])
77 AC_CHECK_HEADERS([gtest/gtest.h], [
78 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
79 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
80 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
81 ], [
82 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
83 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
84 ])
85 ])
86 ], [
87 AS_IF([test "x$enable_tests" = "xyes"], [
88 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
89 ])
90 ])
91 AC_LANG_POP([C++])
92 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
93
94 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
95 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
96 AC_LANG_PUSH([C++])
97 AC_CHECK_HEADERS([gmock/gmock.h], [], [
98 AS_IF([test "x$enable_tests" = "xyes"], [
99 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
100 ])
101 ])
102 AC_LANG_POP([C++])
103 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
104
105 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
106 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
107 AC_CHECK_LIB([gtest], [main], [
108 AS_IF([test "x$GTEST_LIBS" = "x"], [
109 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
110 ])
111 ], [
112 AS_IF([test "x$enable_tests" = "xyes"], [
113 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
114 ])
115 ])
116 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
117
118 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
119 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
120 AC_CHECK_LIB([gmock], [main], [
121 AS_IF([test "x$GMOCK_LIBS" = "x"], [
122 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
123 ])
124 ], [
125 AS_IF([test "x$enable_tests" = "xyes"], [
126 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
127 ])
128 ])
129 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
130])
Patrick Venturee6206562018-03-08 15:36:53 -0800131
Patrick Venture94feffa2019-03-06 09:54:49 -0800132# Code coverage
133AX_CODE_COVERAGE
134AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
135AS_IF([test "x$CODE_COVERAGE_ENABLED" = "xyes"], [
136 AX_APPEND_COMPILE_FLAGS([-DHAVE_GCOV], [CODE_COVERAGE_CPPFLAGS])
137])
138
Patrick Venturee6206562018-03-08 15:36:53 -0800139AC_ARG_ENABLE([oe-sdk],
Patrick Venturef77ecc72018-11-26 09:08:49 -0800140 AS_HELP_STRING(
141 [--enable-oe-sdk],
142 [Link testcases absolutely against OE SDK so they can be ran within it.]
143 )
Patrick Venturee6206562018-03-08 15:36:53 -0800144)
145AC_ARG_VAR(OECORE_TARGET_SYSROOT,
Patrick Venturef77ecc72018-11-26 09:08:49 -0800146 [Path to the OE SDK SYSROOT]
147)
Patrick Venturee6206562018-03-08 15:36:53 -0800148AS_IF([test "x$enable_oe_sdk" == "xyes"],
149 AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
150 AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
151 )
152 AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
153 [
154 testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
155 testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
156 testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
157 ]
158 AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
159)
160
James Feist7136a5a2018-07-19 09:52:05 -0700161AC_ARG_ENABLE([configure-dbus],
Patrick Venturef77ecc72018-11-26 09:08:49 -0800162 AS_HELP_STRING(
163 [--enable-configure-dbus], [Enable configuring pid from D-Bus.]
164 )
165)
James Feist7136a5a2018-07-19 09:52:05 -0700166AM_CONDITIONAL(CONFIGURE_DBUS, [test "x$enable_configure_dbus" = "xyes"])
167AS_IF([test "x$enable_configure_dbus" = "xyes"],
James Feistce15e022018-09-26 10:01:33 -0700168 [AC_DEFINE(CONFIGURE_DBUS, [1], [Read configuration from D-Bus.])],
169 [AC_DEFINE(CONFIGURE_DBUS, [0], [Do not read configuration from D-Bus.])]
James Feist7136a5a2018-07-19 09:52:05 -0700170)
171
Patrick Venturee6206562018-03-08 15:36:53 -0800172# Create configured output
Patrick Venture7a841b62018-06-13 09:39:46 -0700173AC_CONFIG_FILES([Makefile test/Makefile])
Patrick Venturee6206562018-03-08 15:36:53 -0800174AC_OUTPUT