From b788942c7c55f78121a195f989748c0ba92194ad Mon Sep 17 00:00:00 2001
From: Biswapriyo Nath <nathbappai@gmail.com>
Date: Mon, 24 May 2021 10:21:42 +0530
Subject: [PATCH 1/3] CMake: Install DLLs in bin folder.

In Win32 platform, executables and runtime libraries need to be in one folder.
---
 client/common/CMakeLists.txt  |  5 ++++-
 libfreerdp/CMakeLists.txt     |  6 +++++-
 server/Windows/CMakeLists.txt |  5 ++++-
 server/common/CMakeLists.txt  |  6 +++++-
 server/shadow/CMakeLists.txt  | 10 ++++++++--
 winpr/libwinpr/CMakeLists.txt |  6 +++++-
 winpr/tools/CMakeLists.txt    |  6 +++++-
 7 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/client/common/CMakeLists.txt b/client/common/CMakeLists.txt
index cc8f277691e..095039d5779 100644
--- a/client/common/CMakeLists.txt
+++ b/client/common/CMakeLists.txt
@@ -74,7 +74,10 @@ else()
 endif()
 
 
-install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDP-ClientTargets)
+install(TARGETS ${MODULE_NAME} COMPONENT libraries EXPORT FreeRDP-ClientTargets
+        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 
 if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS)
 	get_target_property(OUTPUT_FILENAME ${MODULE_NAME} OUTPUT_NAME)
diff --git a/libfreerdp/CMakeLists.txt b/libfreerdp/CMakeLists.txt
index ef76d059b5b..9b82f6e7033 100644
--- a/libfreerdp/CMakeLists.txt
+++ b/libfreerdp/CMakeLists.txt
@@ -395,7 +395,11 @@ endif()
 
 target_link_libraries(${MODULE_NAME} ${PRIVATE_KEYWORD} ${LIBFREERDP_LIBS} winpr)
 
-install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDPTargets)
+install(TARGETS ${MODULE_NAME} COMPONENT libraries EXPORT FreeRDPTargets
+        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+
 if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS)
     get_target_property(OUTPUT_FILENAME ${MODULE_NAME} OUTPUT_NAME)
     install(FILES ${CMAKE_PDB_BINARY_DIR}/${OUTPUT_FILENAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols)
diff --git a/server/Windows/CMakeLists.txt b/server/Windows/CMakeLists.txt
index aed120586f9..f12687c0cfe 100644
--- a/server/Windows/CMakeLists.txt
+++ b/server/Windows/CMakeLists.txt
@@ -98,7 +98,10 @@
 target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
 
 if(WITH_SERVER_INTERFACE)
-	install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
+	install(TARGETS ${MODULE_NAME} COMPONENT libraries
+            ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 
 	if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS)
 		install(FILES ${CMAKE_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols)
diff --git a/server/common/CMakeLists.txt b/server/common/CMakeLists.txt
index c94a20911b7..2ba633dece9 100644
--- a/server/common/CMakeLists.txt
+++ b/server/common/CMakeLists.txt
@@ -63,7 +63,11 @@ endif()
 target_link_libraries(${MODULE_NAME} ${PRIVATE_KEYWORD} ${FREERDP_CHANNELS_SERVER_LIBS})
 target_link_libraries(${MODULE_NAME} ${PUBLIC_KEYWORD} winpr freerdp)
 
-install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT FreeRDP-ServerTargets)
+install(TARGETS ${MODULE_NAME} COMPONENT libraries EXPORT FreeRDP-ServerTargets
+        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+
 if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS)
     get_target_property(OUTPUT_FILENAME ${MODULE_NAME} OUTPUT_NAME)
     install(FILES ${CMAKE_PDB_BINARY_DIR}/${OUTPUT_FILENAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols)
diff --git a/server/shadow/CMakeLists.txt b/server/shadow/CMakeLists.txt
index 3e0df0b1341..cee1423330a 100644
--- a/server/shadow/CMakeLists.txt
+++ b/server/shadow/CMakeLists.txt
@@ -86,7 +86,10 @@ if (WITH_LIBRARY_VERSIONING)
 	  set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION})
 endif()
 
-install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT server EXPORT FreeRDP-ShadowTargets)
+install(TARGETS ${MODULE_NAME} COMPONENT server EXPORT FreeRDP-ShadowTargets
+        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 
 if (WITH_DEBUG_SYMBOLS AND MSVC)
 	get_target_property(OUTPUT_FILENAME ${MODULE_NAME} OUTPUT_NAME)
@@ -291,7 +294,10 @@ if (WITH_LIBRARY_VERSIONING)
 	set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION})
 endif()
 
-install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT server EXPORT FreeRDP-ShadowTargets)
+install(TARGETS ${MODULE_NAME} COMPONENT server EXPORT FreeRDP-ShadowTargets
+        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 
 if (WITH_DEBUG_SYMBOLS AND MSVC)
 	get_target_property(OUTPUT_FILENAME ${MODULE_NAME} OUTPUT_NAME)
diff --git a/winpr/libwinpr/CMakeLists.txt b/winpr/libwinpr/CMakeLists.txt
index d9673f2d4a2..7ccc09e6e7b 100644
--- a/winpr/libwinpr/CMakeLists.txt
+++ b/winpr/libwinpr/CMakeLists.txt
@@ -142,7 +142,11 @@ endif()
 
 add_definitions(${WINPR_DEFINITIONS})
 target_link_libraries(${MODULE_NAME} ${PRIVATE_KEYWORD} ${WINPR_LIBS_PRIVATE} ${PUBLIC_KEYWORD} ${WINPR_LIBS_PUBLIC})
-install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT WinPRTargets)
+install(TARGETS ${MODULE_NAME} COMPONENT libraries EXPORT WinPRTargets
+        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+
 if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS)
     get_target_property(OUTPUT_FILENAME ${MODULE_NAME} OUTPUT_NAME)
     install(FILES ${CMAKE_PDB_BINARY_DIR}/${OUTPUT_FILENAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols)
diff --git a/winpr/tools/CMakeLists.txt b/winpr/tools/CMakeLists.txt
index 0ddf9fb522d..cf96686ac5e 100644
--- a/winpr/tools/CMakeLists.txt
+++ b/winpr/tools/CMakeLists.txt
@@ -112,7 +112,11 @@ endif()
 add_definitions(${WINPR_DEFINITIONS})
 target_link_libraries(${MODULE_NAME} ${PRIVATE_KEYWORD} ${WINPR_TOOLS_LIBS})
 
-install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries EXPORT WinPRTargets)
+install(TARGETS ${MODULE_NAME} COMPONENT libraries EXPORT WinPRTargets
+        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+
 if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS)
     get_target_property(OUTPUT_FILENAME ${MODULE_NAME} OUTPUT_NAME)
     install(FILES ${CMAKE_PDB_BINARY_DIR}/${OUTPUT_FILENAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols)

From f8cd22cc915d688f1ee3b4ab0bbd4f6c114baa75 Mon Sep 17 00:00:00 2001
From: Biswapriyo Nath <nathbappai@gmail.com>
Date: Mon, 24 May 2021 10:53:49 +0530
Subject: [PATCH 3/3] Check MINGW32 for duplicate type declaration.

---
 include/freerdp/channels/rdpdr.h | 2 ++
 include/freerdp/codec/audio.h    | 2 ++
 include/freerdp/rail.h           | 2 +-
 include/freerdp/server/rdpdr.h   | 2 ++
 server/Windows/wf_wasapi.c       | 4 +++-
 winpr/include/winpr/intrin.h     | 2 +-
 winpr/include/winpr/nt.h         | 6 +++++-
 7 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/include/freerdp/channels/rdpdr.h b/include/freerdp/channels/rdpdr.h
index b61a4c7e189..07af2600f22 100644
--- a/include/freerdp/channels/rdpdr.h
+++ b/include/freerdp/channels/rdpdr.h
@@ -298,6 +298,7 @@ enum FILE_FS_DEVICE_FLAG
 	FILE_DEVICE_SECURE_OPEN = 0x00000100
 };
 
+#ifndef __MINGW32__
 enum FILE_FS_INFORMATION_CLASS
 {
 	FileFsVolumeInformation = 1,
@@ -311,6 +312,7 @@ enum FILE_FS_INFORMATION_CLASS
 	FileFsDriverPathInformation,
 	FileFsMaximumInformation
 };
+#endif
 
 typedef struct _DEVICE DEVICE;
 typedef struct _IRP IRP;
diff --git a/include/freerdp/codec/audio.h b/include/freerdp/codec/audio.h
index e9c0408e8c7..82075826891 100644
--- a/include/freerdp/codec/audio.h
+++ b/include/freerdp/codec/audio.h
@@ -69,6 +69,7 @@ typedef struct AUDIO_FORMAT AUDIO_FORMAT;
  * http://tools.ietf.org/html/rfc2361
  */
 
+#ifndef __MINGW32__
 #define WAVE_FORMAT_UNKNOWN 0x0000
 
 #ifndef WAVE_FORMAT_PCM
@@ -183,6 +184,7 @@ typedef struct AUDIO_FORMAT AUDIO_FORMAT;
 #define WAVE_FORMAT_NORRIS 0x1400
 #define WAVE_FORMAT_SOUNDSPACE_MUSICOMPRESS 0x1500
 #define WAVE_FORMAT_DVM 0x2000
+#endif /* !__MINGW32__ */
 #define WAVE_FORMAT_AAC_MS 0xA106
 
 /**
diff --git a/include/freerdp/rail.h b/include/freerdp/rail.h
index 961ea8f8f5b..8f531fbb771 100644
--- a/include/freerdp/rail.h
+++ b/include/freerdp/rail.h
@@ -246,7 +246,7 @@ enum SPI_MASK
 #define IME_STATE_OPEN 0x00000001
 
 /* ImeConvMode */
-#ifndef _IME_CMODES_
+#if !defined(_IME_CMODES_) && !defined(__MINGW32__)
 #define IME_CMODE_NATIVE 0x00000001
 #define IME_CMODE_KATAKANA 0x00000002
 #define IME_CMODE_FULLSHAPE 0x00000008
diff --git a/include/freerdp/server/rdpdr.h b/include/freerdp/server/rdpdr.h
index 63ddca564d8..72ed0ab2fc1 100644
--- a/include/freerdp/server/rdpdr.h
+++ b/include/freerdp/server/rdpdr.h
@@ -35,6 +35,7 @@
 typedef struct _rdpdr_server_context RdpdrServerContext;
 typedef struct _rdpdr_server_private RdpdrServerPrivate;
 
+#ifndef __MINGW32__
 struct _FILE_DIRECTORY_INFORMATION
 {
 	UINT32 NextEntryOffset;
@@ -49,6 +50,7 @@ struct _FILE_DIRECTORY_INFORMATION
 	char FileName[512];
 };
 typedef struct _FILE_DIRECTORY_INFORMATION FILE_DIRECTORY_INFORMATION;
+#endif
 
 typedef UINT (*psRdpdrStart)(RdpdrServerContext* context);
 typedef UINT (*psRdpdrStop)(RdpdrServerContext* context);
diff --git a/server/Windows/wf_wasapi.c b/server/Windows/wf_wasapi.c
index 9a9dca1c1be..aa7dcd1af6f 100644
--- a/server/Windows/wf_wasapi.c
+++ b/server/Windows/wf_wasapi.c
@@ -18,6 +18,7 @@
 //#define REFTIMES_PER_SEC  50000
 //#define REFTIMES_PER_MILLISEC  50
 
+#ifndef __MINGW32__
 DEFINE_GUID(CLSID_MMDeviceEnumerator, 0xBCDE0395, 0xE52F, 0x467C, 0x8E, 0x3D, 0xC4, 0x57, 0x92,
             0x91, 0x69, 0x2E);
 DEFINE_GUID(IID_IMMDeviceEnumerator, 0xA95664D2, 0x9614, 0x4F35, 0xA7, 0x46, 0xDE, 0x8D, 0xB6, 0x36,
@@ -26,6 +27,7 @@ DEFINE_GUID(IID_IAudioClient, 0x1cb9ad4c, 0xdbfa, 0x4c32, 0xb1, 0x78, 0xc2, 0xf5
             0xb2);
 DEFINE_GUID(IID_IAudioCaptureClient, 0xc8adbd64, 0xe71e, 0x48a0, 0xa4, 0xde, 0x18, 0x5c, 0x39, 0x5c,
             0xd3, 0x17);
+#endif
 
 LPWSTR devStr = NULL;
 wfPeerContext* latestPeer = NULL;
@@ -162,7 +164,7 @@ int wf_wasapi_get_device_string(LPWSTR pattern, LPWSTR* deviceStr)
 	return 0;
 }
 
-static DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam)
+DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam)
 {
 	IMMDeviceEnumerator* pEnumerator = NULL;
 	IMMDevice* pDevice = NULL;
diff --git a/winpr/include/winpr/intrin.h b/winpr/include/winpr/intrin.h
index 53f6b346ab1..b6c3a48ce08 100644
--- a/winpr/include/winpr/intrin.h
+++ b/winpr/include/winpr/intrin.h
@@ -22,7 +22,7 @@
 #ifndef WINPR_INTRIN_H
 #define WINPR_INTRIN_H
 
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__MINGW32__)
 
 /**
  * __lzcnt16, __lzcnt, __lzcnt64:
diff --git a/winpr/include/winpr/nt.h b/winpr/include/winpr/nt.h
index 0cbcde0beae..c58158550cd 100644
--- a/winpr/include/winpr/nt.h
+++ b/winpr/include/winpr/nt.h
@@ -1267,7 +1267,7 @@ static INLINE NTSTATUS NTSTATUS_FROM_WIN32(long x)
 }
 #endif
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__MINGW32__)
 
 /**
  * winternl.h contains an incomplete definition of enum FILE_INFORMATION_CLASS
@@ -1288,8 +1288,11 @@ static INLINE NTSTATUS NTSTATUS_FROM_WIN32(long x)
 #undef _FILE_INFORMATION_CLASS
 #undef FileDirectoryInformation
 
+#elif defined(_WIN32)
+#include <winternl.h>
 #endif
 
+#ifndef __MINGW32__
 typedef enum _FILE_INFORMATION_CLASS
 {
 	FileDirectoryInformation = 1,
@@ -1333,6 +1336,7 @@ typedef enum _FILE_INFORMATION_CLASS
 	FileValidDataLengthInformation,
 	FileShortNameInformation
 } FILE_INFORMATION_CLASS;
+#endif /* !__MINGW32__ */
 
 #if !defined(_WIN32) || defined(_UWP)
 
