Skip to content

Commit 924e9b6

Browse files
Add support for MinGW-w64 (#735)
Add support for MinGW-w64 under MSYS2 environment. Currently requires curl and libbcrypt installed. Resolves: OLPSUP-9555 Signed-off-by: Serhii Lozynskyi <[email protected]>
1 parent 9740ef2 commit 924e9b6

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

olp-cpp-sdk-authentication/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ target_link_libraries(${PROJECT_NAME}
3737
${PROJECT_LIBS}
3838
)
3939

40+
# On MINGW boost uses bcrypt library
41+
if (MINGW)
42+
target_link_libraries(${PROJECT_NAME} PRIVATE bcrypt )
43+
endif()
44+
4045
target_compile_definitions(${PROJECT_NAME}
4146
PRIVATE AUTHENTICATION_LIBRARY)
4247
if(BUILD_SHARED_LIBS)

olp-cpp-sdk-core/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ include(cmake/CompileChecks.cmake)
3030

3131
porting_do_checks()
3232

33-
if(ANDROID OR IOS OR WIN32)
33+
if(ANDROID OR IOS OR (WIN32 AND NOT MINGW))
3434
set(NETWORK_NO_CURL ON)
3535

3636
if(ANDROID)
@@ -262,9 +262,13 @@ if (IOS)
262262
endif()
263263

264264
if (WIN32)
265-
set(OLP_SDK_HTTP_SOURCES ${OLP_SDK_HTTP_SOURCES} ${OLP_SDK_HTTP_WIN_SOURCES})
266-
267-
set(OLP_SDK_DEFAULT_NETWORK_DEFINITION OLP_SDK_NETWORK_HAS_WINHTTP)
265+
if (MINGW)
266+
set(OLP_SDK_HTTP_SOURCES ${OLP_SDK_HTTP_SOURCES} ${OLP_SDK_HTTP_CURL_SOURCES})
267+
set(OLP_SDK_DEFAULT_NETWORK_DEFINITION OLP_SDK_NETWORK_HAS_CURL)
268+
else()
269+
set(OLP_SDK_HTTP_SOURCES ${OLP_SDK_HTTP_SOURCES} ${OLP_SDK_HTTP_WIN_SOURCES})
270+
set(OLP_SDK_DEFAULT_NETWORK_DEFINITION OLP_SDK_NETWORK_HAS_WINHTTP)
271+
endif()
268272
endif()
269273

270274
set(OLP_SDK_PLATFORM_SOURCES
@@ -399,7 +403,7 @@ elseif(ANDROID)
399403
add_dependencies(${PROJECT_NAME} ${OLP_SDK_ANDROID_HTTP_CLIENT_JAR})
400404
endif()
401405

402-
if(CURL_FOUND)
406+
if(CURL_FOUND AND NOT MINGW)
403407
include(CheckIncludeFile)
404408
check_include_file(signal.h HAVE_SIGNAL_H)
405409
if(HAVE_SIGNAL_H)

olp-cpp-sdk-core/cmake/curl.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if(CURL_FOUND AND NOT NETWORK_NO_CURL)
2020

2121
add_definitions(-DOLP_SDK_NETWORK_HAS_CURL)
2222
set(OLP_SDK_NETWORK_CURL_LIBRARIES ${CURL_LIBRARIES})
23-
if(WIN32)
23+
if(WIN32 AND NOT MINGW)
2424
set(OLP_SDK_NETWORK_CURL_LIBRARIES ${OLP_SDK_NETWORK_CURL_LIBRARIES} ws2_32)
2525
endif()
2626
if(APPLE)

olp-cpp-sdk-core/cmake/winhttp.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
1616
# License-Filename: LICENSE
17-
if(WIN32)
17+
if(WIN32 AND NOT MINGW)
1818
set(OLP_SDK_HTTP_WIN_SOURCES
1919
"${CMAKE_CURRENT_LIST_DIR}/../src/http/winhttp/NetworkWinHttp.cpp"
2020
"${CMAKE_CURRENT_LIST_DIR}/../src/http/winhttp/NetworkWinHttp.h"

olp-cpp-sdk-core/src/utils/Dir.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "olp/core/utils/Dir.h"
2121

22-
#ifdef _WIN32
22+
#if defined(_WIN32) && !defined(__MINGW32__)
2323
#ifndef WIN32_LEAN_AND_MEAN
2424
#define WIN32_LEAN_AND_MEAN
2525
#endif
@@ -35,15 +35,16 @@
3535
#include <unistd.h>
3636
#endif
3737

38-
#ifdef _WIN32
38+
#if defined(_WIN32) && !defined(__MINGW32__)
3939
#define G_COUNTOF(array) (sizeof(array) / sizeof(array[0]))
4040
#endif
4141

4242
namespace olp {
4343
namespace utils {
4444

4545
namespace {
46-
#if defined(_WIN32) && defined(_UNICODE)
46+
#if defined(_WIN32) && !defined(__MINGW32__)
47+
#ifdef _UNICODE
4748
std::wstring ConvertStringToWideString(const std::string& str) {
4849
int size_needed =
4950
MultiByteToWideChar(CP_ACP, 0, &str[0], str.size(), NULL, 0);
@@ -52,9 +53,10 @@ std::wstring ConvertStringToWideString(const std::string& str) {
5253
size_needed);
5354
return wstr_path;
5455
}
55-
#endif // _WIN32 && _UNICODE
56+
#endif // _UNICODE
57+
#endif // _WIN32 && _MINGW32
5658

57-
#ifndef _WIN32
59+
#if !defined(_WIN32) || defined(__MINGW32__)
5860
int remove_dir_callback(const char* file, const struct stat* /*stat*/, int flag,
5961
struct FTW* /*buf*/) {
6062
int rc = 0;
@@ -100,7 +102,11 @@ static bool mkdir_all(const char* dirname, int mode) {
100102

101103
std::string subdir(ptr, end - ptr);
102104

105+
#if defined(__MINGW32__)
106+
int rc = mkdir(subdir.c_str());
107+
#else
103108
int rc = mkdir(subdir.c_str(), mode);
109+
#endif
104110
if (rc != 0 && errno != EEXIST) {
105111
return false;
106112
}
@@ -116,8 +122,8 @@ static bool mkdir_all(const char* dirname, int mode) {
116122
}
117123
#endif // ifndef _WIN32
118124

119-
#ifdef _WIN32
120-
static void Tokenize(const std::string& path, const std::string& delimiters,
125+
#if defined(_WIN32) && !defined(__MINGW32__)
126+
void Tokenize(const std::string& path, const std::string& delimiters,
121127
std::vector<std::string>& result) {
122128
std::string sub_path = path;
123129
while (1) {
@@ -208,8 +214,7 @@ bool DeleteDirectory(const TCHAR* utfdirPath) {
208214
} // namespace
209215

210216
bool Dir::Exists(const std::string& path) {
211-
#ifdef _WIN32
212-
217+
#if defined(_WIN32) && !defined(MINGW32)
213218
#ifdef _UNICODE
214219
std::wstring wstr_path = ConvertStringToWideString(path);
215220
const TCHAR* syspath = wstr_path.c_str();
@@ -245,7 +250,7 @@ bool Dir::exists(const std::string& path) { return Dir::Exists(path); }
245250

246251
bool Dir::Remove(const std::string& path) {
247252
bool ret = true;
248-
#ifdef _WIN32
253+
#if defined(_WIN32) && !defined(__MINGW32__)
249254
#ifdef _UNICODE
250255
std::wstring wstrPath = ConvertStringToWideString(path);
251256
const TCHAR* n_path = wstrPath.c_str();
@@ -271,7 +276,7 @@ bool Dir::Create(const std::string& path) {
271276
return true;
272277
}
273278
bool ret = true;
274-
#ifndef _WIN32
279+
#if !defined(_WIN32) || defined(__MINGW32__)
275280
struct stat sbuf;
276281
if (stat(path.c_str(), &sbuf) != 0) {
277282
if (!mkdir_all(path.c_str(), 0777)) {
@@ -323,7 +328,7 @@ bool Dir::Create(const std::string& path) {
323328
bool Dir::create(const std::string& path) { return Dir::Create(path); }
324329

325330
std::string Dir::TempDirectory() {
326-
#if defined(_WIN32)
331+
#if defined(_WIN32) && !defined(__MINGW32__)
327332
wchar_t path[MAX_PATH];
328333
::GetTempPathW(MAX_PATH, path);
329334

@@ -365,7 +370,7 @@ std::string Dir::TempDirectory() {
365370
}
366371

367372
bool Dir::FileExists(const std::string& file_path) {
368-
#ifdef _WIN32
373+
#if defined(_WIN32) && !defined(__MINGW32__)
369374
#ifdef _UNICODE
370375
std::wstring wstrPath = ConvertStringToWideString(file_path);
371376
const TCHAR* syspath = wstrPath.c_str();

0 commit comments

Comments
 (0)