From f42b03f7bbaddf8150f5ed5ca48cd0ab2a7b7a15 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 11 Feb 2015 17:35:05 +0100 Subject: [PATCH] build: fix build on win32 Manually pick changes and improvements from master to build on win32 (without specifying platform toolset) --- CMakeLists.txt | 17 ++++++++++++++++- winpr/include/winpr/interlocked.h | 8 ++++++++ winpr/include/winpr/pool.h | 10 +++++++++- winpr/libwinpr/interlocked/interlocked.c | 5 +++-- winpr/libwinpr/pool/callback.c | 2 ++ winpr/libwinpr/pool/callback_cleanup.c | 5 ++--- winpr/libwinpr/pool/callback_environment.c | 4 ++++ winpr/libwinpr/pool/cleanup_group.c | 5 +++-- winpr/libwinpr/pool/io.c | 3 +++ winpr/libwinpr/pool/pool.c | 3 +++ winpr/libwinpr/pool/synch.c | 4 +++- winpr/libwinpr/pool/timer.c | 3 ++- winpr/libwinpr/pool/work.c | 2 ++ 13 files changed, 60 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc9cdc34c..375e2d1b6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,9 +175,24 @@ endif() if(WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUNICODE -D_UNICODE") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WIN32_WINNT=0x0501") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN") + +if(NOT DEFINED CMAKE_WINDOWS_VERSION) + set(CMAKE_WINDOWS_VERSION "WINXP") +endif() + + if(CMAKE_WINDOWS_VERSION STREQUAL "WINXP") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWINVER=0x0501 -DWIN32_WINNT=0x0501") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWINVER=0x0501 -DWIN32_WINNT=0x0501") + elseif(CMAKE_WINDOWS_VERSION STREQUAL "WIN7") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWINVER=0x0601 -DWIN32_WINNT=0x0601") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWINVER=0x0601 -DWIN32_WINNT=0x0601") + elseif(CMAKE_WINDOWS_VERSION STREQUAL "WIN8") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWINVER=0x0602 -DWIN32_WINNT=0x0602") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWINVER=0x0602 -DWIN32_WINNT=0x0602") +endif() + endif() if(IOS) diff --git a/winpr/include/winpr/interlocked.h b/winpr/include/winpr/interlocked.h index e96a2b62f..7b76c48ab 100644 --- a/winpr/include/winpr/interlocked.h +++ b/winpr/include/winpr/interlocked.h @@ -156,8 +156,16 @@ WINPR_API LONG InterlockedCompareExchange(LONG volatile *Destination, LONG Excha #endif /* _WIN32 */ +#if (!defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0502))) +#define WINPR_INTERLOCKED_COMPARE_EXCHANGE64 1 +#endif + +#ifdef WINPR_INTERLOCKED_COMPARE_EXCHANGE64 + WINPR_API LONGLONG InterlockedCompareExchange64(LONGLONG volatile *Destination, LONGLONG Exchange, LONGLONG Comperand); +#endif + /* Doubly-Linked List */ WINPR_API VOID InitializeListHead(PLIST_ENTRY ListHead); diff --git a/winpr/include/winpr/pool.h b/winpr/include/winpr/pool.h index 8ff2ff855..3354c3990 100644 --- a/winpr/include/winpr/pool.h +++ b/winpr/include/winpr/pool.h @@ -121,7 +121,9 @@ typedef struct _TP_WAIT TP_WAIT, *PTP_WAIT; typedef struct _TP_IO TP_IO, *PTP_IO; +#if !defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0601)) typedef TP_CALLBACK_ENVIRON_V1 TP_CALLBACK_ENVIRON, *PTP_CALLBACK_ENVIRON; +#endif #ifndef _WIN32 @@ -152,13 +154,18 @@ typedef VOID (*PTP_WIN32_IO_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Cont #endif +#if (!defined(_WIN32) || ((defined(_WIN32) && (_WIN32_WINNT < 0x0601)))) +#define WINPR_THREAD_POOL 1 +#endif + #ifdef __cplusplus extern "C" { #endif - /* Synch */ +#ifdef WINPR_THREAD_POOL + WINPR_API PTP_WAIT CreateThreadpoolWait(PTP_WAIT_CALLBACK pfnwa, PVOID pv, PTP_CALLBACK_ENVIRON pcbe); WINPR_API VOID CloseThreadpoolWait(PTP_WAIT pwa); WINPR_API VOID SetThreadpoolWait(PTP_WAIT pwa, HANDLE h, PFILETIME pftTimeout); @@ -225,6 +232,7 @@ WINPR_API VOID LeaveCriticalSectionWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci WINPR_API VOID FreeLibraryWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HMODULE mod); WINPR_API VOID DisassociateCurrentThreadFromCallback(PTP_CALLBACK_INSTANCE pci); +#endif /* Dummy */ WINPR_API void winpr_pool_dummy(void); diff --git a/winpr/libwinpr/interlocked/interlocked.c b/winpr/libwinpr/interlocked/interlocked.c index 044c36684..ca391d1cb 100644 --- a/winpr/libwinpr/interlocked/interlocked.c +++ b/winpr/libwinpr/interlocked/interlocked.c @@ -236,11 +236,12 @@ LONG InterlockedCompareExchange(LONG volatile *Destination, LONG Exchange, LONG #endif /* _WIN32 */ -#if defined(_WIN64) +#if defined(_WIN32) && !defined(WINPR_INTERLOCKED_COMPARE_EXCHANGE64) /* InterlockedCompareExchange64 already defined */ -#elif (_WIN32 && (_WIN32_WINNT < 0x0502)) +#elif defined(_WIN32) && defined(WINPR_INTERLOCKED_COMPARE_EXCHANGE64) + static volatile HANDLE mutex = NULL; diff --git a/winpr/libwinpr/pool/callback.c b/winpr/libwinpr/pool/callback.c index f9a600fa8..6ca77ca1e 100644 --- a/winpr/libwinpr/pool/callback.c +++ b/winpr/libwinpr/pool/callback.c @@ -50,6 +50,7 @@ static void module_init() #endif +#ifdef WINPR_THREAD_POOL BOOL CallbackMayRunLong(PTP_CALLBACK_INSTANCE pci) { #ifdef _WIN32 @@ -61,3 +62,4 @@ BOOL CallbackMayRunLong(PTP_CALLBACK_INSTANCE pci) #endif return FALSE; } +#endif \ No newline at end of file diff --git a/winpr/libwinpr/pool/callback_cleanup.c b/winpr/libwinpr/pool/callback_cleanup.c index f0653ae98..9ab50d3e2 100644 --- a/winpr/libwinpr/pool/callback_cleanup.c +++ b/winpr/libwinpr/pool/callback_cleanup.c @@ -62,6 +62,7 @@ static void module_init() #endif +#ifdef WINPR_THREAD_POOL VOID SetEventWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE evt) { #ifdef _WIN32 @@ -127,6 +128,4 @@ VOID DisassociateCurrentThreadFromCallback(PTP_CALLBACK_INSTANCE pci) #else #endif } - - - +#endif diff --git a/winpr/libwinpr/pool/callback_environment.c b/winpr/libwinpr/pool/callback_environment.c index 93d981777..29ea2d4e4 100644 --- a/winpr/libwinpr/pool/callback_environment.c +++ b/winpr/libwinpr/pool/callback_environment.c @@ -26,6 +26,8 @@ #include "pool.h" +#ifdef WINPR_THREAD_POOL + VOID InitializeCallbackEnvironment_V1(TP_CALLBACK_ENVIRON_V1* pcbe) { pcbe->Version = 1; @@ -193,3 +195,5 @@ VOID SetThreadpoolCallbackPriority(PTP_CALLBACK_ENVIRON pcbe, TP_CALLBACK_PRIORI #else #endif } + +#endif \ No newline at end of file diff --git a/winpr/libwinpr/pool/cleanup_group.c b/winpr/libwinpr/pool/cleanup_group.c index bd8676df6..7e0e358d5 100644 --- a/winpr/libwinpr/pool/cleanup_group.c +++ b/winpr/libwinpr/pool/cleanup_group.c @@ -56,6 +56,8 @@ static void module_init() #endif +#ifdef WINPR_THREAD_POOL + PTP_CLEANUP_GROUP CreateThreadpoolCleanupGroup() { PTP_CLEANUP_GROUP cleanupGroup = NULL; @@ -93,5 +95,4 @@ VOID CloseThreadpoolCleanupGroup(PTP_CLEANUP_GROUP ptpcg) free(ptpcg); #endif } - - +#endif \ No newline at end of file diff --git a/winpr/libwinpr/pool/io.c b/winpr/libwinpr/pool/io.c index 5327148d9..577d2fb95 100644 --- a/winpr/libwinpr/pool/io.c +++ b/winpr/libwinpr/pool/io.c @@ -24,6 +24,8 @@ #include #include +#ifdef WINPR_THREAD_POOL + PTP_IO CreateThreadpoolIo(HANDLE fl, PTP_WIN32_IO_CALLBACK pfnio, PVOID pv, PTP_CALLBACK_ENVIRON pcbe) { return NULL; @@ -49,3 +51,4 @@ VOID WaitForThreadpoolIoCallbacks(PTP_IO pio, BOOL fCancelPendingCallbacks) } +#endif \ No newline at end of file diff --git a/winpr/libwinpr/pool/pool.c b/winpr/libwinpr/pool/pool.c index 2151370bf..752719644 100644 --- a/winpr/libwinpr/pool/pool.c +++ b/winpr/libwinpr/pool/pool.c @@ -144,6 +144,8 @@ PTP_POOL GetDefaultThreadpool() #endif +#ifdef WINPR_THREAD_POOL + PTP_POOL CreateThreadpool(PVOID reserved) { PTP_POOL pool = NULL; @@ -230,6 +232,7 @@ VOID SetThreadpoolThreadMaximum(PTP_POOL ptpp, DWORD cthrdMost) #endif } +#endif /* dummy */ void winpr_pool_dummy() diff --git a/winpr/libwinpr/pool/synch.c b/winpr/libwinpr/pool/synch.c index 5f87c78ff..320bedbba 100644 --- a/winpr/libwinpr/pool/synch.c +++ b/winpr/libwinpr/pool/synch.c @@ -24,6 +24,8 @@ #include #include +#ifdef WINPR_THREAD_POOL + PTP_WAIT CreateThreadpoolWait(PTP_WAIT_CALLBACK pfnwa, PVOID pv, PTP_CALLBACK_ENVIRON pcbe) { return NULL; @@ -44,4 +46,4 @@ VOID WaitForThreadpoolWaitCallbacks(PTP_WAIT pwa, BOOL fCancelPendingCallbacks) } - +#endif \ No newline at end of file diff --git a/winpr/libwinpr/pool/timer.c b/winpr/libwinpr/pool/timer.c index 9867941a6..3a49b49a2 100644 --- a/winpr/libwinpr/pool/timer.c +++ b/winpr/libwinpr/pool/timer.c @@ -24,6 +24,7 @@ #include #include +#ifdef WINPR_THREAD_POOL PTP_TIMER CreateThreadpoolTimer(PTP_TIMER_CALLBACK pfnti, PVOID pv, PTP_CALLBACK_ENVIRON pcbe) { return NULL; @@ -49,4 +50,4 @@ VOID WaitForThreadpoolTimerCallbacks(PTP_TIMER pti, BOOL fCancelPendingCallbacks } - +#endif \ No newline at end of file diff --git a/winpr/libwinpr/pool/work.c b/winpr/libwinpr/pool/work.c index 62581650b..5cd3eaea3 100644 --- a/winpr/libwinpr/pool/work.c +++ b/winpr/libwinpr/pool/work.c @@ -60,6 +60,7 @@ static void module_init() #endif +#ifdef WINPR_THREAD_POOL PTP_WORK CreateThreadpoolWork(PTP_WORK_CALLBACK pfnwk, PVOID pv, PTP_CALLBACK_ENVIRON pcbe) { PTP_WORK work = NULL; @@ -153,3 +154,4 @@ VOID WaitForThreadpoolWorkCallbacks(PTP_WORK pwk, BOOL fCancelPendingCallbacks) printf("WaitForThreadpoolWorkCallbacks: error waiting on work completion\n"); #endif } +#endif \ No newline at end of file