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