[656] Fix building on Windows.

Thanks to Arun Kirthi Cherian.

Bug: https://github.com/eclipse/mosquitto/issues/656
This commit is contained in:
Roger A. Light
2018-01-06 22:42:40 +00:00
parent 024fd400d4
commit 9c6a5f3cf0
10 changed files with 57 additions and 50 deletions
+1
View File
@@ -26,6 +26,7 @@ Contributors:
#include <process.h>
#include <winsock2.h>
#define snprintf sprintf_s
#define strncasecmp _strnicmp
#endif
#include <mosquitto.h>
+10 -11
View File
@@ -1,5 +1,5 @@
option(WITH_STATIC_LIBRARIES "Build the static libraries?" ON)
option(WITH_PIC "Build the static library with PIC(Position Independent Code) enabled archives?" OFF)
option(WITH_STATIC_LIBRARIES "Build static versions of the libmosquitto/pp libraries?" OFF)
option(WITH_PIC "Build the static library with PIC (Position Independent Code) enabled archives?" OFF)
add_subdirectory(cpp)
option(WITH_THREADING "Include client library threading support?" ON)
@@ -90,13 +90,11 @@ if (${WITH_SRV} STREQUAL ON)
endif (ARES_HEADER)
endif (${WITH_SRV} STREQUAL ON)
add_library(libmosquitto_obj OBJECT ${C_SRC})
set_target_properties(libmosquitto_obj PROPERTIES
add_library(libmosquitto SHARED ${C_SRC})
set_target_properties(libmosquitto PROPERTIES
POSITION_INDEPENDENT_CODE 1
)
add_library(libmosquitto SHARED $<TARGET_OBJECTS:libmosquitto_obj>)
target_link_libraries(libmosquitto ${LIBRARIES})
set_target_properties(libmosquitto PROPERTIES
@@ -108,11 +106,12 @@ set_target_properties(libmosquitto PROPERTIES
install(TARGETS libmosquitto RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")
if (${WITH_STATIC_LIBRARIES} STREQUAL ON)
if (${WITH_PIC} STREQUAL OFF)
add_library(libmosquitto_static STATIC ${C_SRC})
else (${WITH_PIC} STREQUAL OFF)
add_library(libmosquitto_static STATIC $<TARGET_OBJECTS:libmosquitto_obj>)
endif (${WITH_PIC} STREQUAL OFF)
add_library(libmosquitto_static STATIC ${C_SRC})
if (${WITH_PIC} STREQUAL ON)
set_target_properties(libmosquitto_static PROPERTIES
POSITION_INDEPENDENT_CODE 1
)
endif (${WITH_PIC} STREQUAL ON)
target_link_libraries(libmosquitto_static ${LIBRARIES})
+11 -16
View File
@@ -2,15 +2,12 @@ include_directories(${mosquitto_SOURCE_DIR}/lib ${mosquitto_SOURCE_DIR}/lib/cpp
${STDBOOL_H_PATH} ${STDINT_H_PATH})
link_directories(${mosquitto_BINARY_DIR}/lib)
set(C_SRC mosquittopp.cpp mosquittopp.h)
set(CPP_SRC mosquittopp.cpp mosquittopp.h)
add_library(mosquittopp_obj OBJECT ${C_SRC})
set_target_properties(mosquittopp_obj PROPERTIES
add_library(mosquittopp SHARED ${CPP_SRC})
set_target_properties(mosquittopp PROPERTIES
POSITION_INDEPENDENT_CODE 1
)
add_library(mosquittopp SHARED $<TARGET_OBJECTS:mosquittopp_obj>)
target_link_libraries(mosquittopp libmosquitto)
set_target_properties(mosquittopp PROPERTIES
VERSION ${VERSION}
@@ -19,17 +16,15 @@ set_target_properties(mosquittopp PROPERTIES
install(TARGETS mosquittopp RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")
if (${WITH_STATIC_LIBRARIES} STREQUAL ON)
if (${WITH_PIC} STREQUAL OFF)
add_library(mosquittopp_static STATIC
$<TARGET_OBJECTS:libmosquitto_obj>
${C_SRC}
add_library(mosquittopp_static STATIC
${C_SRC}
${CPP_SRC}
)
if (${WITH_PIC} STREQUAL ON)
set_target_properties(mosquittopp_static PROPERTIES
POSITION_INDEPENDENT_CODE 1
)
else (${WITH_PIC} STREQUAL OFF)
add_library(mosquittopp_static STATIC
$<TARGET_OBJECTS:libmosquitto_obj>
$<TARGET_OBJECTS:mosquittopp_obj>
)
endif (${WITH_PIC} STREQUAL OFF)
endif (${WITH_PIC} STREQUAL ON)
target_link_libraries(mosquittopp_static ${LIBRARIES})
+1 -1
View File
@@ -31,7 +31,7 @@ extern "C" {
# define libmosq_EXPORT
#endif
#ifdef WIN32
#if defined(_MSC_VER) && _MSC_VER < 1900
# ifndef __cplusplus
# define bool char
# define true 1
+4 -2
View File
@@ -54,6 +54,8 @@ int strcasecmp_p(const void *p1, const void *p2)
#ifdef WIN32
int config__get_dir_files(const char *include_dir, char ***files, int *file_count)
{
int len;
int i;
char **l_files = NULL;
int l_file_count = 0;
char **files_tmp;
@@ -79,7 +81,7 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
mosquitto__free(l_files[i]);
}
mosquitto__free(l_files);
closedir(dh);
FindClose(fh);
return MOSQ_ERR_NOMEM;
}
l_files = files_tmp;
@@ -90,7 +92,7 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
mosquitto__free(l_files[i]);
}
mosquitto__free(l_files);
closedir(dh);
FindClose(fh);
return MOSQ_ERR_NOMEM;
}
snprintf(l_files[l_file_count-1], len, "%s/%s", include_dir, find_data.cFileName);
+1 -1
View File
@@ -407,7 +407,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
}
name_entry = X509_NAME_get_entry(name, i);
if(name_entry){
context->username = mosquitto__strdup((char *)ASN1_STRING_data(name_entry->value));
context->username = mosquitto__strdup((char *)X509_NAME_ENTRY_get_data(name_entry));
}
} else { // use_subject_as_username
BIO *subject_bio = BIO_new(BIO_s_mem());
+3 -1
View File
@@ -603,12 +603,14 @@ int mosquitto_unpwd_check_default(struct mosquitto_db *db, const char *username,
int mosquitto_psk_key_get_default(struct mosquitto_db *db, const char *hint, const char *identity, char *key, int max_key_len);
/* ============================================================
* Window service related functions
* Window service and signal related functions
* ============================================================ */
#if defined(WIN32) || defined(__CYGWIN__)
void service_install(void);
void service_uninstall(void);
void service_run(void);
DWORD WINAPI SigThreadProc(void* data);
#endif
/* ============================================================
+11 -4
View File
@@ -23,15 +23,22 @@ Contributors:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
# include <process.h>
# include <process.h>
# ifndef __cplusplus
# define bool char
# define true 1
# define false 0
# if defined(_MSC_VER) && _MSC_VER < 1900
# define bool char
# define true 1
# define false 0
# else
# include <stdbool.h>
# endif
# endif
# define snprintf sprintf_s
# include <io.h>
# include <windows.h>
#else
# include <stdbool.h>
# include <unistd.h>
+11 -10
View File
@@ -120,16 +120,17 @@ DWORD WINAPI SigThreadProc(void* data)
while (true) {
int wr = WaitForMultipleObjects(sizeof(evt) / sizeof(HANDLE), evt, FALSE, INFINITE);
switch (wr) {
case WAIT_OBJECT_0 + 0:
handle_sigint(SIGINT);
break;
case WAIT_OBJECT_0 + 1:
flag_reload = true;
continue;
case WAIT_OBJECT_0 + 2:
handle_sigusr1(0);
continue;
break;
case WAIT_OBJECT_0 + 0:
handle_sigint(SIGINT);
break;
case WAIT_OBJECT_0 + 1:
flag_reload = true;
continue;
case WAIT_OBJECT_0 + 2:
handle_sigusr1(0);
continue;
break;
}
}
CloseHandle(evt[0]);
CloseHandle(evt[1]);
+4 -4
View File
@@ -39,10 +39,10 @@ extern unsigned int g_connection_count;
#define G_MSGS_SENT_INC(A) (g_msgs_sent+=(A))
#define G_PUB_MSGS_RECEIVED_INC(A) (g_pub_msgs_received+=(A))
#define G_PUB_MSGS_SENT_INC(A) (g_pub_msgs_sent+=(A))
#define G_MSGS_DROPPED_INC(A) (g_msgs_dropped++)
#define G_CLIENTS_EXPIRED_INC(A) (g_clients_expired++)
#define G_SOCKET_CONNECTIONS_INC(A) (g_socket_connections++)
#define G_CONNECTION_COUNT_INC(A) (g_connection_count++)
#define G_MSGS_DROPPED_INC() (g_msgs_dropped++)
#define G_CLIENTS_EXPIRED_INC() (g_clients_expired++)
#define G_SOCKET_CONNECTIONS_INC() (g_socket_connections++)
#define G_CONNECTION_COUNT_INC() (g_connection_count++)
#else