Skip to content

Commit

Permalink
Win32: Enable WinHTTP for MinGW
Browse files Browse the repository at this point in the history
  • Loading branch information
phkelley authored and tkelman committed Mar 16, 2015
1 parent d675982 commit 8f426d7
Show file tree
Hide file tree
Showing 8 changed files with 735 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ matrix:
compiler: gcc
include:
- compiler: i586-mingw32msvc-gcc
env: OPTIONS="-DBUILD_CLAR=OFF -DWIN32=ON -DMINGW=ON -DUSE_SSH=OFF"
env: OPTIONS="-DCMAKE_TOOLCHAIN_FILE=../script/toolchain-mingw32.cmake" SKIP_TESTS=1
os: linux
- compiler: gcc
env: COVERITY=1
Expand Down
41 changes: 36 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

PROJECT(libgit2 C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
CMAKE_POLICY(SET CMP0015 NEW)

# Add find modules to the path
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
Expand Down Expand Up @@ -58,10 +59,6 @@ IF(MSVC)
# are linking statically
OPTION( STATIC_CRT "Link the static CRT libraries" ON )

# By default, libgit2 is built with WinHTTP. To use the built-in
# HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument.
OPTION( WINHTTP "Use Win32 WinHTTP routines" ON )

# If you want to embed a copy of libssh2 into libgit2, pass a
# path to libssh2
OPTION( EMBED_SSH_PATH "Path to libssh2 to embed (Windows)" OFF )
Expand All @@ -71,6 +68,12 @@ IF(MSVC)
ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
ENDIF()

IF(WIN32)
# By default, libgit2 is built with WinHTTP. To use the built-in
# HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument.
OPTION( WINHTTP "Use Win32 WinHTTP routines" ON )
ENDIF()

# This variable will contain the libraries we need to put into
# libgit2.pc's Requires.private. That is, what we're linking to or
# what someone who's statically linking us needs to link to.
Expand Down Expand Up @@ -147,10 +150,38 @@ IF (WIN32 AND EMBED_SSH_PATH)
ADD_DEFINITIONS(-DGIT_SSH)
ENDIF()

IF (WIN32 AND WINHTTP AND NOT MINGW)
IF (WIN32 AND WINHTTP)
ADD_DEFINITIONS(-DGIT_WINHTTP)
INCLUDE_DIRECTORIES(deps/http-parser)
FILE(GLOB SRC_HTTP deps/http-parser/*.c deps/http-parser/*.h)

# Since MinGW does not come with headers or an import library for winhttp,
# we have to include a private header and generate our own import library
IF (MINGW)
FIND_PROGRAM(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH)
IF (NOT DLLTOOL)
MESSAGE(FATAL_ERROR "Could not find dlltool command")
ENDIF ()

SET(LIBWINHTTP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps/winhttp")

ADD_CUSTOM_COMMAND(
OUTPUT ${LIBWINHTTP_PATH}/libwinhttp.a
COMMAND ${DLLTOOL} -d winhttp.def -k -D winhttp.dll -l libwinhttp.a
DEPENDS ${LIBWINHTTP_PATH}/winhttp.def
WORKING_DIRECTORY ${LIBWINHTTP_PATH}
)

SET_SOURCE_FILES_PROPERTIES(
${CMAKE_CURRENT_SOURCE_DIR}/src/transports/winhttp.c
PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a
)

INCLUDE_DIRECTORIES(deps/winhttp)
LINK_DIRECTORIES(deps/winhttp)
ENDIF ()

LINK_LIBRARIES(winhttp rpcrt4)
ELSE ()
IF (NOT AMIGA AND USE_OPENSSL)
FIND_PACKAGE(OpenSSL)
Expand Down
37 changes: 37 additions & 0 deletions deps/winhttp/urlmon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/

#ifndef __CUSTOM_URLMON_H
#define __CUSTOM_URLMON_H

typedef struct IInternetSecurityManager IInternetSecurityManager;

typedef struct IInternetSecurityManagerVtbl
{
HRESULT(STDMETHODCALLTYPE *QueryInterface)(IInternetSecurityManager *, REFIID, void **);
ULONG(STDMETHODCALLTYPE *AddRef)(IInternetSecurityManager *);
ULONG(STDMETHODCALLTYPE *Release)(IInternetSecurityManager *);
LPVOID SetSecuritySite;
LPVOID GetSecuritySite;
HRESULT(STDMETHODCALLTYPE *MapUrlToZone)(IInternetSecurityManager *, LPCWSTR, DWORD *, DWORD);
LPVOID GetSecurityId;
LPVOID ProcessUrlAction;
LPVOID QueryCustomPolicy;
LPVOID SetZoneMapping;
LPVOID GetZoneMappings;
} IInternetSecurityManagerVtbl;

struct IInternetSecurityManager
{
CONST_VTBL struct IInternetSecurityManagerVtbl *lpVtbl;
};

#define URLZONE_LOCAL_MACHINE 0
#define URLZONE_INTRANET 1
#define URLZONE_TRUSTED 2

#endif /* __CUSTOM_URLMON_H */
29 changes: 29 additions & 0 deletions deps/winhttp/winhttp.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
LIBRARY WINHTTP
EXPORTS
WinHttpAddRequestHeaders@16
WinHttpCheckPlatform@0
WinHttpCloseHandle@4
WinHttpConnect@16
WinHttpCrackUrl@16
WinHttpCreateUrl@16
WinHttpDetectAutoProxyConfigUrl@8
WinHttpGetDefaultProxyConfiguration@4
WinHttpGetIEProxyConfigForCurrentUser@4
WinHttpGetProxyForUrl@16
WinHttpOpen@20
WinHttpOpenRequest@28
WinHttpQueryAuthSchemes@16
WinHttpQueryDataAvailable@8
WinHttpQueryHeaders@24
WinHttpQueryOption@16
WinHttpReadData@16
WinHttpReceiveResponse@8
WinHttpSendRequest@28
WinHttpSetCredentials@24
WinHttpSetDefaultProxyConfiguration@4
WinHttpSetOption@16
WinHttpSetStatusCallback@16
WinHttpSetTimeouts@20
WinHttpTimeFromSystemTime@8
WinHttpTimeToSystemTime@8
WinHttpWriteData@16
Loading

0 comments on commit 8f426d7

Please sign in to comment.