Skip to content

Commit 291f34d

Browse files
authored
Merge pull request #283 from dgrove-oss/cmake-extended-warnings
Enable additional compiler warnings for CMake build
2 parents 4e0c302 + 0652ef8 commit 291f34d

File tree

3 files changed

+104
-14
lines changed

3 files changed

+104
-14
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ set(WITH_BLOCKS_RUNTIME "" CACHE PATH "Path to blocks runtime")
2626

2727
include(DispatchAppleOptions)
2828

29+
include(DispatchCompilerWarnings)
30+
dispatch_common_warnings()
31+
2932
option(ENABLE_DISPATCH_INIT_CONSTRUCTOR "enable libdispatch_init as a constructor" ON)
3033
set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})
3134

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
3+
# TODO: someone needs to provide the msvc equivalent warning flags
4+
macro(dispatch_common_warnings)
5+
endmacro()
6+
else()
7+
macro(dispatch_common_warnings)
8+
add_compile_options(-Werror)
9+
add_compile_options(-Wall)
10+
add_compile_options(-Wextra)
11+
add_compile_options(-Wno-unknown-warning-option)
12+
add_compile_options(-Wno-trigraphs)
13+
add_compile_options(-Wmissing-field-initializers)
14+
add_compile_options(-Wmissing-prototypes)
15+
add_compile_options(-Wdocumentation)
16+
add_compile_options(-Wunreachable-code)
17+
add_compile_options(-Wmissing-braces)
18+
add_compile_options(-Wparentheses)
19+
add_compile_options(-Wswitch)
20+
add_compile_options(-Wunused-function)
21+
add_compile_options(-Wunused-label)
22+
add_compile_options(-Wunused-parameter)
23+
add_compile_options(-Wunused-variable)
24+
add_compile_options(-Wunused-value)
25+
add_compile_options(-Wempty-body)
26+
add_compile_options(-Wuninitialized)
27+
add_compile_options(-Wunknown-pragmas)
28+
add_compile_options(-Wshadow)
29+
add_compile_options(-Wno-four-char-constants)
30+
add_compile_options(-Wconversion)
31+
add_compile_options(-Wconstant-conversion)
32+
add_compile_options(-Wint-conversion)
33+
add_compile_options(-Wbool-conversion)
34+
add_compile_options(-Wenum-conversion)
35+
add_compile_options(-Wassign-enum)
36+
add_compile_options(-Wsign-compare)
37+
add_compile_options(-Wshorten-64-to-32)
38+
add_compile_options(-Wpointer-sign)
39+
add_compile_options(-Wnewline-eof)
40+
add_compile_options(-Wdeprecated-declarations)
41+
add_compile_options(-Wsign-conversion)
42+
add_compile_options(-Winfinite-recursion)
43+
add_compile_options(-Warray-bounds-pointer-arithmetic)
44+
add_compile_options(-Watomic-properties)
45+
add_compile_options(-Wcomma)
46+
add_compile_options(-Wconditional-uninitialized)
47+
add_compile_options(-Wcovered-switch-default)
48+
add_compile_options(-Wdate-time)
49+
add_compile_options(-Wdeprecated)
50+
add_compile_options(-Wdouble-promotion)
51+
add_compile_options(-Wduplicate-enum)
52+
add_compile_options(-Wexpansion-to-defined)
53+
add_compile_options(-Wfloat-equal)
54+
add_compile_options(-Widiomatic-parentheses)
55+
add_compile_options(-Wignored-qualifiers)
56+
add_compile_options(-Wimplicit-fallthrough)
57+
add_compile_options(-Wnullable-to-nonnull-conversion)
58+
add_compile_options(-Wobjc-interface-ivars)
59+
add_compile_options(-Wover-aligned)
60+
add_compile_options(-Wpacked)
61+
add_compile_options(-Wpointer-arith)
62+
add_compile_options(-Wselector)
63+
add_compile_options(-Wstatic-in-inline)
64+
add_compile_options(-Wsuper-class-method-mismatch)
65+
add_compile_options(-Wswitch-enum)
66+
add_compile_options(-Wtautological-compare)
67+
add_compile_options(-Wunguarded-availability)
68+
add_compile_options(-Wunused)
69+
add_compile_options(-Wno-disabled-macro-expansion)
70+
add_compile_options(-Wno-pedantic)
71+
add_compile_options(-Wno-bad-function-cast)
72+
add_compile_options(-Wno-c++-compat)
73+
add_compile_options(-Wno-c++98-compat)
74+
add_compile_options(-Wno-c++98-compat-pedantic)
75+
add_compile_options(-Wno-cast-align)
76+
add_compile_options(-Wno-cast-qual)
77+
add_compile_options(-Wno-documentation-unknown-command)
78+
add_compile_options(-Wno-format-nonliteral)
79+
add_compile_options(-Wno-missing-variable-declarations)
80+
add_compile_options(-Wno-old-style-cast)
81+
add_compile_options(-Wno-padded)
82+
add_compile_options(-Wno-reserved-id-macro)
83+
add_compile_options(-Wno-shift-sign-overflow)
84+
add_compile_options(-Wno-undef)
85+
add_compile_options(-Wno-unreachable-code-aggressive)
86+
add_compile_options(-Wno-unused-macros)
87+
add_compile_options(-Wno-used-but-marked-unused)
88+
add_compile_options(-Wno-vla)
89+
endmacro()
90+
endif()

tests/CMakeLists.txt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if(ENABLE_SWIFT)
5959
endif()
6060

6161
function(add_unit_test name)
62-
set(options DISABLED_TEST)
62+
set(options DISABLED_TEST;NO_BSD_OVERLAY)
6363
set(single_value_args)
6464
set(multiple_value_args SOURCES)
6565
cmake_parse_arguments(AUT "${options}" "${single_value_args}" "${multiple_value_args}" ${ARGN})
@@ -84,7 +84,7 @@ function(add_unit_test name)
8484
SYSTEM BEFORE PRIVATE
8585
"${WITH_BLOCKS_RUNTIME}")
8686
endif()
87-
if(BSD_OVERLAY_FOUND)
87+
if(BSD_OVERLAY_FOUND AND NOT AUT_NO_BSD_OVERLAY)
8888
target_compile_options(${name}
8989
PRIVATE
9090
${BSD_OVERLAY_CFLAGS})
@@ -96,7 +96,7 @@ function(add_unit_test name)
9696
if(WITH_BLOCKS_RUNTIME)
9797
target_link_libraries(${name} PRIVATE BlocksRuntime)
9898
endif()
99-
if(BSD_OVERLAY_FOUND)
99+
if(BSD_OVERLAY_FOUND AND NOT AUT_NO_BSD_OVERLAY)
100100
target_link_libraries(${name}
101101
PRIVATE
102102
${BSD_OVERLAY_LDFLAGS})
@@ -122,10 +122,10 @@ function(add_unit_test name)
122122
endif()
123123
endfunction()
124124

125+
# Tests that reliably pass on all platforms
125126
set(DISPATCH_C_TESTS
126127
apply
127128
api
128-
c99
129129
debug
130130
queue_finalizer
131131
group
@@ -143,11 +143,9 @@ set(DISPATCH_C_TESTS
143143
data
144144
io_net
145145
select)
146-
set(DISPATCH_CPP_TESTS
147-
plusplus)
148146

149-
# Tests that usually pass, but occasionally fail
150-
# and are therefore not suitable for general CI usage.
147+
# Tests that usually pass, but occasionally fail.
148+
# Excluded by default for purposes of Swift CI
151149
if(EXTENDED_TEST_SUITE)
152150
list(APPEND DISPATCH_C_TESTS
153151
priority
@@ -165,7 +163,7 @@ if(EXTENDED_TEST_SUITE)
165163
target_compile_options(dispatch_priority2 PRIVATE -DUSE_SET_TARGET_QUEUE=1)
166164
endif()
167165

168-
# Tests for platform-specific functionality
166+
# add C tests for platform-specific functionality when applicable
169167
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
170168
list(APPEND DISPATCH_C_TESTS
171169
deadname
@@ -179,11 +177,10 @@ foreach(test ${DISPATCH_C_TESTS})
179177
SOURCES
180178
dispatch_${test}.c)
181179
endforeach()
182-
foreach(test ${DISPATCH_CPP_TESTS})
183-
add_unit_test(dispatch_${test}
184-
SOURCES
185-
dispatch_${test}.cpp)
186-
endforeach()
180+
181+
# test dispatch API for various C/CXX language variants
182+
add_unit_test(dispatch_c99 NO_BSD_OVERLAY SOURCES dispatch_c99.c)
183+
add_unit_test(dispatch_plusplus SOURCES dispatch_plusplus.cpp)
187184

188185
# test-specific link options
189186
target_link_libraries(dispatch_group PRIVATE m)

0 commit comments

Comments
 (0)