From c3441fb6bafd1646e239b9e36e84272c31f8d4b1 Mon Sep 17 00:00:00 2001 From: Date: Thu, 22 Jan 2009 18:22:48 +0000 Subject: [PATCH] Better Cygwin support. - configure.ac: Add -lpthread only if acx_pthread_ok is yes. In cygwin, we use Windows' thread so that we don't need -lpthread. - base/mutex.h: Define NOMINMAX before we include windows.h. - glog/*.h: Make sure that dllimport doesn't appear in cygwin. Note that windows.h may define _WIN32 macro. - utilities.h: Define OS_CYGWIN. git-svn-id: https://google-glog.googlecode.com/svn/trunk@30 eb4d4688-79bd-11dd-afb4-1d65580434c0 --- configure | 6 ++++-- configure.ac | 8 +++++--- src/base/mutex.h | 4 +++- src/glog/log_severity.h | 2 +- src/glog/logging.h.in | 2 +- src/glog/raw_logging.h.in | 2 +- src/glog/vlog_is_on.h.in | 2 +- src/googletest.h | 10 +++++++--- src/utilities.h | 6 ++++-- 9 files changed, 27 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 2b36bdd..060515b 100755 --- a/configure +++ b/configure @@ -23786,8 +23786,9 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -# To make libglog depend on libpthread on Linux, we need to add -# -lpthread in addition to -pthread. +if test x"$acx_pthread_ok" = x"yes"; then + # To make libglog depend on libpthread on Linux, we need to add + # -lpthread in addition to -pthread. { echo "$as_me:$LINENO: checking for pthread_self in -lpthread" >&5 echo $ECHO_N "checking for pthread_self in -lpthread... $ECHO_C" >&6; } @@ -23859,6 +23860,7 @@ _ACEOF fi +fi # Check if there is google-gflags library installed. { echo "$as_me:$LINENO: checking for main in -lgflags" >&5 diff --git a/configure.ac b/configure.ac index 21209d9..fe54b5b 100644 --- a/configure.ac +++ b/configure.ac @@ -92,9 +92,11 @@ AM_CONDITIONAL(X86_64, test "$is_x86_64" = yes) # Some of the code in this directory depends on pthreads ACX_PTHREAD -# To make libglog depend on libpthread on Linux, we need to add -# -lpthread in addition to -pthread. -AC_CHECK_LIB(pthread, pthread_self) +if test x"$acx_pthread_ok" = x"yes"; then + # To make libglog depend on libpthread on Linux, we need to add + # -lpthread in addition to -pthread. + AC_CHECK_LIB(pthread, pthread_self) +fi # Check if there is google-gflags library installed. AC_CHECK_LIB(gflags, main, ac_cv_have_libgflags=1, ac_cv_have_libgflags=0) diff --git a/src/base/mutex.h b/src/base/mutex.h index 4a0cc2d..090f503 100644 --- a/src/base/mutex.h +++ b/src/base/mutex.h @@ -79,7 +79,7 @@ #elif defined(HAVE_PTHREAD) # include typedef pthread_mutex_t MutexType; -#elif defined(OS_WINDOWS) +#elif defined(OS_WINDOWS) || defined(OS_CYGWIN) # define WIN32_LEAN_AND_MEAN // We only need minimal includes # ifdef GMUTEX_TRYLOCK // We need Windows NT or later for TryEnterCriticalSection(). If you @@ -91,6 +91,8 @@ # endif // To avoid macro definition of ERROR. # define NOGDI +// To avoid macro definition of min/max. +# define NOMINMAX # include typedef CRITICAL_SECTION MutexType; #else diff --git a/src/glog/log_severity.h b/src/glog/log_severity.h index b90d333..5abd0ac 100644 --- a/src/glog/log_severity.h +++ b/src/glog/log_severity.h @@ -5,7 +5,7 @@ // Annoying stuff for windows -- makes sure clients can import these functions #ifndef GOOGLE_GLOG_DLL_DECL -# ifdef _WIN32 +# if defined(_WIN32) && !defined(__CYGWIN__) # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport) # else # define GOOGLE_GLOG_DLL_DECL diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in index 8f6389e..607ec1f 100644 --- a/src/glog/logging.h.in +++ b/src/glog/logging.h.in @@ -29,7 +29,7 @@ // Annoying stuff for windows -- makes sure clients can import these functions #ifndef GOOGLE_GLOG_DLL_DECL -# ifdef _WIN32 +# if defined(_WIN32) && !defined(__CYGWIN__) # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport) # else # define GOOGLE_GLOG_DLL_DECL diff --git a/src/glog/raw_logging.h.in b/src/glog/raw_logging.h.in index c785c36..7baeb3d 100644 --- a/src/glog/raw_logging.h.in +++ b/src/glog/raw_logging.h.in @@ -15,7 +15,7 @@ // Annoying stuff for windows -- makes sure clients can import these functions #ifndef GOOGLE_GLOG_DLL_DECL -# ifdef _WIN32 +# if defined(_WIN32) && !defined(__CYGWIN__) # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport) # else # define GOOGLE_GLOG_DLL_DECL diff --git a/src/glog/vlog_is_on.h.in b/src/glog/vlog_is_on.h.in index ff1adb8..2dab0a2 100644 --- a/src/glog/vlog_is_on.h.in +++ b/src/glog/vlog_is_on.h.in @@ -37,7 +37,7 @@ // Annoying stuff for windows -- makes sure clients can import these functions #ifndef GOOGLE_GLOG_DLL_DECL -# ifdef _WIN32 +# if defined(_WIN32) && !defined(__CYGWIN__) # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport) # else # define GOOGLE_GLOG_DLL_DECL diff --git a/src/googletest.h b/src/googletest.h index 4a4475b..8e41d5e 100644 --- a/src/googletest.h +++ b/src/googletest.h @@ -3,6 +3,8 @@ #endif #define GOOGLETEST_H__ +#include "utilities.h" + #include #include #include @@ -491,7 +493,7 @@ class Thread { void Join() { pthread_join(th_, NULL); } -#elif defined(OS_WINDOWS) +#elif defined(OS_WINDOWS) || defined(OS_CYGWIN) void Start() { handle_ = CreateThread(NULL, 0, @@ -517,9 +519,11 @@ class Thread { return NULL; } - pthread_t th_; -#ifdef OS_WINDOWS +#if defined(OS_WINDOWS) || defined(OS_CYGWIN) HANDLE handle_; + DWORD th_; +#else + pthread_t th_; #endif }; diff --git a/src/utilities.h b/src/utilities.h index dc8c208..0db7c3a 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -6,8 +6,10 @@ #ifndef UTILITIES_H__ #define UTILITIES_H__ -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__CYGWIN32__) +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) # define OS_WINDOWS +#elif defined(__CYGWIN__) || defined(__CYGWIN32__) +# define OS_CYGWIN #elif defined(linux) || defined(__linux) || defined(__linux__) # define OS_LINUX #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) @@ -40,7 +42,7 @@ #include -#if defined(OS_WINDOWS) && !defined(__CYGWIN__) +#if defined(OS_WINDOWS) # include "port.h" #endif -- 2.7.4