Merge pull request #306 from carlosmn/development Fix network MSYS compilation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 82208dc..26f00c7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,7 +53,10 @@ IF (MSVC)
SET(CMAKE_C_FLAGS_DEBUG "/Od /DEBUG /MTd")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
ELSE ()
- SET(CMAKE_C_FLAGS "-Wall -Wextra -fPIC")
+ SET(CMAKE_C_FLAGS "-Wall -Wextra")
+ IF (NOT MINGW) # MinGW always does PIC and complains if we tell it to
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+ ENDIF ()
SET(CMAKE_C_FLAGS_DEBUG "-g -O0")
SET(CMAKE_C_FLAGS_RELEASE "-O2")
ENDIF()
@@ -86,6 +89,11 @@ ENDIF ()
# Compile and link libgit2
ADD_LIBRARY(git2 ${SRC} ${SRC_ZLIB})
+
+IF (WIN32)
+ TARGET_LINK_LIBRARIES(git2 ws2_32)
+ENDIF ()
+
TARGET_LINK_LIBRARIES(git2 ${CMAKE_THREAD_LIBS_INIT})
SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING})
SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_VERSION_MAJOR})
diff --git a/src/netops.c b/src/netops.c
index 613226d..55cb7e4 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -23,11 +23,12 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef _MSC_VER
+#ifndef _WIN32
# include <sys/types.h>
# include <sys/socket.h>
# include <netdb.h>
#else
+# define _WIN32_WINNT 0x0501
# include <winsock2.h>
# include <Ws2tcpip.h>
# pragma comment(lib, "Ws2_32.lib")
diff --git a/src/transport_git.c b/src/transport_git.c
index d79ab5e..b3e9407 100644
--- a/src/transport_git.c
+++ b/src/transport_git.c
@@ -23,16 +23,6 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef _MSC_VER
-# include <sys/types.h>
-# include <sys/socket.h>
-# include <netdb.h>
-#else
-# include <winsock2.h>
-# include <Ws2tcpip.h>
-# pragma comment(lib, "Ws2_32.lib")
-#endif
-
#include "git2/net.h"
#include "git2/pkt.h"
#include "git2/common.h"