Fix tests for glog and gflags
authorSara Golemon <sgolemon@fb.com>
Wed, 24 Jun 2015 16:31:49 +0000 (09:31 -0700)
committerSara Golemon <sgolemon@fb.com>
Wed, 24 Jun 2015 18:06:12 +0000 (11:06 -0700)
Summary: The existing tests were trying to find undocumented
symbols in glog/glags which aren't guaranteed to be there on all
platforms.

Use AC_RUN_IFELSE() to try building and executing some code
typical of the usage of these libraries.

Closes #117

Reviewed By: @JoelMarcey

Differential Revision: D2183526

folly/configure.ac

index 3a4311a3e86539ac3b8e4adf7d5d0aac6a7a0fe3..8741396cfc4120d957628e09f69106aae1d63a05 100644 (file)
@@ -52,11 +52,53 @@ fi
 
 CXXFLAGS="$STD $CXXFLAGS"
 
-# Checks for libraries.
-AC_CHECK_LIB([glog],[openlog],[],[AC_MSG_ERROR(
-             [Please install google-glog library])])
-AC_CHECK_LIB([gflags],[getenv],[],[AC_MSG_ERROR(
-             [Please install google-gflags library])])
+# Checks for glog and gflags
+# There are no symbols with C linkage, so we do a try-run
+AC_HAVE_LIBRARY([glog],[],[AC_MSG_ERROR(
+                [Please install google-glog library])])
+AC_CACHE_CHECK(
+  [for glog viability],
+  [folly_cv_prog_cc_glog],
+  [AC_RUN_IFELSE(
+    [AC_LANG_SOURCE[
+      #include <glog/logging.h>
+      int main(int argc, char** argv) {
+        google::InitGoogleLogging(argv[0]);
+        google::ShutdownGoogleLogging();
+        return 0;
+      }
+    ]],
+    [folly_cv_prog_cc_glog=yes],
+    [folly_cv_prog_cc_glog=no]
+  )]
+)
+
+if test "$folly_cv_prog_cc_glog" != "yes"; then
+  AC_MSG_ERROR(["libglog invalid, see config.log for details"])
+fi
+
+AC_HAVE_LIBRARY([gflags],[],[AC_MSG_ERROR(
+                [Please install google-gflags library])])
+AC_CACHE_CHECK(
+  [for gflags viability],
+  [folly_cv_prog_cc_gflags],
+  [AC_RUN_IFELSE(
+    [AC_LANG_SOURCE[
+      #include <gflags/gflags.h>
+      DEFINE_bool(folly_truthy, true, "Sample truthy flag");
+      DEFINE_bool(folly_falsey, false, "Sample falsey flag");
+      int main(int argc, char** argv) {
+        return (FLAGS_folly_truthy && !FLAGS_folly_falsey) ? 0 : 1;
+      }
+    ]],
+    [folly_cv_prog_cc_gflags=yes],
+    [folly_cv_prog_cc_gflags=no]
+  )]
+)
+
+if test "$folly_cv_prog_cc_gflags" != "yes"; then
+  AC_MSG_ERROR(["libgflags invalid, see config.log for details"])
+fi
 
 AC_CHECK_LIB(ssl,
         SSL_ctrl,