Skip to content

Commit 2ab4696

Browse files
compnerddas
authored andcommitted
build: improve support for cl-like compilers
Address some of the portability considerations for the build flags. This improves some of the conditions for building for Windows. Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
1 parent 9c8afda commit 2ab4696

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
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)

src/CMakeLists.txt

Lines changed: 31 additions & 8 deletions
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)