jncornett / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Need to support MinGW #42

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Per Abrahamsen reported that he was able to compile and install Google Test
successfully on Cygwin for MinGW.  "make check" fails with some errors
though.  The following patch by Per fixes some, but not all, errors.

--- gtest-filepath_test.cc_ORIG 2008-09-18 14:16:58.000000000 +0200
+++ gtest-filepath_test.cc  2008-09-30 21:06:27.575000000 +0200
@@ -61,6 +61,11 @@
 #define PATH_SEP "/"
 #endif  // GTEST_OS_WINDOWS

+#ifdef __MINGW32__
+extern "C" int chdir (const char* dir);
+extern "C" int rmdir (const char* path);
+#endif
+
 namespace testing {
 namespace internal {
 namespace {
--- gtest_unittest.cc_ORIG  2008-09-18 14:16:58.000000000 +0200
+++ gtest_unittest.cc   2008-09-30 21:01:37.864000000 +0200
@@ -1030,6 +1030,8 @@
   return;
 #elif defined(GTEST_OS_WINDOWS)  // If we are on Windows proper.
   _putenv((Message() << name << "=" << value).GetString().c_str());
+#elif defined (__MINGW32__)
+  putenv((Message() << name << "=" << value).GetString().c_str());
 #else
   if (*value == '\0') {
     unsetenv(name);

Original issue reported on code.google.com by shiq...@gmail.com on 30 Sep 2008 at 10:21

GoogleCodeExporter commented 9 years ago
mingw 3.4.5 does not support __try so I had to disable them to build / run with 
mingw

--- gtest\src\gtest.cc-revBASE.svn000.tmp.cc    Sun Oct 19 13:50:44 2008
+++ gtest\src\gtest.cc  Sun Oct 19 13:38:36 2008
@@ -1967,8 +1967,8 @@
   if (!HasSameFixtureClass()) return;

   internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
-#ifdef GTEST_OS_WINDOWS
-  // We are on Windows.
+#if defined(GTEST_OS_WINDOWS) && !defined(__MINGW__) && !defined(__MINGW32__)
+  // We are on Windows but mingw does not support __try.
   impl->os_stack_trace_getter()->UponLeavingGTest();
   __try {
     SetUp();
@@ -1999,7 +1999,7 @@
     AddExceptionThrownFailure(GetExceptionCode(), "TearDown()");
   }

-#else  // We are on Linux or Mac - exceptions are disabled.
+#else  // We are on Linux or Mac or using mingw - exceptions are disabled.
   impl->os_stack_trace_getter()->UponLeavingGTest();
   SetUp();

@@ -2170,8 +2170,8 @@
   const TimeInMillis start = GetTimeInMillis();

   impl->os_stack_trace_getter()->UponLeavingGTest();
-#ifdef GTEST_OS_WINDOWS
-  // We are on Windows.
+#if defined(GTEST_OS_WINDOWS) && !defined(__MINGW__) && !defined(__MINGW32__)
+  // We are on Windows but mingw does not support __try.
   Test* test = NULL;

   __try {
@@ -2183,7 +2183,7 @@
                               "the test fixture's constructor");
     return;
   }
-#else  // We are on Linux or Mac OS - exceptions are disabled.
+#else  // We are on Linux or Mac OS or using mingw - exceptions are disabled.

   // TODO(wan): If test->Run() throws, test won't be deleted.  This is
   // not a problem now as we don't use exceptions.  If we were to
@@ -3214,7 +3214,8 @@
 // We don't protect this under mutex_, as we only support calling it
 // from the main thread.
 int UnitTest::Run() {
-#ifdef GTEST_OS_WINDOWS
+#if defined(GTEST_OS_WINDOWS) && !defined(__MINGW__) && !defined(__MINGW32__)
+  // We are on Windows but mingw does not support __try.

 #if !defined(_WIN32_WCE)
   // SetErrorMode doesn't exist on CE.
@@ -3237,7 +3238,7 @@
   }

 #else
-  // We are on Linux or Mac OS.  There is no exception of any kind.
+  // We are on Linux or Mac OS or using mingw. There is no exception of any 
kind.

   return impl_->RunAllTests();
 #endif  // GTEST_OS_WINDOWS

Original comment by y.pag...@gmail.com on 19 Oct 2008 at 10:58

GoogleCodeExporter commented 9 years ago
I cannot verify it, but this is likely to be fixed in 1.2.0.  Please re-open 
the bug 
if you still have problem building gtest 1.2.0 on mingw.

Original comment by shiq...@gmail.com on 2 Dec 2008 at 5:06