Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 1 | # Initialization |
| 2 | AC_PREREQ([2.69]) |
Patrick Venture | 23ef59b | 2018-11-26 09:15:35 -0800 | [diff] [blame] | 3 | AC_INIT([sys-ipmi], [0.1], [https://www.github.com/google-ipmi-sys/issues]) |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 4 | AC_LANG([C++]) |
| 5 | AC_CONFIG_HEADERS([config.h]) |
| 6 | AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz]) |
| 7 | AM_SILENT_RULES([yes]) |
| 8 | |
Patrick Venture | 6667a64 | 2019-03-13 16:39:30 -0700 | [diff] [blame] | 9 | # 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. |
| 12 | AS_IF([test "x$enable_tests" = "xno"], [enable_code_coverage=no]) |
| 13 | AS_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 Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 22 | # Checks for programs. |
| 23 | AC_PROG_CXX |
| 24 | AM_PROG_AR |
| 25 | AC_PROG_INSTALL |
| 26 | AC_PROG_MAKE_SET |
| 27 | |
| 28 | # Checks for typedefs, structures, and compiler characteristics. |
Patrick Venture | c25a3df | 2018-09-17 12:11:19 -0700 | [diff] [blame] | 29 | AX_CXX_COMPILE_STDCXX_17([noext]) |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 30 | AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS]) |
| 31 | |
| 32 | # Checks for libraries. |
Patrick Venture | c662465 | 2019-02-13 07:35:07 -0800 | [diff] [blame] | 33 | PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus]) |
| 34 | PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging]) |
William A. Kennington III | 2c9e162 | 2019-02-07 15:45:19 -0800 | [diff] [blame] | 35 | PKG_CHECK_MODULES( |
| 36 | [LIBIPMID], |
| 37 | [libipmid], |
| 38 | [], |
| 39 | [AC_MSG_ERROR([Could not find libipmid...openbmc/phosphor-host-ipmid package required])] |
| 40 | ) |
Patrick Venture | 3c7037a | 2018-11-21 21:40:50 -0800 | [diff] [blame] | 41 | AC_CHECK_HEADER( |
Patrick Venture | 575a55a | 2019-02-12 07:32:06 -0800 | [diff] [blame] | 42 | nlohmann/json.hpp, |
| 43 | [], |
| 44 | [AC_MSG_ERROR([Could not find nlohmann/json.hpp])] |
| 45 | ) |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 46 | |
| 47 | # Checks for library functions. |
| 48 | LT_INIT # Required for systemd linking |
| 49 | |
Patrick Venture | 848b938 | 2019-03-13 15:48:23 -0700 | [diff] [blame] | 50 | # Make it possible for users to choose if they want test support |
| 51 | # explicitly or not at all |
| 52 | AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests], |
| 53 | [Build test cases])) |
| 54 | |
| 55 | # Check/set gtest specific functions. |
| 56 | AS_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 Venture | ba32fe4 | 2019-03-19 12:50:59 -0700 | [diff] [blame^] | 119 | # Check for valgrind |
| 120 | AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no]) |
| 121 | m4_foreach([vgtool], [valgrind_tool_list], |
| 122 | [AX_VALGRIND_DFLT(vgtool, [off])]) |
| 123 | AX_VALGRIND_DFLT([memcheck], [on]) |
| 124 | AX_VALGRIND_CHECK |
| 125 | AM_EXTRA_RECURSIVE_TARGETS([check-valgrind]) |
| 126 | m4_foreach([vgtool], [valgrind_tool_list], |
| 127 | [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)]) |
| 128 | |
Patrick Venture | 6667a64 | 2019-03-13 16:39:30 -0700 | [diff] [blame] | 129 | # Code coverage |
| 130 | AX_CODE_COVERAGE |
| 131 | m4_ifdef([_AX_CODE_COVERAGE_RULES], |
| 132 | [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])], |
| 133 | [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])]) |
| 134 | AX_ADD_AM_MACRO_STATIC([]) |
| 135 | |
Patrick Venture | f9a19b8 | 2018-09-18 10:03:24 -0700 | [diff] [blame] | 136 | PKG_PROG_PKG_CONFIG |
| 137 | AC_ARG_WITH([systemdsystemunitdir], |
| 138 | [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],, |
| 139 | [with_systemdsystemunitdir=auto]) |
| 140 | AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [ |
| 141 | def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd) |
| 142 | |
| 143 | AS_IF([test "x$def_systemdsystemunitdir" = "x"], |
| 144 | [AS_IF([test "x$with_systemdsystemunitdir" = "xyes"], |
| 145 | [AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])]) |
| 146 | with_systemdsystemunitdir=no], |
| 147 | [with_systemdsystemunitdir="$def_systemdsystemunitdir"])]) |
| 148 | AS_IF([test "x$with_systemdsystemunitdir" != "xno"], |
| 149 | [AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])]) |
| 150 | AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"]) |
| 151 | |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 152 | # Create configured output |
Patrick Venture | 848b938 | 2019-03-13 15:48:23 -0700 | [diff] [blame] | 153 | AC_CONFIG_FILES([Makefile test/Makefile]) |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 154 | AC_OUTPUT |