William A. Kennington III | 8f90e28 | 2018-07-17 14:40:14 -0700 | [diff] [blame^] | 1 | # Initialization |
| 2 | AC_PREREQ([2.69]) |
| 3 | AC_INIT([sdeventplus], [0.1], [https://github.com/openbmc/sdeventplus/issues]) |
| 4 | AC_LANG([C++]) |
| 5 | AC_CONFIG_HEADERS([config.h]) |
| 6 | AC_CONFIG_MACRO_DIRS([m4]) |
| 7 | AC_CONFIG_AUX_DIR([build-aux]) |
| 8 | AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror dist-xz tar-ustar]) |
| 9 | AM_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. |
| 14 | AS_IF([test "x$enable_code_coverage" != "xno"], [ |
| 15 | AS_IF([test "x${CXXFLAGS+set}" != "xset"], [ |
| 16 | AC_SUBST(CXXFLAGS, [""]) |
| 17 | ]) |
| 18 | AS_IF([test "x${CFLAGS+set}" != "xset"], [ |
| 19 | AC_SUBST(CFLAGS, [""]) |
| 20 | ]) |
| 21 | ]) |
| 22 | |
| 23 | # Checks for programs. |
| 24 | AC_PROG_CXX |
| 25 | AC_PROG_CC |
| 26 | AM_PROG_AR |
| 27 | AC_PROG_INSTALL |
| 28 | AC_PROG_MAKE_SET |
| 29 | |
| 30 | # Checks for libtool |
| 31 | LT_INIT # Removes 'unrecognized options: --with-libtool-sysroot' |
| 32 | |
| 33 | # Make sure the pkgconfigdata is configured for automake |
| 34 | PKG_INSTALLDIR |
| 35 | |
| 36 | # Checks for typedefs, structures, and compiler characteristics. |
| 37 | AX_CXX_COMPILE_STDCXX([14], [noext], [mandatory]) |
| 38 | AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CFLAGS]) |
| 39 | AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CXXFLAGS]) |
| 40 | |
| 41 | # We require systemd unconditionally |
| 42 | AX_PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 218]) |
| 43 | |
| 44 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 45 | AX_APPEND_COMPILE_FLAGS([$SYSTEMD_CFLAGS], [CPPFLAGS]) |
| 46 | AC_CHECK_HEADERS([systemd/sd-event.h], [], |
| 47 | [AC_MSG_ERROR([Could not find systemd/sd-event.h])]) |
| 48 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 49 | |
| 50 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 51 | AX_APPEND_COMPILE_FLAGS([$SYSTEMD_LIBS], [LDFLAGS]) |
| 52 | AC_CHECK_LIB([systemd], [sd_event_default], [], [ |
| 53 | AC_MSG_ERROR([Could not find sd_event_default in libsystemd]) |
| 54 | ]) |
| 55 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 56 | |
| 57 | # Make it possible for users to choose if they want test support |
| 58 | # explicitly or not at all |
| 59 | AC_ARG_ENABLE([tests], [Whether we should build test cases]) |
| 60 | |
| 61 | # Check/set gtest specific functions. |
| 62 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 63 | PKG_CHECK_MODULES([GTEST], [gtest], [], [true]) |
| 64 | PKG_CHECK_MODULES([GMOCK], [gmock], [], [true]) |
| 65 | AX_PTHREAD |
| 66 | |
| 67 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 68 | AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS]) |
| 69 | AC_LANG_PUSH([C++]) |
| 70 | AC_CHECK_HEADERS([gtest/gtest.h], [ |
| 71 | AS_IF([test "x$GTEST_CFLAGS" = "x"], [ |
| 72 | AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [ |
| 73 | AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS]) |
| 74 | ], [ |
| 75 | AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS]) |
| 76 | AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS]) |
| 77 | ]) |
| 78 | ]) |
| 79 | ], [ |
| 80 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 81 | AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h]) |
| 82 | ]) |
| 83 | ]) |
| 84 | AC_LANG_POP([C++]) |
| 85 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 86 | |
| 87 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 88 | AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS]) |
| 89 | AC_LANG_PUSH([C++]) |
| 90 | AC_CHECK_HEADERS([gmock/gmock.h], [], [ |
| 91 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 92 | AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h]) |
| 93 | ]) |
| 94 | ]) |
| 95 | AC_LANG_POP([C++]) |
| 96 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 97 | |
| 98 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 99 | AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS]) |
| 100 | AC_CHECK_LIB([gtest], [main], [ |
| 101 | AS_IF([test "x$GTEST_LIBS" = "x"], [ |
| 102 | AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS]) |
| 103 | ]) |
| 104 | ], [ |
| 105 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 106 | AC_MSG_ERROR([Testing enabled but couldn't find gtest libs]) |
| 107 | ]) |
| 108 | ]) |
| 109 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 110 | |
| 111 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 112 | AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS]) |
| 113 | AC_CHECK_LIB([gmock], [main], [ |
| 114 | AS_IF([test "x$GMOCK_LIBS" = "x"], [ |
| 115 | AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS]) |
| 116 | ]) |
| 117 | ], [ |
| 118 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 119 | AC_MSG_ERROR([Testing enabled but couldn't find gmock libs]) |
| 120 | ]) |
| 121 | ]) |
| 122 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 123 | ]) |
| 124 | |
| 125 | # Check for valgrind |
| 126 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 127 | m4_foreach([vgtool], [valgrind_tool_list], |
| 128 | [AX_VALGRIND_DFLT(vgtool, [off])]) |
| 129 | AX_VALGRIND_DFLT([memcheck], [on]) |
| 130 | AX_VALGRIND_CHECK |
| 131 | AM_EXTRA_RECURSIVE_TARGETS([check-valgrind]) |
| 132 | m4_foreach([vgtool], [valgrind_tool_list], |
| 133 | [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)]) |
| 134 | ]) |
| 135 | |
| 136 | # Code coverage |
| 137 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 138 | AX_CODE_COVERAGE |
| 139 | AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage]) |
| 140 | ]) |
| 141 | |
| 142 | # Append -Werror after doing autoconf compiler checks |
| 143 | # Otherwise some perfectly valid checks can fail and cause our |
| 144 | # final configuratin to be broken. |
| 145 | AC_ARG_ENABLE([werror], [Whether to automatically add -Werror CFLAGS]) |
| 146 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 147 | AX_APPEND_COMPILE_FLAGS([-Werror], [CFLAGS]) |
| 148 | AX_APPEND_COMPILE_FLAGS([-Werror], [CXXFLAGS]) |
| 149 | ]) |
| 150 | |
| 151 | # Create configured output |
| 152 | AC_CONFIG_FILES([Makefile example/Makefile src/Makefile test/Makefile]) |
| 153 | AC_CONFIG_FILES([src/sdeventplus.pc]) |
| 154 | AC_OUTPUT |