From 830874494792644fdf452bb743bf8e2dfba3b4e2 Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Fri, 24 Mar 2017 20:53:17 +0000 Subject: [PATCH] Build TLS libraries on Windows --- CMakeLists.txt | 2 +- appveyor.yml | 8 +++++++- cbuild.bat | 3 ++- src/CMakeLists.txt | 12 ++++++++---- src/samples/paho_c_pub.c | 4 +--- src/samples/paho_c_sub.c | 35 +++++++++++++++------------------ src/samples/paho_cs_pub.c | 4 +--- src/samples/paho_cs_sub.c | 41 +++++++++++++++++++-------------------- test/CMakeLists.txt | 12 +++++++++--- test/test3.c | 1 + 10 files changed, 66 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 72baa9ba..2b258559 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,7 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") ENDIF() IF(WIN32) - ADD_DEFINITIONS(-DWIN32 -D_WINDOWS -D_CRT_SECURE_NO_DEPRECATE) + ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -DWIN32_LEAN_AND_MEAN -MD) ELSEIF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") ADD_DEFINITIONS(-DOSX) ENDIF() diff --git a/appveyor.yml b/appveyor.yml index 2e264340..79914ff9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,11 @@ version: 1.0.{build} image: Visual Studio 2015 configuration: Debug install: -- cmd: cinst openssl.light +- ps: cinst openssl.light -y +- ps: (new-object net.webclient).DownloadFile('https://eclipse.org/downloads/download.php?file=/mosquitto/binary/win32/mosquitto-1.4.11-install-win32.exe', 'mosquitto-1.4.11-install-win32.exe') +- ps: mosquitto-1.4.11-install-win32.exe /S +- ps: taskkill +- ps: (new-object net.webclient).DownloadFile('ftp://sources.redhat.com/pub/pthreads-win32/dll-latest/dll/x86/pthreadVC2.dll', "C:\Program Files (x86)\mosquitto\pthreadVC2.dll") build_script: - cmd: >- mkdir build.paho @@ -15,6 +19,8 @@ build_script: nmake + python ..\test\mqttsas2.py mqtt.iotree.co.uk + ctest -T test -VV cd .. diff --git a/cbuild.bat b/cbuild.bat index caf673cb..22cbd379 100644 --- a/cbuild.bat +++ b/cbuild.bat @@ -1,13 +1,14 @@ setlocal +rmdir /s /q build.paho mkdir build.paho cd build.paho call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 -cmake -G "NMake Makefiles" -DPAHO_WITH_SSL=FALSE -DPAHO_BUILD_DOCUMENTATION=FALSE -DPAHO_BUILD_SAMPLES=TRUE -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=TRUE .. +cmake -G "NMake Makefiles" -DPAHO_WITH_SSL=TRUE -DPAHO_BUILD_DOCUMENTATION=FALSE -DPAHO_BUILD_SAMPLES=TRUE -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=TRUE .. nmake diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d4b660f2..bcb83e49 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,14 +36,18 @@ IF (PAHO_WITH_SSL) SET(OPENSSL_BREW_PATH "/usr/local/opt/openssl") ENDIF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + IF (WIN32) + SET(OPENSSL_DIR $ENV{OPENSSL_DIR}) + ENDIF () + FIND_PATH(OPENSSL_INCLUDE_DIR openssl/ssl.h - HINTS ${OPENSSL_INC_SEARCH_PATH}/include ${OPENSSL_BREW_PATH}/include/) - FIND_LIBRARY(OPENSSL_LIB NAMES ssl libssl + HINTS ${OPENSSL_INC_SEARCH_PATH}/include ${OPENSSL_DIR}/include ${OPENSSL_BREW_PATH}/include/) + FIND_LIBRARY(OPENSSL_LIB NAMES ssl libssl ssleay32 HINTS ${OPENSSL_BREW_PATH}/lib ${OPENSSL_DIR}/lib ${OPENSSL_DIR}/lib64) - FIND_LIBRARY(OPENSSLCRYPTO_LIB NAMES crypto libcrypto + FIND_LIBRARY(OPENSSLCRYPTO_LIB NAMES crypto libcrypto libeay32 HINTS ${OPENSSL_BREW_PATH}/lib ${OPENSSL_DIR}/lib ${OPENSSL_DIR}/lib64) - MESSAGE(STATUS "OpenSSL hint ${PENSSL_INC_SEARCH_PATH} (includes) / ") + MESSAGE(STATUS "OpenSSL hint ${OPENSSL_INC_SEARCH_PATH} (includes) / ") MESSAGE(STATUS "OpenSSL headers found at ${OPENSSL_INCLUDE_DIR}") MESSAGE(STATUS "OpenSSL library found at ${OPENSSL_LIB}") MESSAGE(STATUS "OpenSSL Crypto library found at ${OPENSSLCRYPTO_LIB}") diff --git a/src/samples/paho_c_pub.c b/src/samples/paho_c_pub.c index 5cdf9e2b..760382dc 100644 --- a/src/samples/paho_c_pub.c +++ b/src/samples/paho_c_pub.c @@ -42,15 +42,13 @@ #include #include #include - +#include #if defined(WIN32) -#include #define sleep Sleep #else #include #include -#include #include #endif diff --git a/src/samples/paho_c_sub.c b/src/samples/paho_c_sub.c index 4c820b60..473bfada 100644 --- a/src/samples/paho_c_sub.c +++ b/src/samples/paho_c_sub.c @@ -3,11 +3,11 @@ * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. + * and Eclipse Distribution License v1.0 which accompany this distribution. * - * The Eclipse Public License is available at + * The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at + * and the Eclipse Distribution License is available at * http://www.eclipse.org/org/documents/edl-v10.php. * * Contributors: @@ -17,15 +17,15 @@ *******************************************************************************/ /* - + stdout subscriber for the asynchronous client - + compulsory parameters: - + --topic topic to subscribe to - + defaulted parameters: - + --host localhost --port 1883 --qos 2 @@ -33,10 +33,10 @@ --clientid stdout-subscriber-async --showtopics off --keepalive 10 - + --userid none --password none - + */ #include "MQTTAsync.h" @@ -45,14 +45,13 @@ #include #include #include +#include #if defined(WIN32) -#include #define sleep Sleep #else #include -#include #include #endif @@ -108,7 +107,7 @@ void usage(void) void getopts(int argc, char** argv) { int count = 2; - + while (count < argc) { if (strcmp(argv[count], "--qos") == 0) @@ -198,7 +197,7 @@ void getopts(int argc, char** argv) } count++; } - + } @@ -287,10 +286,10 @@ int main(int argc, char** argv) MQTTAsync_disconnectOptions disc_opts = MQTTAsync_disconnectOptions_initializer; int rc = 0; char url[100]; - + if (argc < 2) usage(); - + topic = argv[1]; if (strchr(topic, '#') || strchr(topic, '+')) @@ -298,7 +297,7 @@ int main(int argc, char** argv) if (opts.showtopics) printf("topic is %s\n", topic); - getopts(argc, argv); + getopts(argc, argv); sprintf(url, "%s:%s", opts.host, opts.port); rc = MQTTAsync_create(&client, url, opts.clientid, MQTTCLIENT_PERSISTENCE_NONE, NULL); @@ -357,5 +356,3 @@ exit: return EXIT_SUCCESS; } - - diff --git a/src/samples/paho_cs_pub.c b/src/samples/paho_cs_pub.c index 8a4599ac..2f1b2474 100644 --- a/src/samples/paho_cs_pub.c +++ b/src/samples/paho_cs_pub.c @@ -41,14 +41,12 @@ #include #include #include - +#include #if defined(WIN32) -#include #define sleep Sleep #else #include -#include #endif diff --git a/src/samples/paho_cs_sub.c b/src/samples/paho_cs_sub.c index 49ed8300..1aef4b64 100644 --- a/src/samples/paho_cs_sub.c +++ b/src/samples/paho_cs_sub.c @@ -3,11 +3,11 @@ * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. + * and Eclipse Distribution License v1.0 which accompany this distribution. * - * The Eclipse Public License is available at + * The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at + * and the Eclipse Distribution License is available at * http://www.eclipse.org/org/documents/edl-v10.php. * * Contributors: @@ -17,15 +17,15 @@ *******************************************************************************/ /* - + stdout subscriber - + compulsory parameters: - + --topic topic to subscribe to - + defaulted parameters: - + --host localhost --port 1883 --qos 2 @@ -33,10 +33,10 @@ --clientid stdout-subscriber --showtopics off --keepalive 10 - + --userid none --password none - + */ #include "MQTTClient.h" #include "MQTTClientPersistence.h" @@ -44,14 +44,13 @@ #include #include #include +#include #if defined(WIN32) -#include #define sleep Sleep #else #include -#include #endif @@ -119,10 +118,10 @@ int main(int argc, char** argv) char* topic = NULL; int rc = 0; char url[100]; - + if (argc < 2) usage(); - + topic = argv[1]; if (strchr(topic, '#') || strchr(topic, '+')) @@ -130,7 +129,7 @@ int main(int argc, char** argv) if (opts.showtopics) printf("topic is %s\n", topic); - getopts(argc, argv); + getopts(argc, argv); sprintf(url, "%s:%s", opts.host, opts.port); rc = MQTTClient_create(&client, url, opts.clientid, MQTTCLIENT_PERSISTENCE_NONE, NULL); @@ -143,9 +142,9 @@ int main(int argc, char** argv) conn_opts.cleansession = 1; conn_opts.username = opts.username; conn_opts.password = opts.password; - + myconnect(&client, &conn_opts); - + rc = MQTTClient_subscribe(client, topic, opts.qos); while (!toStop) @@ -153,7 +152,7 @@ int main(int argc, char** argv) char* topicName = NULL; int topicLen; MQTTClient_message* message = NULL; - + rc = MQTTClient_receive(client, &topicName, &topicLen, &message, 1000); if (message) { @@ -170,7 +169,7 @@ int main(int argc, char** argv) if (rc != 0) myconnect(&client, &conn_opts); } - + printf("Stopping\n"); MQTTClient_disconnect(client, 0); @@ -183,7 +182,7 @@ int main(int argc, char** argv) void getopts(int argc, char** argv) { int count = 2; - + while (count < argc) { if (strcmp(argv[count], "--qos") == 0) @@ -267,5 +266,5 @@ void getopts(int argc, char** argv) } count++; } - + } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 22c36c12..724edd1c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,8 +1,14 @@ PROJECT(mqtt-tests) -SET(MQTT_TEST_BROKER "tcp://localhost:1883" CACHE STRING "Hostname of a test MQTT broker to use") -SET(MQTT_TEST_PROXY "tcp://localhost:1884" CACHE STRING "Hostname of the test proxy to use") -SET(MQTT_SSL_HOSTNAME "localhost" CACHE STRING "Hostname of a test SSL MQTT broker to use") +IF (WIN32) + SET(MQTT_TEST_BROKER "tcp://mqtt.iotree.co.uk:1883" CACHE STRING "Hostname of a test MQTT broker to use") + SET(MQTT_TEST_PROXY "tcp://localhost:1883" CACHE STRING "Hostname of the test proxy to use") + SET(MQTT_SSL_HOSTNAME "mqtt.iotree.co.uk" CACHE STRING "Hostname of a test SSL MQTT broker to use") +ELSE () + SET(MQTT_TEST_BROKER "tcp://localhost:1883" CACHE STRING "Hostname of a test MQTT broker to use") + SET(MQTT_TEST_PROXY "tcp://localhost:1884" CACHE STRING "Hostname of the test proxy to use") + SET(MQTT_SSL_HOSTNAME "localhost" CACHE STRING "Hostname of a test SSL MQTT broker to use") +ENDIF () SET(CERTDIR $ENV{TRAVIS_BUILD_DIR}/test/ssl ) ADD_EXECUTABLE( diff --git a/test/test3.c b/test/test3.c index e55b6fff..a14c511c 100644 --- a/test/test3.c +++ b/test/test3.c @@ -31,6 +31,7 @@ #include #else #include +#include #define MAXHOSTNAMELEN 256 #define snprintf _snprintf #define setenv(a, b, c) _putenv_s(a, b)