Skip to content

Commit 68f00fc

Browse files
author
Sebastiano Merlino
committed
Merge pull request etr#51 from InBetweenNames/master
Introduce support for building on MinGW/Cygwin systems
2 parents 8951cee + 65d42f8 commit 68f00fc

File tree

14 files changed

+96
-46
lines changed

14 files changed

+96
-46
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ compiler:
55
# Change this to your needs
66
before_install:
77
- sudo apt-get install texinfo
8-
- wget http://199.231.187.83/resources/libmicrohttpd-0.9.26.tar.gz
9-
- tar -xvzf libmicrohttpd-0.9.26.tar.gz
10-
- cd libmicrohttpd-0.9.26
8+
- wget ftp://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.37.tar.gz
9+
- tar -xvzf libmicrohttpd-0.9.37.tar.gz
10+
- cd libmicrohttpd-0.9.37
1111
- ./configure --prefix=/usr
1212
- make
1313
- sudo make install

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ Requirements
135135
* libmicrohttpd >= 0.9.7
136136
* doxygen (if you want to build code reference)
137137

138+
Additionally, for MinGW on windows you will need:
139+
* libwinpthread (For MinGW-w64, if you use thread model posix then you have this)
140+
* libgnurx >= 2.5.1
141+
138142
Compilation
139143
===========
140144
libhttpserver uses the standard system where the usual build process

configure.ac

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ m4_define([libhttpserver_REVISION],[2])dnl
2626
m4_define([libhttpserver_PKG_VERSION],[libhttpserver_MAJOR_VERSION.libhttpserver_MINOR_VERSION.libhttpserver_REVISION])dnl
2727
m4_define([libhttpserver_LDF_VERSION],[libhttpserver_MAJOR_VERSION:libhttpserver_MINOR_VERSION:libhttpserver_REVISION])dnl
2828
AC_INIT([libhttpserver], libhttpserver_PKG_VERSION, [electrictwister2000@gmail.com])
29-
AM_INIT_AUTOMAKE
29+
AM_INIT_AUTOMAKE([subdir-objects])
3030
AC_CONFIG_HEADERS([config.h])
3131
AC_CONFIG_MACRO_DIR([m4])
3232

@@ -53,6 +53,21 @@ if test x"$samedirectory" = x"no"; then
5353
fi
5454
fi
5555

56+
case "$host" in
57+
*-mingw*)
58+
NETWORK_HEADER="winsock2.h"
59+
REGEX_LIBS="-lregex -no-undefined"
60+
;;
61+
*-cygwin*)
62+
NETWORK_HEADER="winsock2.h"
63+
REGEX_LIBS="-lregex -no-undefined"
64+
;;
65+
*)
66+
NETWORK_HEADER="arpa/inet.h"
67+
REGEX_LIBS=""
68+
;;
69+
esac
70+
5671
# Checks for header files.
5772
AC_HEADER_STDC
5873
AC_CHECK_HEADER([string],[],[AC_MSG_ERROR("C++ strings not found")])
@@ -73,7 +88,7 @@ AC_CHECK_HEADER([ctype.h],[],[AC_MSG_ERROR("cctype not found")])
7388
AC_CHECK_HEADER([regex.h],[],[AC_MSG_ERROR("regex.h not found")])
7489
AC_CHECK_HEADER([sys/stat.h],[],[AC_MSG_ERROR("sys/stat.h not found")])
7590
AC_CHECK_HEADER([sys/types.h],[],[AC_MSG_ERROR("sys/types.h not found")])
76-
AC_CHECK_HEADER([arpa/inet.h],[],[AC_MSG_ERROR("arpa/inet.h not found")])
91+
AC_CHECK_HEADER([$NETWORK_HEADER],[],[AC_MSG_ERROR("$NETWORK_HEADER not found")])
7792
AC_CHECK_HEADER([signal.h],[],[AC_MSG_ERROR("signal.h not found")])
7893

7994
AC_CHECK_HEADER([gnutls/gnutls.h],[have_gnutls="yes"],[AC_MSG_WARN("gnutls/gnutls.h not found. TLS will be disabled"); have_gnutls="no"])
@@ -84,7 +99,7 @@ PKG_CHECK_MODULES([LIBMICROHTTPD],[libmicrohttpd >= 0.9.7],[],[AC_MSG_ERROR("lib
8499
#AC_CHECK_LIB([microhttpd],[MHD_start_daemon],[],[AC_MSG_ERROR("Microhttpd header files not found. Please use a version >= 0.9.9.")])
85100

86101
CXXFLAGS="-DHTTPSERVER_COMPILATION -D_REENTRANT $LIBMICROHTTPD_CFLAGS $CXXFLAGS"
87-
LDFLAGS="$LIBMICROHTTPD_LIBS $LD_FLAGS"
102+
LDFLAGS="$LIBMICROHTTPD_LIBS $REGEX_LIBS $LD_FLAGS"
88103

89104
m4_pattern_allow([AC_TYPE_SIZE_T])
90105
m4_pattern_allow([AC_TYPE_UINT16_T])

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ AM_CXXFLAGS += -fPIC -Wall
2626
libhttpserver_la_LIBADD = -lmicrohttpd
2727
libhttpserver_la_LDFLAGS =
2828

29-
install-exec-hook:
29+
install-data-hook:
3030
(mkdir -p $(DESTDIR)$(includedir) && cd $(DESTDIR)$(includedir) && $(LN_S) -f httpserver.hpp httpserverpp)
3131

3232
uninstall-hook:

src/details/comet_manager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <errno.h>
2222
#include <iostream>
2323
#include "details/comet_manager.hpp"
24+
#include <sys/time.h>
2425

2526
using namespace std;
2627

@@ -140,7 +141,7 @@ size_t comet_manager::get_topic_consumers(
140141
{
141142
consumers.insert((*it));
142143
}
143-
int size = consumers.size();
144+
std::set<httpserver::http::httpserver_ska>::size_type size = consumers.size();
144145
pthread_rwlock_unlock(&comet_guard);
145146
return size;
146147
}

src/details/http_endpoint.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ http_endpoint::http_endpoint
9999
(parts[i][parts[i].size() - 1] == '}')
100100
)
101101
{
102-
int bar = parts[i].find_first_of('|');
103-
if(bar != (int)string::npos)
102+
std::string::size_type bar = parts[i].find_first_of('|');
103+
if(bar != string::npos)
104104
{
105105
this->url_pars.push_back(parts[i].substr(1, bar - 1));
106106
if(first)
@@ -201,7 +201,7 @@ http_endpoint& http_endpoint::operator =(const http_endpoint& h)
201201

202202
bool http_endpoint::operator <(const http_endpoint& b) const
203203
{
204-
COMPARATOR(this->url_modded, b.url_modded, toupper);
204+
COMPARATOR(this->url_modded, b.url_modded, std::toupper);
205205
}
206206

207207
bool http_endpoint::match(const http_endpoint& url) const

src/http_response.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ namespace details
207207

208208
ssize_t cb(void* cls, uint64_t pos, char* buf, size_t max)
209209
{
210-
int val = static_cast<http_response*>(cls)->cycle_callback(buf);
210+
ssize_t val = static_cast<http_response*>(cls)->cycle_callback(buf);
211211
if(val == -1)
212212
static_cast<http_response*>(cls)->completed = true;
213213
return val;
@@ -272,7 +272,7 @@ ssize_t http_response::data_generator(
272272
if(_this->ws->pop_signaled(_this->connection_id))
273273
{
274274
string message;
275-
int size = _this->ws->read_message(_this->connection_id, message);
275+
size_t size = _this->ws->read_message(_this->connection_id, message);
276276
memcpy(buf, message.c_str(), size);
277277
return size;
278278
}

src/http_utils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@
2121
#include <stdio.h>
2222
#include <stdlib.h>
2323
#include <string.h>
24+
#if defined(__MINGW32__) || defined(__CYGWIN32__)
25+
#define _WINDOWS
26+
#undef _WIN32_WINNT
27+
#define _WIN32_WINNT 0x600
28+
#include <winsock2.h>
29+
#include <ws2tcpip.h>
30+
#else
2431
#include <arpa/inet.h>
32+
#endif
2533
#include <sstream>
2634
#include <iomanip>
2735
#include <fstream>

src/httpserver/create_webserver.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class create_webserver
8585
{
8686
}
8787

88-
explicit create_webserver(int port):
88+
explicit create_webserver(uint16_t port):
8989
_port(port),
9090
_start_method(http::http_utils::INTERNAL_SELECT),
9191
_max_threads(0),
@@ -125,7 +125,7 @@ class create_webserver
125125
{
126126
}
127127

128-
create_webserver& port(int port) { _port = port; return *this; }
128+
create_webserver& port(uint16_t port) { _port = port; return *this; }
129129
create_webserver& start_method(
130130
const http::http_utils::start_method_T& start_method
131131
)
@@ -317,7 +317,7 @@ class create_webserver
317317
}
318318

319319
private:
320-
int _port;
320+
uint16_t _port;
321321
http::http_utils::start_method_T _start_method;
322322
int _max_threads;
323323
int _max_connections;

src/httpserver/details/event_tuple.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace details
4242
fd_set*,
4343
fd_set*,
4444
fd_set*,
45-
int*
45+
MHD_socket*
4646
);
4747

4848
typedef struct timeval(*get_timeout_ptr)();

0 commit comments

Comments
 (0)