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 | |
William A. Kennington III | 321ed01 | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 57 | # Make it possible for users to choose to disable examples |
| 58 | AC_ARG_ENABLE([examples], AC_HELP_STRING([--disable-examples], |
| 59 | [Build example programs])) |
| 60 | AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" != "xno"]) |
| 61 | |
William A. Kennington III | 8f90e28 | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 62 | # Make it possible for users to choose if they want test support |
| 63 | # explicitly or not at all |
William A. Kennington III | d6d5314 | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 64 | AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests], |
| 65 | [Build test cases])) |
William A. Kennington III | 8f90e28 | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 66 | |
| 67 | # Check/set gtest specific functions. |
| 68 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 69 | PKG_CHECK_MODULES([GTEST], [gtest], [], [true]) |
| 70 | PKG_CHECK_MODULES([GMOCK], [gmock], [], [true]) |
| 71 | AX_PTHREAD |
| 72 | |
| 73 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 74 | AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS]) |
| 75 | AC_LANG_PUSH([C++]) |
| 76 | AC_CHECK_HEADERS([gtest/gtest.h], [ |
| 77 | AS_IF([test "x$GTEST_CFLAGS" = "x"], [ |
| 78 | AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [ |
| 79 | AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS]) |
| 80 | ], [ |
| 81 | AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS]) |
| 82 | AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS]) |
| 83 | ]) |
| 84 | ]) |
| 85 | ], [ |
| 86 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 87 | AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h]) |
| 88 | ]) |
| 89 | ]) |
| 90 | AC_LANG_POP([C++]) |
| 91 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 92 | |
| 93 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 94 | AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS]) |
| 95 | AC_LANG_PUSH([C++]) |
| 96 | AC_CHECK_HEADERS([gmock/gmock.h], [], [ |
| 97 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 98 | AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h]) |
| 99 | ]) |
| 100 | ]) |
| 101 | AC_LANG_POP([C++]) |
| 102 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 103 | |
| 104 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 105 | AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS]) |
| 106 | AC_CHECK_LIB([gtest], [main], [ |
| 107 | AS_IF([test "x$GTEST_LIBS" = "x"], [ |
| 108 | AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS]) |
| 109 | ]) |
| 110 | ], [ |
| 111 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 112 | AC_MSG_ERROR([Testing enabled but couldn't find gtest libs]) |
| 113 | ]) |
| 114 | ]) |
| 115 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 116 | |
| 117 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 118 | AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS]) |
| 119 | AC_CHECK_LIB([gmock], [main], [ |
| 120 | AS_IF([test "x$GMOCK_LIBS" = "x"], [ |
| 121 | AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS]) |
| 122 | ]) |
| 123 | ], [ |
| 124 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 125 | AC_MSG_ERROR([Testing enabled but couldn't find gmock libs]) |
| 126 | ]) |
| 127 | ]) |
| 128 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 129 | ]) |
| 130 | |
| 131 | # Check for valgrind |
| 132 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 133 | m4_foreach([vgtool], [valgrind_tool_list], |
| 134 | [AX_VALGRIND_DFLT(vgtool, [off])]) |
| 135 | AX_VALGRIND_DFLT([memcheck], [on]) |
| 136 | AX_VALGRIND_CHECK |
| 137 | AM_EXTRA_RECURSIVE_TARGETS([check-valgrind]) |
| 138 | m4_foreach([vgtool], [valgrind_tool_list], |
| 139 | [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)]) |
| 140 | ]) |
| 141 | |
| 142 | # Code coverage |
| 143 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 144 | AX_CODE_COVERAGE |
| 145 | AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage]) |
| 146 | ]) |
| 147 | |
| 148 | # Append -Werror after doing autoconf compiler checks |
| 149 | # Otherwise some perfectly valid checks can fail and cause our |
| 150 | # final configuratin to be broken. |
William A. Kennington III | d6d5314 | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 151 | AC_ARG_ENABLE([werror], AC_HELP_STRING([--disable-werror], [Whether to automatically add -Werror CFLAGS])) |
William A. Kennington III | 8f90e28 | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 152 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 153 | AX_APPEND_COMPILE_FLAGS([-Werror], [CFLAGS]) |
| 154 | AX_APPEND_COMPILE_FLAGS([-Werror], [CXXFLAGS]) |
| 155 | ]) |
| 156 | |
| 157 | # Create configured output |
| 158 | AC_CONFIG_FILES([Makefile example/Makefile src/Makefile test/Makefile]) |
| 159 | AC_CONFIG_FILES([src/sdeventplus.pc]) |
| 160 | AC_OUTPUT |