Skip to content

Commit 5460cef

Browse files
committed
Support compiling on MinGW
1 parent bb1cb6a commit 5460cef

File tree

7 files changed

+45
-7
lines changed

7 files changed

+45
-7
lines changed

CMakeLists.txt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
1818
endif()
1919

2020
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
21-
include(DispatchWindowsSupport)
22-
dispatch_windows_arch_spelling(${CMAKE_SYSTEM_PROCESSOR} DISPATCH_MSVC_ARCH)
23-
dispatch_windows_include_for_arch(${DISPATCH_MSVC_ARCH} DISPATCH_INCLUDES)
24-
include_directories(BEFORE SYSTEM ${DISPATCH_INCLUDES})
25-
dispatch_windows_lib_for_arch(${CMAKE_SYSTEM_PROCESSOR} DISPATCH_LIBDIR)
26-
link_directories(${DISPATCH_LIBDIR})
21+
if(NOT MINGW)
22+
include(DispatchWindowsSupport)
23+
dispatch_windows_arch_spelling(${CMAKE_SYSTEM_PROCESSOR} DISPATCH_MSVC_ARCH)
24+
dispatch_windows_include_for_arch(${DISPATCH_MSVC_ARCH} DISPATCH_INCLUDES)
25+
include_directories(BEFORE SYSTEM ${DISPATCH_INCLUDES})
26+
dispatch_windows_lib_for_arch(${CMAKE_SYSTEM_PROCESSOR} DISPATCH_LIBDIR)
27+
link_directories(${DISPATCH_LIBDIR})
28+
endif()
2729

2830
include(CheckCSourceCompiles)
31+
include(CheckSymbolExists)
32+
2933
check_c_source_compiles([=[
3034
#include <Windows.h>
3135
int main(int argc, char *argv[]) {
@@ -54,6 +58,22 @@ int main(int argc, char *argv[]) {
5458
if(DISPATCH_HAVE_EXTENDED_SLPI_22000)
5559
add_compile_definitions(DISPATCH_HAVE_EXTENDED_SLPI_22000)
5660
endif()
61+
62+
check_c_source_compiles([=[
63+
#include <Windows.h>
64+
#include <winternl.h>
65+
int main(int argc, char *argv[]) {
66+
FILE_PIPE_LOCAL_INFORMATION fpli;
67+
}
68+
]=] HAVE_FILE_PIPE_LOCAL_INFORMATION)
69+
if(HAVE_FILE_PIPE_LOCAL_INFORMATION)
70+
add_compile_definitions(HAVE_FILE_PIPE_LOCAL_INFORMATION)
71+
endif()
72+
73+
check_symbol_exists(mkstemp "stdlib.h" HAVE_MKSTEMP)
74+
if(HAVE_MKSTEMP)
75+
add_compile_definitions(HAVE_MKSTEMP)
76+
endif()
5777
endif()
5878

5979
set(CMAKE_C_STANDARD 11)

cmake/modules/DispatchCompilerWarnings.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

2-
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
2+
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC" OR MINGW)
33
# TODO: someone needs to provide the msvc equivalent warning flags
4+
# -fms-extensions will enable __popcnt64
5+
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fms-extensions>)
46
else()
57
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Werror>)
68
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wall>)

os/generic_win_base.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
// Unices provide `howmany` via sys/param.h
2525
#define howmany(x, y) (((x) + ((y) - 1)) / (y))
2626

27+
#ifndef _MODE_T_
28+
#define _MODE_T_
2729
typedef int mode_t;
30+
#endif
2831
typedef void pthread_attr_t;
2932

3033
#ifndef API_AVAILABLE

src/event/workqueue.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424

2525
#if defined(_WIN32)
2626
#include <wct.h>
27+
28+
#if !defined(WCT_MAX_NODE_COUNT)
29+
#define WCT_MAX_NODE_COUNT 16
30+
#endif
31+
2732
#endif
2833

2934
/*

src/shims/generic_win_stubs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ bool _dispatch_handle_is_socket(HANDLE hFile);
4949
void _dispatch_QueryInterruptTimePrecise(PULONGLONG lpInterruptTimePrecise);
5050
void _dispatch_QueryUnbiasedInterruptTimePrecise(PULONGLONG lpUnbiasedInterruptTimePrecise);
5151

52+
#ifndef HAVE_FILE_PIPE_LOCAL_INFORMATION
5253
enum {
5354
FilePipeLocalInformation = 24,
5455
};
@@ -65,6 +66,7 @@ typedef struct _FILE_PIPE_LOCAL_INFORMATION {
6566
ULONG NamedPipeState;
6667
ULONG NamedPipeEnd;
6768
} FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION;
69+
#endif
6870

6971
NTSTATUS _dispatch_NtQueryInformationFile(HANDLE FileHandle,
7072
PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length,

tests/generic_win_port.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ randomize_name(char *out)
238238
}
239239
}
240240

241+
#ifndef HAVE_MKSTEMP
241242
dispatch_fd_t
242243
mkstemp(char *tmpl)
243244
{
@@ -257,6 +258,7 @@ mkstemp(char *tmpl)
257258
errno = EEXIST;
258259
return -1;
259260
}
261+
#endif
260262

261263
void
262264
print_winapi_error(const char *function_name, DWORD error)

tests/generic_win_port.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include <Windows.h>
88

99
typedef int kern_return_t;
10+
#ifndef _PID_T_
1011
typedef int pid_t;
12+
#endif
1113

1214
#if defined(_WIN64)
1315
typedef long long ssize_t;
@@ -68,8 +70,10 @@ mach_timebase_info(mach_timebase_info_t tbi)
6870
return 0;
6971
}
7072

73+
#ifndef HAVE_MKSTEMP
7174
dispatch_fd_t
7275
mkstemp(char *tmpl);
76+
#endif
7377

7478
void
7579
print_winapi_error(const char *function_name, DWORD error);

0 commit comments

Comments
 (0)