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.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 08f6fc1..755f3c6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -154,6 +154,10 @@
check_include_files("objc/objc-internal.h" HAVE_OBJC)
check_library_exists(pthread sem_init "" USE_POSIX_SEM)
+if(CMAKE_SYSTEM_NAME STREQUAL Windows)
+ add_definitions(-DTARGET_OS_WIN32)
+ add_definitions(-DUSE_WIN32_SEM)
+endif()
check_symbol_exists(CLOCK_UPTIME "time.h" HAVE_DECL_CLOCK_UPTIME)
check_symbol_exists(CLOCK_UPTIME_FAST "time.h" HAVE_DECL_CLOCK_UPTIME_FAST)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 113ff4e..75c7266 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -72,24 +72,47 @@
SYSTEM BEFORE PRIVATE
"${WITH_BLOCKS_RUNTIME}")
endif()
-# TODO(compnerd) make this portable
-target_compile_options(dispatch PRIVATE -fno-exceptions)
+if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
+ target_compile_options(dispatch PRIVATE /EHsc-)
+else()
+ target_compile_options(dispatch PRIVATE -fno-exceptions)
+endif()
if(DISPATCH_ENABLE_ASSERTS)
target_compile_definitions(dispatch
PRIVATE
-DDISPATCH_DEBUG=1)
endif()
+if(CMAKE_SYSTEM_NAME STREQUAL Windows)
+ target_compile_definitions(dispatch
+ PRIVATE
+ -D_CRT_SECURE_NO_WARNINGS)
+endif()
if(BSD_OVERLAY_FOUND)
target_compile_options(dispatch
PRIVATE
${BSD_OVERLAY_CFLAGS})
endif()
-# FIXME(compnerd) add check for -momit-leaf-frame-pointer?
-target_compile_options(dispatch
- PRIVATE
- -Wall
- -fblocks
- -momit-leaf-frame-pointer)
+if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
+ target_compile_options(dispatch
+ PRIVATE
+ /W3)
+else()
+ target_compile_options(dispatch
+ PRIVATE
+ -Wall)
+endif()
+# FIXME(compnerd) add check for -fblocks?
+if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
+ target_compile_options(dispatch
+ PRIVATE
+ -Xclang -fblocks)
+else()
+ # FIXME(compnerd) add check for -momit-leaf-frame-pointer?
+ target_compile_options(dispatch
+ PRIVATE
+ -fblocks
+ -momit-leaf-frame-pointer)
+endif()
if(BSD_OVERLAY_FOUND)
target_link_libraries(dispatch PRIVATE ${BSD_OVERLAY_LDFLAGS})
endif()