cmake: build&run tests (sortof)
[awesomized/libmemcached] / libtest / has.cc
index 1e020a20047da1301c492dcb923ec95e302975c1..6048bacf24cd806e955779459b5b347da06924d1 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Data Differential YATL (i.e. libtest)  library
  *
- *  Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *  Copyright (C) 2012-2013 Data Differential, http://datadifferential.com/
  *
  *  Redistribution and use in source and binary forms, with or without
  *  modification, are permitted provided that the following conditions are
  *
  */
 
-#include "mem_config.h"
+#include "libtest/yatlcon.h"
 #include <libtest/common.h>
 
+#include <cstdio>
 #include <cstdlib>
 #include <unistd.h>
 
 namespace libtest {
 
+bool has_libmemcached_sasl(void)
+{
+  return false;
+}
+
 bool has_libmemcached(void)
 {
 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
@@ -69,13 +75,15 @@ bool has_libdrizzle(void)
 bool has_postgres_support(void)
 {
   char *getenv_ptr;
-  if (bool((getenv_ptr= getenv("POSTGES_IS_RUNNING_AND_SETUP"))))
+  if (bool((getenv_ptr= getenv("POSTGRES_IS_RUNNING_AND_SETUP"))))
   {
     (void)(getenv_ptr);
+#if defined(HAVE_LIBPQ) && HAVE_LIBPQ
     if (HAVE_LIBPQ)
     {
       return true;
     }
+#endif
   }
 
   return false;
@@ -84,7 +92,7 @@ bool has_postgres_support(void)
 
 bool has_gearmand()
 {
-#if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
+#if defined(GEARMAND_BINARY) && defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
   if (HAVE_GEARMAND_BINARY)
   {
     std::stringstream arg_buffer;
@@ -110,7 +118,7 @@ bool has_gearmand()
 
 bool has_drizzled()
 {
-#if defined(HAVE_DRIZZLED_BINARY) && HAVE_DRIZZLED_BINARY
+#if defined(DRIZZLED_BINARY) && defined(HAVE_DRIZZLED_BINARY) && HAVE_DRIZZLED_BINARY
   if (HAVE_DRIZZLED_BINARY)
   {
     if (access(DRIZZLED_BINARY, X_OK) == 0)
@@ -125,7 +133,7 @@ bool has_drizzled()
 
 bool has_mysqld()
 {
-#if defined(HAVE_MYSQLD_BUILD) && HAVE_MYSQLD_BUILD
+#if defined(MYSQLD_BINARY) && defined(HAVE_MYSQLD_BUILD) && HAVE_MYSQLD_BUILD
   if (HAVE_MYSQLD_BUILD)
   {
     if (access(MYSQLD_BINARY, X_OK) == 0)
@@ -138,14 +146,17 @@ bool has_mysqld()
   return false;
 }
 
-bool has_memcached()
+static char memcached_binary_path[FILENAME_MAX];
+
+static void initialize_memcached_binary_path()
 {
-#if defined(HAVE_MEMCACHED_BINARY) && HAVE_MEMCACHED_BINARY
+  memcached_binary_path[0]= 0;
+
+#if defined(MEMCACHED_BINARY) && defined(HAVE_MEMCACHED_BINARY) && HAVE_MEMCACHED_BINARY
   if (HAVE_MEMCACHED_BINARY)
   {
     std::stringstream arg_buffer;
 
-
     char *getenv_ptr;
     if (bool((getenv_ptr= getenv("PWD"))) and strcmp(MEMCACHED_BINARY, "memcached/memcached") == 0)
     {
@@ -156,27 +167,62 @@ bool has_memcached()
 
     if (access(arg_buffer.str().c_str(), X_OK) == 0)
     {
-      return true;
+      strncpy(memcached_binary_path, arg_buffer.str().c_str(), FILENAME_MAX-1);
     }
   }
 #endif
+}
+
+static pthread_once_t memcached_binary_once= PTHREAD_ONCE_INIT;
+static void initialize_memcached_binary(void)
+{
+  int ret;
+  if ((ret= pthread_once(&memcached_binary_once, initialize_memcached_binary_path)) != 0)
+  {
+    FATAL(strerror(ret));
+  }
+}
+
+bool has_memcached()
+{
+  initialize_memcached_binary();
+
+  if (memcached_binary_path[0] and (strlen(memcached_binary_path) > 0))
+  {
+    return true;
+  }
 
   return false;
 }
 
-bool has_memcached_sasl()
+const char* memcached_binary()
 {
-#if defined(HAVE_MEMCACHED_SASL_BINARY) && HAVE_MEMCACHED_SASL_BINARY
-  if (HAVE_MEMCACHED_SASL_BINARY)
+  initialize_memcached_binary();
+
+  if (memcached_binary_path[0])
   {
-    if (access(MEMCACHED_SASL_BINARY, X_OK) == 0)
-    {
-      return true;
-    }
+    return memcached_binary_path;
   }
+
+  return NULL;
+}
+
+const char *gearmand_binary() 
+{
+#if defined(GEARMAND_BINARY)
+  return GEARMAND_BINARY;
+#else
+  return NULL;
 #endif
+}
 
-  return false;
+const char *drizzled_binary() 
+{
+#if defined(DRIZZLED_BINARY)
+  return DRIZZLED_BINARY;
+#else
+  return NULL;
+#endif
 }
 
 } // namespace libtest