Skip to content

Building with MinGW-w64 #13

@brechtsanders

Description

@brechtsanders

Hi,
I was able to build Processlib with MinGW-w64, but it required some patches as it assumes Windows builds are always using MSVC.
Also I wanted the possibility to also build a static library, which was achieved with the CMakeLists.txt patch near the end, which allows the use of -DBUILD_SHARED_LIBS:BOOL=OFF and -DBUILD_SHARED_LIBS:BOOL=ON to build a static/shared library.
Below are my patches for MinGW-w64, I hope you can include them.
Regards
Brecht

patch -ulbf core/include/WindowSpecific/pthread_mutex.h << EOF
@@ -50,3 +50,3 @@
 /* MSC 14 2015 provides this struct */
-#if _MSC_VER < 1900
+#if _MSC_VER < 1900 && !defined(__MINGW64_VERSION_MAJOR)
 struct timespec
EOF
patch -ulbf core/src/WindowSpecific/pthread_thread.cpp << EOF
@@ -353,3 +353,3 @@
       tv->p_state = attr->p_state;
-      ssize = unsigned int(attr->s_size);
+      ssize = (unsigned int)(attr->s_size);
     }
EOF
patch -ulbf tasks/src/SoftRoi.cpp << EOF
@@ -53,3 +53,3 @@

-#ifdef __unix
+#if defined(__unix) || defined(__MINGW32__)
 static inline int min(int a,int b) {return a < b ? a : b;}
EOF
patch -ulbf core/src/PoolThreadMgr.cpp << EOF
@@ -23,3 +23,3 @@
 #include <iostream>
-#ifdef __unix
+#if defined(__unix) || defined(__MINGW32__)
 #include <sys/time.h>
@@ -260,3 +260,3 @@
 {
-#ifdef WIN32
+#if defined(WIN32) && !defined(__MINGW32__)
   _pthread_once_raw(&_init,_processMgrInit);
EOF
patch -ulbf core/include/processlib/SinkTaskMgr.h << EOF
@@ -29,3 +29,3 @@
 #include <pthread.h>
-#ifdef __unix
+#if defined(__unix) || defined(__MINGW32__)
 #include <sys/time.h>
EOF
patch -ulbf core/include/processlib/Stat.h << EOF
@@ -29,3 +29,3 @@
 #include <stdio.h>      /* for printf() and fprintf() */
-#ifdef __unix
+#if defined(__unix) || defined(__MINGW32__)
 #include <sys/time.h>
EOF
patch -ulbf tasks/src/Bpm.cpp << EOF
@@ -30,3 +30,3 @@
 #include <math.h>
-#ifdef __unix
+#if defined(__unix) || defined(__MINGW32__)
 #include <sys/time.h>
EOF
patch -ulbf tasks/src/Flip.cpp << EOF
@@ -80,3 +80,3 @@
 }
-#ifndef __unix
+#if !defined(__unix) && !defined(__MINGW32__)
 #if _MSC_VER < 1900
EOF
patch -ulbf tasks/src/BackgroundSubstraction.cpp << EOF
@@ -57,3 +57,3 @@
   int n = aSize >> 1;          // div / 2
-  if(!((long)srcShort & 15))   // aligned to 128 bits
+  if(!((uintptr_t)srcShort & 15))      // aligned to 128 bits
     {
@@ -123,3 +123,3 @@
   int n = aSize >> 1;          // div / 2
-  if(!((long)srcShort & 15))   // aligned to 128 bits
+  if(!((uintptr_t)srcShort & 15))      // aligned to 128 bits
     {
EOF
patch -ulbf tasks/src/Bpm.cpp << EOF
@@ -43,3 +43,3 @@
 using namespace Tasks;
-#ifdef __unix
+#if defined(__unix) || defined(__MINGW32__)
 template<class INPUT> static inline INPUT max(INPUT a,INPUT b)
@@ -55,3 +55,3 @@
 // oldest windows C++ (VStudio 2008) does not provide round() func with math.h, so wrap it with local function
-#ifdef __unix
+#if defined(__unix) || defined(__MINGW32__)
 #define ROUND(a) round(a)
EOF
patch -ulbf CMakeLists.txt << EOF
@@ -138,5 +138,5 @@
     tasks/src/PeakFinder.cpp
 )
-if(WIN32)
+if(MSVC)
     list(APPEND processlib_srcs
         core/src/WindowSpecific/pthread_cancelling.cpp
@@ -192,5 +192,5 @@
     "\$<INSTALL_INTERFACE:\${CMAKE_INSTALL_INCLUDEDIR}>"
 )
-if(WIN32)
+if(MSVC)
     target_include_directories(processlib PUBLIC
         "\$<BUILD_INTERFACE:\${CMAKE_CURRENT_SOURCE_DIR}/core/include/WindowSpecific>"
@@ -265,5 +265,5 @@
 )

-if(WIN32)
+if(MSVC)
     install(
         DIRECTORY \${CMAKE_CURRENT_SOURCE_DIR}/core/include/WindowSpecific
EOF

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions