| From f9b4499ccb63ef02d8c9de462fbbcf301eb1907a Mon Sep 17 00:00:00 2001 |
| From: Daniel Schulte <daniel.schulte@picture-instruments.com> |
| Date: Tue, 3 Mar 2020 11:09:15 +0100 |
| Subject: [PATCH] Add support for building with MinGW |
| |
| --- |
| aws-cpp-sdk-core/include/aws/core/utils/Array.h | 8 ++++---- |
| .../include/aws/core/utils/crypto/bcrypt/CryptoImpl.h | 7 +++++++ |
| .../include/aws/core/utils/event/EventHeader.h | 10 ++++++++++ |
| .../source/http/windows/WinHttpSyncHttpClient.cpp | 4 ++-- |
| .../source/http/windows/WinINetSyncHttpClient.cpp | 2 +- |
| .../source/http/windows/WinSyncHttpClient.cpp | 2 +- |
| .../source/platform/windows/Environment.cpp | 5 +++++ |
| .../source/platform/windows/FileSystem.cpp | 7 ++++++- |
| .../source/platform/windows/OSVersionInfo.cpp | 2 ++ |
| .../source/utils/crypto/factory/Factories.cpp | 4 ++-- |
| .../BucketAndObjectOperationTest.cpp | 4 ++-- |
| cmake/compiler_settings.cmake | 6 ++++++ |
| .../source/platform/windows/PlatformTesting.cpp | 2 ++ |
| 13 files changed, 50 insertions(+), 13 deletions(-) |
| |
| diff --git a/aws-cpp-sdk-core/include/aws/core/utils/Array.h b/aws-cpp-sdk-core/include/aws/core/utils/Array.h |
| index 1dbb9020f4..6768b6b850 100644 |
| --- a/aws-cpp-sdk-core/include/aws/core/utils/Array.h |
| +++ b/aws-cpp-sdk-core/include/aws/core/utils/Array.h |
| @@ -64,7 +64,7 @@ namespace Aws |
| { |
| m_data.reset(Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG)); |
| |
| -#ifdef _WIN32 |
| +#ifdef _MSC_VER |
| std::copy(arrayToCopy, arrayToCopy + arraySize, stdext::checked_array_iterator< T * >(m_data.get(), m_size)); |
| #else |
| std::copy(arrayToCopy, arrayToCopy + arraySize, m_data.get()); |
| @@ -92,7 +92,7 @@ namespace Aws |
| if(arr->m_size > 0 && arr->m_data) |
| { |
| size_t arraySize = arr->m_size; |
| -#ifdef _WIN32 |
| +#ifdef _MSC_VER |
| std::copy(arr->m_data.get(), arr->m_data.get() + arraySize, stdext::checked_array_iterator< T * >(m_data.get() + location, m_size)); |
| #else |
| std::copy(arr->m_data.get(), arr->m_data.get() + arraySize, m_data.get() + location); |
| @@ -111,7 +111,7 @@ namespace Aws |
| { |
| m_data.reset(Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG)); |
| |
| -#ifdef _WIN32 |
| +#ifdef _MSC_VER |
| std::copy(other.m_data.get(), other.m_data.get() + other.m_size, stdext::checked_array_iterator< T * >(m_data.get(), m_size)); |
| #else |
| std::copy(other.m_data.get(), other.m_data.get() + other.m_size, m_data.get()); |
| @@ -144,7 +144,7 @@ namespace Aws |
| { |
| m_data.reset(Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG)); |
| |
| -#ifdef _WIN32 |
| +#ifdef _MSC_VER |
| std::copy(other.m_data.get(), other.m_data.get() + other.m_size, stdext::checked_array_iterator< T * >(m_data.get(), m_size)); |
| #else |
| std::copy(other.m_data.get(), other.m_data.get() + other.m_size, m_data.get()); |
| diff --git a/aws-cpp-sdk-core/include/aws/core/utils/crypto/bcrypt/CryptoImpl.h b/aws-cpp-sdk-core/include/aws/core/utils/crypto/bcrypt/CryptoImpl.h |
| index 992efab47c..406380033a 100644 |
| --- a/aws-cpp-sdk-core/include/aws/core/utils/crypto/bcrypt/CryptoImpl.h |
| +++ b/aws-cpp-sdk-core/include/aws/core/utils/crypto/bcrypt/CryptoImpl.h |
| @@ -39,7 +39,14 @@ namespace Aws |
| { |
| namespace Crypto |
| { |
| + #ifdef __MINGW32__ |
| + #pragma GCC diagnostic push |
| + #pragma GCC diagnostic ignored "-Wunused-variable" |
| + #endif |
| static const char* SecureRandom_BCrypt_Tag = "SecureRandom_BCrypt"; |
| + #ifdef __MINGW32__ |
| + #pragma GCC diagnostic pop |
| + #endif |
| |
| class SecureRandomBytes_BCrypt : public SecureRandomBytes |
| { |
| diff --git a/aws-cpp-sdk-core/include/aws/core/utils/event/EventHeader.h b/aws-cpp-sdk-core/include/aws/core/utils/event/EventHeader.h |
| index 2041b208da..6fb333bff7 100644 |
| --- a/aws-cpp-sdk-core/include/aws/core/utils/event/EventHeader.h |
| +++ b/aws-cpp-sdk-core/include/aws/core/utils/event/EventHeader.h |
| @@ -24,6 +24,12 @@ |
| #include <aws/event-stream/event_stream.h> |
| #include <cassert> |
| |
| +#ifdef __MINGW32__ |
| +#pragma GCC diagnostic push |
| +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" |
| +#pragma GCC diagnostic ignored "-Wuninitialized" |
| +#endif |
| + |
| namespace Aws |
| { |
| namespace Utils |
| @@ -319,3 +325,7 @@ namespace Aws |
| } |
| } |
| } |
| + |
| +#ifdef __MINGW32__ |
| +#pragma GCC diagnostic pop |
| +#endif |
| diff --git a/aws-cpp-sdk-core/source/http/windows/WinHttpSyncHttpClient.cpp b/aws-cpp-sdk-core/source/http/windows/WinHttpSyncHttpClient.cpp |
| index 4a0f80a161..a98635f706 100644 |
| --- a/aws-cpp-sdk-core/source/http/windows/WinHttpSyncHttpClient.cpp |
| +++ b/aws-cpp-sdk-core/source/http/windows/WinHttpSyncHttpClient.cpp |
| @@ -267,7 +267,7 @@ bool WinHttpSyncHttpClient::DoQueryHeaders(void* hHttpRequest, std::shared_ptr<H |
| wmemset(contentTypeStr, 0, static_cast<size_t>(dwSize / sizeof(wchar_t))); |
| |
| WinHttpQueryHeaders(hHttpRequest, WINHTTP_QUERY_CONTENT_TYPE, nullptr, &contentTypeStr, &dwSize, 0); |
| - if (contentTypeStr[0] != NULL) |
| + if (contentTypeStr[0]) |
| { |
| Aws::String contentStr = StringUtils::FromWString(contentTypeStr); |
| response->SetContentType(contentStr); |
| @@ -298,7 +298,7 @@ bool WinHttpSyncHttpClient::DoQueryHeaders(void* hHttpRequest, std::shared_ptr<H |
| |
| bool WinHttpSyncHttpClient::DoSendRequest(void* hHttpRequest) const |
| { |
| - return (WinHttpSendRequest(hHttpRequest, NULL, NULL, 0, 0, 0, NULL) != 0); |
| + return (WinHttpSendRequest(hHttpRequest, NULL, 0, 0, 0, 0, 0) != 0); |
| } |
| |
| bool WinHttpSyncHttpClient::DoReadData(void* hHttpRequest, char* body, uint64_t size, uint64_t& read) const |
| diff --git a/aws-cpp-sdk-core/source/http/windows/WinINetSyncHttpClient.cpp b/aws-cpp-sdk-core/source/http/windows/WinINetSyncHttpClient.cpp |
| index 8b42c64dab..ef1fd99975 100644 |
| --- a/aws-cpp-sdk-core/source/http/windows/WinINetSyncHttpClient.cpp |
| +++ b/aws-cpp-sdk-core/source/http/windows/WinINetSyncHttpClient.cpp |
| @@ -228,7 +228,7 @@ bool WinINetSyncHttpClient::DoQueryHeaders(void* hHttpRequest, std::shared_ptr<H |
| char contentTypeStr[1024]; |
| dwSize = sizeof(contentTypeStr); |
| HttpQueryInfoA(hHttpRequest, HTTP_QUERY_CONTENT_TYPE, &contentTypeStr, &dwSize, 0); |
| - if (contentTypeStr[0] != NULL) |
| + if (contentTypeStr[0]) |
| { |
| response->SetContentType(contentTypeStr); |
| AWS_LOGSTREAM_DEBUG(GetLogTag(), "Received content type " << contentTypeStr); |
| diff --git a/aws-cpp-sdk-core/source/http/windows/WinSyncHttpClient.cpp b/aws-cpp-sdk-core/source/http/windows/WinSyncHttpClient.cpp |
| index 3758006a53..2b4ce940b7 100644 |
| --- a/aws-cpp-sdk-core/source/http/windows/WinSyncHttpClient.cpp |
| +++ b/aws-cpp-sdk-core/source/http/windows/WinSyncHttpClient.cpp |
| @@ -322,7 +322,7 @@ void WinSyncHttpClient::MakeRequestInternal(HttpRequest& request, |
| } |
| } |
| |
| - if (!success && !IsRequestProcessingEnabled() || !ContinueRequest(*request)) |
| + if (!success && (!IsRequestProcessingEnabled() || !ContinueRequest(*request))) |
| { |
| response->SetClientErrorType(CoreErrors::USER_CANCELLED); |
| response->SetClientErrorMessage("Request processing disabled or continuation cancelled by user's continuation handler."); |
| diff --git a/aws-cpp-sdk-core/source/platform/windows/Environment.cpp b/aws-cpp-sdk-core/source/platform/windows/Environment.cpp |
| index fd8d58f291..097274a56b 100644 |
| --- a/aws-cpp-sdk-core/source/platform/windows/Environment.cpp |
| +++ b/aws-cpp-sdk-core/source/platform/windows/Environment.cpp |
| @@ -29,6 +29,7 @@ that would need to be manually freed in all the client functions, just copy it i |
| */ |
| Aws::String GetEnv(const char *variableName) |
| { |
| +#ifdef _MSC_VER |
| char* variableValue = nullptr; |
| std::size_t valueSize = 0; |
| auto queryResult = _dupenv_s(&variableValue, &valueSize, variableName); |
| @@ -41,6 +42,10 @@ Aws::String GetEnv(const char *variableName) |
| } |
| |
| return result; |
| +#else // __MINGW32__ |
| + auto variableValue = std::getenv(variableName); |
| + return Aws::String( variableValue ? variableValue : "" ); |
| +#endif |
| } |
| |
| } // namespace Environment |
| diff --git a/aws-cpp-sdk-core/source/platform/windows/FileSystem.cpp b/aws-cpp-sdk-core/source/platform/windows/FileSystem.cpp |
| index 49af3c1f79..f427fa9233 100644 |
| --- a/aws-cpp-sdk-core/source/platform/windows/FileSystem.cpp |
| +++ b/aws-cpp-sdk-core/source/platform/windows/FileSystem.cpp |
| @@ -21,7 +21,9 @@ |
| #include <iostream> |
| #include <Userenv.h> |
| |
| -#pragma warning( disable : 4996) |
| +#ifdef _MSC_VER |
| +# pragma warning( disable : 4996) |
| +#endif |
| |
| using namespace Aws::Utils; |
| namespace Aws |
| @@ -314,6 +316,9 @@ Aws::String CreateTempFilePath() |
| { |
| #ifdef _MSC_VER |
| #pragma warning(disable: 4996) // _CRT_SECURE_NO_WARNINGS |
| +#elif !defined(L_tmpnam_s) |
| + // Definition from the MSVC stdio.h |
| + #define L_tmpnam_s (sizeof("\\") + 16) |
| #endif |
| char s_tempName[L_tmpnam_s+1]; |
| |
| diff --git a/aws-cpp-sdk-core/source/platform/windows/OSVersionInfo.cpp b/aws-cpp-sdk-core/source/platform/windows/OSVersionInfo.cpp |
| index 23f395f6bb..18bd5836da 100644 |
| --- a/aws-cpp-sdk-core/source/platform/windows/OSVersionInfo.cpp |
| +++ b/aws-cpp-sdk-core/source/platform/windows/OSVersionInfo.cpp |
| @@ -19,7 +19,9 @@ |
| |
| #include <iomanip> |
| |
| +#ifdef _MSC_VER |
| #pragma warning(disable: 4996) |
| +#endif |
| #include <windows.h> |
| #include <stdio.h> |
| namespace Aws |
| diff --git a/aws-cpp-sdk-core/source/utils/crypto/factory/Factories.cpp b/aws-cpp-sdk-core/source/utils/crypto/factory/Factories.cpp |
| index d7cb481d5c..3b34d7fc62 100644 |
| --- a/aws-cpp-sdk-core/source/utils/crypto/factory/Factories.cpp |
| +++ b/aws-cpp-sdk-core/source/utils/crypto/factory/Factories.cpp |
| @@ -755,7 +755,7 @@ std::shared_ptr<Aws::Utils::Crypto::HMAC> Aws::Utils::Crypto::CreateSha256HMACIm |
| return s_Sha256HMACFactory->CreateImplementation(); |
| } |
| |
| -#ifdef _WIN32 |
| +#ifdef _MSC_VER |
| #pragma warning( push ) |
| #pragma warning( disable : 4702 ) |
| #endif |
| @@ -840,7 +840,7 @@ std::shared_ptr<SymmetricCipher> Aws::Utils::Crypto::CreateAES_KeyWrapImplementa |
| return s_AES_KeyWrapFactory->CreateImplementation(key); |
| } |
| |
| -#ifdef _WIN32 |
| +#ifdef _MSC_VER |
| #pragma warning(pop) |
| #endif |
| |
| diff --git a/aws-cpp-sdk-s3-integration-tests/BucketAndObjectOperationTest.cpp b/aws-cpp-sdk-s3-integration-tests/BucketAndObjectOperationTest.cpp |
| index 0f31fcd061..586303e044 100644 |
| --- a/aws-cpp-sdk-s3-integration-tests/BucketAndObjectOperationTest.cpp |
| +++ b/aws-cpp-sdk-s3-integration-tests/BucketAndObjectOperationTest.cpp |
| @@ -54,9 +54,9 @@ |
| #include <aws/testing/TestingEnvironment.h> |
| #include <fstream> |
| |
| -#ifdef _WIN32 |
| +#ifdef _MSC_VER |
| #pragma warning(disable: 4127) |
| -#endif //_WIN32 |
| +#endif //_MSC_VER |
| |
| #include <aws/core/http/standard/StandardHttpRequest.h> |
| |
| diff --git a/cmake/compiler_settings.cmake b/cmake/compiler_settings.cmake |
| index db054b2c1b..e1d6dce55e 100644 |
| --- a/cmake/compiler_settings.cmake |
| +++ b/cmake/compiler_settings.cmake |
| @@ -11,6 +11,9 @@ else() |
| set(COMPILER_CLANG 1) |
| else() |
| set(COMPILER_GCC 1) |
| + if(MINGW) |
| + set(COMPILER_MINGW 1) |
| + endif() |
| endif() |
| set(USE_GCC_FLAGS 1) |
| endif() |
| @@ -34,6 +37,9 @@ endfunction() |
| |
| macro(set_gcc_flags) |
| list(APPEND AWS_COMPILER_FLAGS "-fno-exceptions" "-std=c++${CPP_STANDARD}") |
| + if(COMPILER_IS_MINGW) |
| + list(APPEND AWS_COMPILER_FLAGS -D__USE_MINGW_ANSI_STDIO=1) |
| + endif() |
| |
| if(NOT BUILD_SHARED_LIBS) |
| list(APPEND AWS_COMPILER_FLAGS "-fPIC") |
| diff --git a/testing-resources/source/platform/windows/PlatformTesting.cpp b/testing-resources/source/platform/windows/PlatformTesting.cpp |
| index 2b0a04c0b4..2a27710557 100644 |
| --- a/testing-resources/source/platform/windows/PlatformTesting.cpp |
| +++ b/testing-resources/source/platform/windows/PlatformTesting.cpp |
| @@ -15,7 +15,9 @@ |
| |
| #include <aws/testing/platform/PlatformTesting.h> |
| |
| +#ifdef _MSC_VER |
| #pragma warning(disable: 4996) |
| +#endif |
| #include <windows.h> |
| #include <aws/core/utils/memory/stl/AWSStringStream.h> |
| |