Skip to content

Commit 1122e85

Browse files
committed
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.
1 parent dcbbf17 commit 1122e85

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
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)

src/CMakeLists.txt

+31-8
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,47 @@ if(WITH_BLOCKS_RUNTIME)
7272
SYSTEM BEFORE PRIVATE
7373
"${WITH_BLOCKS_RUNTIME}")
7474
endif()
75-
# TODO(compnerd) make this portable
76-
target_compile_options(dispatch PRIVATE -fno-exceptions)
75+
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
76+
target_compile_options(dispatch PRIVATE /EHsc-)
77+
else()
78+
target_compile_options(dispatch PRIVATE -fno-exceptions)
79+
endif()
7780
if(DISPATCH_ENABLE_ASSERTS)
7881
target_compile_definitions(dispatch
7982
PRIVATE
8083
-DDISPATCH_DEBUG=1)
8184
endif()
85+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
86+
target_compile_definitions(dispatch
87+
PRIVATE
88+
-D_CRT_SECURE_NO_WARNINGS)
89+
endif()
8290
if(BSD_OVERLAY_FOUND)
8391
target_compile_options(dispatch
8492
PRIVATE
8593
${BSD_OVERLAY_CFLAGS})
8694
endif()
87-
# FIXME(compnerd) add check for -momit-leaf-frame-pointer?
88-
target_compile_options(dispatch
89-
PRIVATE
90-
-Wall
91-
-fblocks
92-
-momit-leaf-frame-pointer)
95+
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
96+
target_compile_options(dispatch
97+
PRIVATE
98+
/W3)
99+
else()
100+
target_compile_options(dispatch
101+
PRIVATE
102+
-Wall)
103+
endif()
104+
# FIXME(compnerd) add check for -fblocks?
105+
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
106+
target_compile_options(dispatch
107+
PRIVATE
108+
-Xclang -fblocks)
109+
else()
110+
# FIXME(compnerd) add check for -momit-leaf-frame-pointer?
111+
target_compile_options(dispatch
112+
PRIVATE
113+
-fblocks
114+
-momit-leaf-frame-pointer)
115+
endif()
93116
if(BSD_OVERLAY_FOUND)
94117
target_link_libraries(dispatch PRIVATE ${BSD_OVERLAY_LDFLAGS})
95118
endif()

0 commit comments

Comments
 (0)