William A. Kennington III | 1d25055 | 2018-08-16 00:46:34 -0700 | [diff] [blame] | 1 | # Initialization |
| 2 | AC_PREREQ([2.69]) |
| 3 | AC_INIT([gpioplus], [0.1], [https://github.com/openbmc/gpioplus/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([nostdinc 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. |
William A. Kennington III | d8c0a7f | 2018-08-16 14:00:02 -0700 | [diff] [blame] | 14 | AS_IF([test "x$enable_tests" = "xno"], [enable_code_coverage=no]) |
William A. Kennington III | 1d25055 | 2018-08-16 00:46:34 -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 |
| 32 | LT_INIT # Removes 'unrecognized options: --with-libtool-sysroot' |
| 33 | |
| 34 | # Make sure the pkgconfigdata is configured for automake |
| 35 | PKG_INSTALLDIR |
| 36 | |
| 37 | # Checks for typedefs, structures, and compiler characteristics. |
| 38 | AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory]) |
| 39 | AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CFLAGS]) |
| 40 | AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CXXFLAGS]) |
| 41 | |
| 42 | # We require the linux gpio functionality |
| 43 | AC_CHECK_HEADERS([linux/gpio.h], [], [ |
| 44 | AC_MSG_ERROR([Could not find linux/gpio.h]) |
| 45 | ]) |
| 46 | |
| 47 | # Make it possible for users to choose to disable examples |
| 48 | AC_ARG_ENABLE([examples], AC_HELP_STRING([--disable-examples], |
| 49 | [Build example programs])) |
| 50 | AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" != "xno"]) |
| 51 | |
| 52 | # Make it possible for users to choose if they want test support |
| 53 | # explicitly or not at all |
| 54 | AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests], |
| 55 | [Build test cases])) |
| 56 | |
| 57 | # Check/set gtest specific functions. |
| 58 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 59 | PKG_CHECK_MODULES([GTEST], [gtest], [], [true]) |
| 60 | PKG_CHECK_MODULES([GMOCK], [gmock], [], [true]) |
| 61 | AX_PTHREAD |
| 62 | |
| 63 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 64 | AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS]) |
| 65 | AC_LANG_PUSH([C++]) |
| 66 | AC_CHECK_HEADERS([gtest/gtest.h], [ |
| 67 | AS_IF([test "x$GTEST_CFLAGS" = "x"], [ |
| 68 | AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [ |
| 69 | AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS]) |
| 70 | ], [ |
| 71 | AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS]) |
| 72 | AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS]) |
| 73 | ]) |
| 74 | ]) |
| 75 | ], [ |
| 76 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 77 | AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h]) |
| 78 | ]) |
| 79 | ]) |
| 80 | AC_LANG_POP([C++]) |
| 81 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 82 | |
| 83 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 84 | AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS]) |
| 85 | AC_LANG_PUSH([C++]) |
| 86 | AC_CHECK_HEADERS([gmock/gmock.h], [], [ |
| 87 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 88 | AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h]) |
| 89 | ]) |
| 90 | ]) |
| 91 | AC_LANG_POP([C++]) |
| 92 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 93 | |
| 94 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 95 | AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS]) |
| 96 | AC_CHECK_LIB([gtest], [main], [ |
| 97 | AS_IF([test "x$GTEST_LIBS" = "x"], [ |
| 98 | AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS]) |
| 99 | ]) |
| 100 | ], [ |
| 101 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 102 | AC_MSG_ERROR([Testing enabled but couldn't find gtest libs]) |
| 103 | ]) |
| 104 | ]) |
| 105 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 106 | |
| 107 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 108 | AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS]) |
| 109 | AC_CHECK_LIB([gmock], [main], [ |
| 110 | AS_IF([test "x$GMOCK_LIBS" = "x"], [ |
| 111 | AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS]) |
| 112 | ]) |
| 113 | ], [ |
| 114 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 115 | AC_MSG_ERROR([Testing enabled but couldn't find gmock libs]) |
| 116 | ]) |
| 117 | ]) |
| 118 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 119 | ]) |
| 120 | |
| 121 | # Check for valgrind |
William A. Kennington III | d8c0a7f | 2018-08-16 14:00:02 -0700 | [diff] [blame] | 122 | AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no]) |
| 123 | m4_foreach([vgtool], [valgrind_tool_list], |
| 124 | [AX_VALGRIND_DFLT(vgtool, [off])]) |
| 125 | AX_VALGRIND_DFLT([memcheck], [on]) |
| 126 | AX_VALGRIND_CHECK |
| 127 | AM_EXTRA_RECURSIVE_TARGETS([check-valgrind]) |
| 128 | m4_foreach([vgtool], [valgrind_tool_list], |
| 129 | [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)]) |
William A. Kennington III | 1d25055 | 2018-08-16 00:46:34 -0700 | [diff] [blame] | 130 | |
| 131 | # Code coverage |
William A. Kennington III | d8c0a7f | 2018-08-16 14:00:02 -0700 | [diff] [blame] | 132 | AX_CODE_COVERAGE |
| 133 | AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage]) |
William A. Kennington III | 1d25055 | 2018-08-16 00:46:34 -0700 | [diff] [blame] | 134 | |
| 135 | # Append -Werror after doing autoconf compiler checks |
| 136 | # Otherwise some perfectly valid checks can fail and cause our |
| 137 | # final configuratin to be broken. |
| 138 | AC_ARG_ENABLE([werror], AC_HELP_STRING([--disable-werror], [Whether to automatically add -Werror CFLAGS])) |
| 139 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 140 | AX_APPEND_COMPILE_FLAGS([-Werror], [CFLAGS]) |
| 141 | AX_APPEND_COMPILE_FLAGS([-Werror], [CXXFLAGS]) |
| 142 | ]) |
| 143 | |
| 144 | # Create configured output |
| 145 | AC_CONFIG_FILES([Makefile example/Makefile src/Makefile test/Makefile]) |
| 146 | AC_CONFIG_FILES([src/gpioplus.pc]) |
| 147 | AC_OUTPUT |