Enable additional compiler warnings for CMake build

1. add a CMake module to define additional warning flags to enable
   when compiling dispatch.

2. enable the additional warning flags by default for CMake

3. match autotools behavior of not including the BSD_OVERLAY
   when compiling the dispatch_c99 test case. This avoids
   a warning about __printflike being redefined when compiling
   this test case with the expanded set of warning flags.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f6b078e..1f34e51 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,9 @@
 
 include(DispatchAppleOptions)
 
+include(DispatchCompilerWarnings)
+dispatch_common_warnings()
+
 option(ENABLE_DISPATCH_INIT_CONSTRUCTOR "enable libdispatch_init as a constructor" ON)
 set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})
 
diff --git a/cmake/modules/DispatchCompilerWarnings.cmake b/cmake/modules/DispatchCompilerWarnings.cmake
new file mode 100644
index 0000000..2ae27cd
--- /dev/null
+++ b/cmake/modules/DispatchCompilerWarnings.cmake
@@ -0,0 +1,90 @@
+
+if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
+  # TODO: someone needs to provide the msvc equivalent warning flags
+  macro(dispatch_common_warnings)
+  endmacro()
+else()
+  macro(dispatch_common_warnings)
+	add_compile_options(-Werror)
+	add_compile_options(-Wall)
+	add_compile_options(-Wextra)
+	add_compile_options(-Wno-unknown-warning-option)
+	add_compile_options(-Wno-trigraphs)
+	add_compile_options(-Wmissing-field-initializers)
+	add_compile_options(-Wmissing-prototypes)
+	add_compile_options(-Wdocumentation)
+	add_compile_options(-Wunreachable-code)
+	add_compile_options(-Wmissing-braces)
+	add_compile_options(-Wparentheses)
+	add_compile_options(-Wswitch)
+	add_compile_options(-Wunused-function)
+	add_compile_options(-Wunused-label)
+	add_compile_options(-Wunused-parameter)
+	add_compile_options(-Wunused-variable)
+	add_compile_options(-Wunused-value)
+	add_compile_options(-Wempty-body)
+	add_compile_options(-Wuninitialized)
+	add_compile_options(-Wunknown-pragmas)
+	add_compile_options(-Wshadow)
+	add_compile_options(-Wno-four-char-constants)
+	add_compile_options(-Wconversion)
+	add_compile_options(-Wconstant-conversion)
+	add_compile_options(-Wint-conversion)
+	add_compile_options(-Wbool-conversion)
+	add_compile_options(-Wenum-conversion)
+	add_compile_options(-Wassign-enum)
+	add_compile_options(-Wsign-compare)
+	add_compile_options(-Wshorten-64-to-32)
+	add_compile_options(-Wpointer-sign)
+	add_compile_options(-Wnewline-eof)
+	add_compile_options(-Wdeprecated-declarations)
+	add_compile_options(-Wsign-conversion)
+	add_compile_options(-Winfinite-recursion)
+	add_compile_options(-Warray-bounds-pointer-arithmetic)
+	add_compile_options(-Watomic-properties)
+	add_compile_options(-Wcomma)
+	add_compile_options(-Wconditional-uninitialized)
+	add_compile_options(-Wcovered-switch-default)
+	add_compile_options(-Wdate-time)
+	add_compile_options(-Wdeprecated)
+	add_compile_options(-Wdouble-promotion)
+	add_compile_options(-Wduplicate-enum)
+	add_compile_options(-Wexpansion-to-defined)
+	add_compile_options(-Wfloat-equal)
+	add_compile_options(-Widiomatic-parentheses)
+	add_compile_options(-Wignored-qualifiers)
+	add_compile_options(-Wimplicit-fallthrough)
+	add_compile_options(-Wnullable-to-nonnull-conversion)
+	add_compile_options(-Wobjc-interface-ivars)
+	add_compile_options(-Wover-aligned)
+	add_compile_options(-Wpacked)
+	add_compile_options(-Wpointer-arith)
+	add_compile_options(-Wselector)
+	add_compile_options(-Wstatic-in-inline)
+	add_compile_options(-Wsuper-class-method-mismatch)
+	add_compile_options(-Wswitch-enum)
+	add_compile_options(-Wtautological-compare)
+	add_compile_options(-Wunguarded-availability)
+	add_compile_options(-Wunused)
+	add_compile_options(-Wno-disabled-macro-expansion)
+	add_compile_options(-Wno-pedantic)
+	add_compile_options(-Wno-bad-function-cast)
+	add_compile_options(-Wno-c++-compat)
+	add_compile_options(-Wno-c++98-compat)
+	add_compile_options(-Wno-c++98-compat-pedantic)
+	add_compile_options(-Wno-cast-align)
+	add_compile_options(-Wno-cast-qual)
+	add_compile_options(-Wno-documentation-unknown-command)
+	add_compile_options(-Wno-format-nonliteral)
+	add_compile_options(-Wno-missing-variable-declarations)
+	add_compile_options(-Wno-old-style-cast)
+	add_compile_options(-Wno-padded)
+	add_compile_options(-Wno-reserved-id-macro)
+	add_compile_options(-Wno-shift-sign-overflow)
+	add_compile_options(-Wno-undef)
+	add_compile_options(-Wno-unreachable-code-aggressive)
+	add_compile_options(-Wno-unused-macros)
+	add_compile_options(-Wno-used-but-marked-unused)
+	add_compile_options(-Wno-vla)
+  endmacro()
+endif()
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 3ecd069..0f8628f 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -59,7 +59,7 @@
 endif()
 
 function(add_unit_test name)
-  set(options DISABLED_TEST)
+  set(options DISABLED_TEST;NO_BSD_OVERLAY)
   set(single_value_args)
   set(multiple_value_args SOURCES)
   cmake_parse_arguments(AUT "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})
@@ -84,7 +84,7 @@
                                SYSTEM BEFORE PRIVATE
                                  "${WITH_BLOCKS_RUNTIME}")
   endif()
-  if(BSD_OVERLAY_FOUND)
+  if(BSD_OVERLAY_FOUND AND NOT AUT_NO_BSD_OVERLAY)
     target_compile_options(${name}
                            PRIVATE
                              ${BSD_OVERLAY_CFLAGS})
@@ -96,7 +96,7 @@
   if(WITH_BLOCKS_RUNTIME)
     target_link_libraries(${name} PRIVATE BlocksRuntime)
   endif()
-  if(BSD_OVERLAY_FOUND)
+  if(BSD_OVERLAY_FOUND AND NOT AUT_NO_BSD_OVERLAY)
     target_link_libraries(${name}
                           PRIVATE
                             ${BSD_OVERLAY_LDFLAGS})
@@ -122,10 +122,10 @@
   endif()
 endfunction()
 
+# Tests that reliably pass on all platforms
 set(DISPATCH_C_TESTS
     apply
     api
-    c99
     debug
     queue_finalizer
     group
@@ -143,11 +143,9 @@
     data
     io_net
     select)
-set(DISPATCH_CPP_TESTS
-    plusplus)
 
-# Tests that usually pass, but occasionally fail
-# and are therefore not suitable for general CI usage.
+# Tests that usually pass, but occasionally fail.
+# Excluded by default for purposes of Swift CI
 if(EXTENDED_TEST_SUITE)
   list(APPEND DISPATCH_C_TESTS
 	priority
@@ -165,7 +163,7 @@
   target_compile_options(dispatch_priority2 PRIVATE -DUSE_SET_TARGET_QUEUE=1)
 endif()
 
-# Tests for platform-specific functionality
+# add C tests for platform-specific functionality when applicable
 if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
   list(APPEND DISPATCH_C_TESTS
 	deadname
@@ -179,11 +177,10 @@
                 SOURCES
                   dispatch_${test}.c)
 endforeach()
-foreach(test ${DISPATCH_CPP_TESTS})
-  add_unit_test(dispatch_${test}
-                SOURCES
-                  dispatch_${test}.cpp)
-endforeach()
+
+# test dispatch API for various C/CXX language variants
+add_unit_test(dispatch_c99 NO_BSD_OVERLAY SOURCES dispatch_c99.c)
+add_unit_test(dispatch_plusplus SOURCES dispatch_plusplus.cpp)
 
 # test-specific link options
 target_link_libraries(dispatch_group PRIVATE m)