Skip to content

Commit 5e8789e

Browse files
authored
Merge pull request swiftlang#245 from compnerd/windows-cleanups
Windows cleanups
2 parents 3828fbb + 1122e85 commit 5e8789e

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ check_include_files("unistd.h" HAVE_UNISTD_H)
154154
check_include_files("objc/objc-internal.h" HAVE_OBJC)
155155

156156
check_library_exists(pthread sem_init "" USE_POSIX_SEM)
157+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
158+
add_definitions(-DTARGET_OS_WIN32)
159+
add_definitions(-DUSE_WIN32_SEM)
160+
endif()
157161

158162
check_symbol_exists(CLOCK_UPTIME "time.h" HAVE_DECL_CLOCK_UPTIME)
159163
check_symbol_exists(CLOCK_UPTIME_FAST "time.h" HAVE_DECL_CLOCK_UPTIME_FAST)

dispatch/dispatch.h

+4
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@
3939
#endif
4040
#endif // __APPLE__
4141

42+
#if HAVE_SYS_CDEFS_H
4243
#include <sys/cdefs.h>
44+
#endif
4345
#include <sys/types.h>
4446
#include <stddef.h>
4547
#include <stdint.h>
4648
#include <stdbool.h>
4749
#include <stdarg.h>
50+
#if HAVE_UNISTD_H
4851
#include <unistd.h>
52+
#endif
4953
#include <fcntl.h>
5054

5155
#if defined(__linux__) && defined(__has_feature)

os/object.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
#include <TargetConditionals.h>
2727
#include <os/availability.h>
2828
#endif
29-
#ifndef __linux__
30-
#include <os/base.h>
31-
#else
29+
#ifdef __linux__
3230
#include <os/linux_base.h>
31+
#else
32+
#include <os/base.h>
3333
#endif
3434

3535
/*!

os/object_private.h

+2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
#ifndef __OS_OBJECT_PRIVATE__
2828
#define __OS_OBJECT_PRIVATE__
2929

30+
#if HAVE_SYS_CDEFS_H
3031
#include <sys/cdefs.h>
32+
#endif
3133
#include <stddef.h>
3234
#include <os/object.h>
3335

src/CMakeLists.txt

+31-8
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,47 @@ if(WITH_BLOCKS_RUNTIME)
109109
SYSTEM BEFORE PRIVATE
110110
"${WITH_BLOCKS_RUNTIME}")
111111
endif()
112-
# TODO(compnerd) make this portable
113-
target_compile_options(dispatch PRIVATE -fno-exceptions)
112+
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
113+
target_compile_options(dispatch PRIVATE /EHsc-)
114+
else()
115+
target_compile_options(dispatch PRIVATE -fno-exceptions)
116+
endif()
114117
if(DISPATCH_ENABLE_ASSERTS)
115118
target_compile_definitions(dispatch
116119
PRIVATE
117120
-DDISPATCH_DEBUG=1)
118121
endif()
122+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
123+
target_compile_definitions(dispatch
124+
PRIVATE
125+
-D_CRT_SECURE_NO_WARNINGS)
126+
endif()
119127
if(BSD_OVERLAY_FOUND)
120128
target_compile_options(dispatch
121129
PRIVATE
122130
${BSD_OVERLAY_CFLAGS})
123131
endif()
124-
# FIXME(compnerd) add check for -momit-leaf-frame-pointer?
125-
target_compile_options(dispatch
126-
PRIVATE
127-
-Wall
128-
-fblocks
129-
-momit-leaf-frame-pointer)
132+
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
133+
target_compile_options(dispatch
134+
PRIVATE
135+
/W3)
136+
else()
137+
target_compile_options(dispatch
138+
PRIVATE
139+
-Wall)
140+
endif()
141+
# FIXME(compnerd) add check for -fblocks?
142+
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
143+
target_compile_options(dispatch
144+
PRIVATE
145+
-Xclang -fblocks)
146+
else()
147+
# FIXME(compnerd) add check for -momit-leaf-frame-pointer?
148+
target_compile_options(dispatch
149+
PRIVATE
150+
-fblocks
151+
-momit-leaf-frame-pointer)
152+
endif()
130153
if(BSD_OVERLAY_FOUND)
131154
target_link_libraries(dispatch PRIVATE ${BSD_OVERLAY_LDFLAGS})
132155
endif()

0 commit comments

Comments
 (0)