diff options
author | Patrick Venture <venture@google.com> | 2019-03-06 10:24:04 -0800 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2019-03-06 13:18:56 -0800 |
commit | 5d8f570bdc264d7447ee2fc0fb6f134c1a3780f8 (patch) | |
tree | e49cea96e04461b6e653cf5e45765ea6a2d58e49 | |
parent | 56c876f3a108f4f4fdbe13898ac3ba47b98b9a20 (diff) | |
download | phosphor-hwmon-5d8f570bdc264d7447ee2fc0fb6f134c1a3780f8.tar.gz phosphor-hwmon-5d8f570bdc264d7447ee2fc0fb6f134c1a3780f8.zip |
test: rework gtest/gmock lookup
Rework the gtest/gmock lookup based on openbmc/gpioplus.
Change-Id: Ic53928e6f8b7a30e801976d62c910fe31bd4cc49
Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r-- | configure.ac | 85 | ||||
-rw-r--r-- | test/Makefile.am | 10 |
2 files changed, 73 insertions, 22 deletions
diff --git a/configure.ac b/configure.ac index 0c8fc09..6278681 100644 --- a/configure.ac +++ b/configure.ac @@ -36,25 +36,74 @@ AC_CHECK_HEADER( # Checks for library functions. LT_INIT +# Make it possible for users to choose if they want test support +# explicitly or not at all +AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests], + [Build test cases])) + # Check/set gtest specific functions. -PKG_CHECK_MODULES( - [GTEST], - [gtest], - [], - [AC_MSG_NOTICE([gtest not found, tests will not build])] -) -PKG_CHECK_MODULES( - [GMOCK], - [gmock], - [], - [AC_MSG_NOTICE([gmock not found, tests will not build])] -) -PKG_CHECK_MODULES( - [GTEST_MAIN], - [gtest_main], - [], - [AC_MSG_NOTICE([gtest_main not found, tests will not build])] -) +AS_IF([test "x$enable_tests" != "xno"], [ + PKG_CHECK_MODULES([GTEST], [gtest], [], [true]) + PKG_CHECK_MODULES([GMOCK], [gmock], [], [true]) + AX_PTHREAD + + AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) + AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS]) + AC_LANG_PUSH([C++]) + AC_CHECK_HEADERS([gtest/gtest.h], [ + AS_IF([test "x$GTEST_CFLAGS" = "x"], [ + AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [ + AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS]) + ], [ + AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS]) + AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS]) + ]) + ]) + ], [ + AS_IF([test "x$enable_tests" = "xyes"], [ + AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h]) + ]) + ]) + AC_LANG_POP([C++]) + AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) + + AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) + AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS]) + AC_LANG_PUSH([C++]) + AC_CHECK_HEADERS([gmock/gmock.h], [], [ + AS_IF([test "x$enable_tests" = "xyes"], [ + AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h]) + ]) + ]) + AC_LANG_POP([C++]) + AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) + + AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) + AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS]) + AC_CHECK_LIB([gtest], [main], [ + AS_IF([test "x$GTEST_LIBS" = "x"], [ + AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS]) + ]) + ], [ + AS_IF([test "x$enable_tests" = "xyes"], [ + AC_MSG_ERROR([Testing enabled but couldn't find gtest libs]) + ]) + ]) + AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) + + AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) + AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS]) + AC_CHECK_LIB([gmock], [main], [ + AS_IF([test "x$GMOCK_LIBS" = "x"], [ + AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS]) + ]) + ], [ + AS_IF([test "x$enable_tests" = "xyes"], [ + AC_MSG_ERROR([Testing enabled but couldn't find gmock libs]) + ]) + ]) + AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) +]) # Add --enable-oe-sdk flag to configure script AC_ARG_ENABLE([oe-sdk], diff --git a/test/Makefile.am b/test/Makefile.am index 2682d45..562de03 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,11 +1,13 @@ -AM_CPPFLAGS = -I$(top_srcdir)/ $(GTEST_CFLAGS) $(GMOCK_CFLAGS) -AM_CXXFLAGS = \ - $(GTEST_MAIN_CFLAGS) +AM_CPPFLAGS = \ + -I$(top_srcdir)/ \ + $(GTEST_CFLAGS) \ + $(GMOCK_CFLAGS) \ $(SDBUSPLUS_CFLAGS) \ $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) AM_LDFLAGS = \ + $(GTEST_LIBS) \ $(GMOCK_LIBS) \ - $(GTEST_MAIN_LIBS) \ + -lgmock_main \ $(OESDK_TESTCASE_FLAGS) \ $(SDBUSPLUS_LIBS) \ $(PHOSPHOR_DBUS_INTERFACES_LIBS) |