From acc1e4606fa193b3601fd770cb19f6fadbf44b94 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 6 May 2017 18:38:36 -0700 Subject: [PATCH 1/3] guard includes with checks sys/cdefs.h and unistd.h are not always available. We already have checks for these, guard the inclusion appropriately. --- dispatch/dispatch.h | 4 ++++ os/object_private.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/dispatch/dispatch.h b/dispatch/dispatch.h index 585940cc0..a0622e6cb 100644 --- a/dispatch/dispatch.h +++ b/dispatch/dispatch.h @@ -39,13 +39,17 @@ #endif #endif // __APPLE__ +#if HAVE_SYS_CDEFS_H #include +#endif #include #include #include #include #include +#if HAVE_UNISTD_H #include +#endif #include #if defined(__linux__) && defined(__has_feature) diff --git a/os/object_private.h b/os/object_private.h index 36a807cb0..ebaf8549f 100644 --- a/os/object_private.h +++ b/os/object_private.h @@ -27,7 +27,9 @@ #ifndef __OS_OBJECT_PRIVATE__ #define __OS_OBJECT_PRIVATE__ +#if HAVE_SYS_CDEFS_H #include +#endif #include #include From dcbbf17c8a53a60221c6baf5eaa333327af22411 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 6 May 2017 18:40:02 -0700 Subject: [PATCH 2/3] invert Linux handling Rather than checking for non-Linux and including the target specific header, invert the check and include the linux target header if `__linux__` is defined. This makes it easier to target other platforms. --- os/object.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/os/object.h b/os/object.h index b0b47059a..b98a93e57 100644 --- a/os/object.h +++ b/os/object.h @@ -26,10 +26,10 @@ #include #include #endif -#ifndef __linux__ -#include -#else +#ifdef __linux__ #include +#else +#include #endif /*! From 1122e85f598c64d34a3890e326fb2efae62e1c7c Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 6 May 2017 18:48:10 -0700 Subject: [PATCH 3/3] 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. --- CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08f6fc17d..755f3c6c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,6 +154,10 @@ check_include_files("unistd.h" HAVE_UNISTD_H) 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 113ff4e3b..75c72666b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -72,24 +72,47 @@ if(WITH_BLOCKS_RUNTIME) 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()