blob: 7b57762969228e6c10488fe5a891bf7a6d4d45df [file] [log] [blame]
Patrick Venture4d49ae62018-09-17 11:35:32 -07001# Initialization
2AC_PREREQ([2.69])
Patrick Venture23ef59b2018-11-26 09:15:35 -08003AC_INIT([sys-ipmi], [0.1], [https://www.github.com/google-ipmi-sys/issues])
Patrick Venture4d49ae62018-09-17 11:35:32 -07004AC_LANG([C++])
5AC_CONFIG_HEADERS([config.h])
6AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
7AM_SILENT_RULES([yes])
8
Patrick Venture6667a642019-03-13 16:39:30 -07009# 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 Venture4d49ae62018-09-17 11:35:32 -070022# Checks for programs.
23AC_PROG_CXX
24AM_PROG_AR
25AC_PROG_INSTALL
26AC_PROG_MAKE_SET
27
28# Checks for typedefs, structures, and compiler characteristics.
Patrick Venturec25a3df2018-09-17 12:11:19 -070029AX_CXX_COMPILE_STDCXX_17([noext])
Patrick Venture4d49ae62018-09-17 11:35:32 -070030AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS])
31
32# Checks for libraries.
Patrick Venturec6624652019-02-13 07:35:07 -080033PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus])
34PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging])
William A. Kennington III2c9e1622019-02-07 15:45:19 -080035PKG_CHECK_MODULES(
36 [LIBIPMID],
37 [libipmid],
38 [],
39 [AC_MSG_ERROR([Could not find libipmid...openbmc/phosphor-host-ipmid package required])]
40)
Patrick Venture3c7037a2018-11-21 21:40:50 -080041AC_CHECK_HEADER(
Patrick Venture575a55a2019-02-12 07:32:06 -080042 nlohmann/json.hpp,
43 [],
44 [AC_MSG_ERROR([Could not find nlohmann/json.hpp])]
45)
Patrick Venture4d49ae62018-09-17 11:35:32 -070046
47# Checks for library functions.
48LT_INIT # Required for systemd linking
49
Patrick Venture848b9382019-03-13 15:48:23 -070050# Make it possible for users to choose if they want test support
51# explicitly or not at all
52AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
53 [Build test cases]))
54
55# Check/set gtest specific functions.
56AS_IF([test "x$enable_tests" != "xno"], [
57 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
58 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
59 AX_PTHREAD
60
61 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
62 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
63 AC_LANG_PUSH([C++])
64 AC_CHECK_HEADERS([gtest/gtest.h], [
65 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
66 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
67 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
68 ], [
69 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
70 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
71 ])
72 ])
73 ], [
74 AS_IF([test "x$enable_tests" = "xyes"], [
75 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
76 ])
77 ])
78 AC_LANG_POP([C++])
79 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
80
81 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
82 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
83 AC_LANG_PUSH([C++])
84 AC_CHECK_HEADERS([gmock/gmock.h], [], [
85 AS_IF([test "x$enable_tests" = "xyes"], [
86 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
87 ])
88 ])
89 AC_LANG_POP([C++])
90 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
91
92 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
93 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
94 AC_CHECK_LIB([gtest], [main], [
95 AS_IF([test "x$GTEST_LIBS" = "x"], [
96 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
97 ])
98 ], [
99 AS_IF([test "x$enable_tests" = "xyes"], [
100 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
101 ])
102 ])
103 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
104
105 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
106 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
107 AC_CHECK_LIB([gmock], [main], [
108 AS_IF([test "x$GMOCK_LIBS" = "x"], [
109 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
110 ])
111 ], [
112 AS_IF([test "x$enable_tests" = "xyes"], [
113 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
114 ])
115 ])
116 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
117])
118
Patrick Venture6667a642019-03-13 16:39:30 -0700119# Code coverage
120AX_CODE_COVERAGE
121m4_ifdef([_AX_CODE_COVERAGE_RULES],
122 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
123 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
124AX_ADD_AM_MACRO_STATIC([])
125
Patrick Venturef9a19b82018-09-18 10:03:24 -0700126PKG_PROG_PKG_CONFIG
127AC_ARG_WITH([systemdsystemunitdir],
128 [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],,
129 [with_systemdsystemunitdir=auto])
130AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [
131 def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
132
133 AS_IF([test "x$def_systemdsystemunitdir" = "x"],
134 [AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
135 [AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])])
136 with_systemdsystemunitdir=no],
137 [with_systemdsystemunitdir="$def_systemdsystemunitdir"])])
138AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
139 [AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
140AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"])
141
Patrick Venture4d49ae62018-09-17 11:35:32 -0700142# Create configured output
Patrick Venture848b9382019-03-13 15:48:23 -0700143AC_CONFIG_FILES([Makefile test/Makefile])
Patrick Venture4d49ae62018-09-17 11:35:32 -0700144AC_OUTPUT