Skip to content

Enable additional compiler warnings for CMake build #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ set(WITH_BLOCKS_RUNTIME "" CACHE PATH "Path to blocks runtime")

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})

Expand Down
90 changes: 90 additions & 0 deletions cmake/modules/DispatchCompilerWarnings.cmake
Original file line number Diff line number Diff line change
@@ -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()
25 changes: 11 additions & 14 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if(ENABLE_SWIFT)
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})
Expand All @@ -84,7 +84,7 @@ function(add_unit_test name)
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})
Expand All @@ -96,7 +96,7 @@ function(add_unit_test name)
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})
Expand All @@ -122,10 +122,10 @@ function(add_unit_test name)
endif()
endfunction()

# Tests that reliably pass on all platforms
set(DISPATCH_C_TESTS
apply
api
c99
debug
queue_finalizer
group
Expand All @@ -143,11 +143,9 @@ set(DISPATCH_C_TESTS
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
Expand All @@ -165,7 +163,7 @@ if(EXTENDED_TEST_SUITE)
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
Expand All @@ -179,11 +177,10 @@ foreach(test ${DISPATCH_C_TESTS})
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)
Expand Down