Skip to content

Commit 1b87af5

Browse files
author
Ata Kuyumcu
authored
Merge pull request #16 from martin-kudlicka/patch
Windows patch
2 parents 38abd54 + 7547365 commit 1b87af5

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ option(COUNTLY_USE_CUSTOM_HTTP "Use a custom HTTP library" OFF)
1111
option(COUNTLY_USE_SQLITE "Use SQLite" OFF)
1212
option(COUNTLY_BUILD_TESTS "Build test programs" OFF)
1313

14-
if (NOT BUILD_SHARED_LIBS AND NOT COUNTLY_CUSTOM_HTTP)
14+
if (NOT WIN32 AND NOT BUILD_SHARED_LIBS AND NOT COUNTLY_CUSTOM_HTTP)
1515
message(FATAL_ERROR "You must provide a custom HTTP function when compiling statically.")
1616
endif()
1717

@@ -33,6 +33,13 @@ target_link_libraries(countly Threads::Threads)
3333

3434
target_include_directories(countly PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vendor/json/include)
3535

36+
if (APPLE)
37+
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
38+
endif()
39+
find_package(OpenSSL REQUIRED)
40+
target_include_directories(countly PRIVATE ${OPENSSL_INCLUDE_DIR})
41+
target_link_libraries(countly ${OPENSSL_LIBRARIES})
42+
3643
if(COUNTLY_USE_CUSTOM_HTTP)
3744
target_compile_definitions(countly PRIVATE COUNTLY_USE_CUSTOM_HTTP)
3845
elseif(NOT WIN32)
@@ -47,12 +54,6 @@ if(COUNTLY_USE_SQLITE)
4754
find_package(Sqlite3)
4855
target_include_directories(countly PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor/sqlite)
4956
target_link_libraries(countly sqlite3)
50-
if (APPLE)
51-
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
52-
endif()
53-
find_package(OpenSSL REQUIRED)
54-
target_include_directories(countly PRIVATE ${OPENSSL_INCLUDE_DIRS})
55-
target_link_libraries(countly ${OPENSSL_LIBRARIES})
5657
endif()
5758

5859
if(COUNTLY_BUILD_TESTS)

include/countly.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include "nlohmann/json.hpp"
1616
using json = nlohmann::json;
1717

18+
#ifdef _WIN32
19+
#undef ERROR
20+
#endif
21+
1822
#define COUNTLY_SDK_NAME "cpp-native-unknown"
1923
#define COUNTLY_SDK_VERSION "0.1.0"
2024
#define COUNTLY_API_VERSION "19.8.0"
@@ -136,6 +140,8 @@ class Countly {
136140
void SetPath(const std::string& path) {
137141
#ifdef COUNTLY_USE_SQLITE
138142
setDatabasePath(path);
143+
#elif defined _WIN32
144+
UNREFERENCED_PARAMETER(path);
139145
#endif
140146
}
141147

src/countly.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using json = nlohmann::json;
1717
#ifdef _WIN32
1818
#include "Windows.h"
1919
#include "WinHTTP.h"
20+
#undef ERROR
2021
#pragma comment(lib, "winhttp.lib")
2122
#else
2223
#include "curl/curl.h"
@@ -694,7 +695,7 @@ Countly::HTTPResponse Countly::sendHTTP(std::string path, std::string data) {
694695
}
695696

696697
if (hRequest) {
697-
bool ok = WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, use_post ? data.c_str() : WINHTTP_NO_REQUEST_DATA, use_post ? data.size() : 0, 0, nullptr) != 0;
698+
bool ok = WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, use_post ? (LPVOID)data.data() : WINHTTP_NO_REQUEST_DATA, use_post ? data.size() : 0, 0, 0) != 0;
698699
if (ok) {
699700
ok = WinHttpReceiveResponse(hRequest, NULL);
700701
if (ok) {

0 commit comments

Comments
 (0)