Enable -Werror build for clang on Circle CI

This commit is contained in:
Sebastian Messmer 2018-10-02 20:51:33 -07:00
parent b66b7bfeb1
commit f4be42d892
5 changed files with 43 additions and 16 deletions

View File

@ -377,17 +377,28 @@ jobs:
BUILD_TYPE: "Release"
CMAKE_FLAGS: ""
RUN_TESTS: true
# clang_werror:
# <<: *job_definition
# environment:
# CC: clang-7
# CXX: clang++-7
# BUILD_TOOLSET: clang
# APT_COMPILER_PACKAGE: clang-7
# CXXFLAGS: "-Werror"
# BUILD_TYPE: "Release"
# CMAKE_FLAGS: ""
# RUN_TESTS: false
clang_werror:
<<: *job_definition
environment:
CC: clang-7
CXX: clang++-7
BUILD_TOOLSET: clang
APT_COMPILER_PACKAGE: clang-7
CXXFLAGS: ""
BUILD_TYPE: "Release"
CMAKE_FLAGS: "-DUSE_WERROR=on"
RUN_TESTS: false
gcc_werror:
<<: *job_definition
environment:
CC: gcc-8
CXX: g++-8
BUILD_TOOLSET: gcc
APT_COMPILER_PACKAGE: "g++-8"
CXXFLAGS: ""
BUILD_TYPE: "Release"
CMAKE_FLAGS: "-DUSE_WERROR=on"
RUN_TESTS: false
gcc_werror:
<<: *job_definition
environment:
@ -484,8 +495,8 @@ workflows:
<<: *enable_for_tags
- clang_7_release:
<<: *enable_for_tags
# - clang_werror:
# <<: *enable_for_tags
- clang_werror:
<<: *enable_for_tags
- gcc_werror:
<<: *enable_for_tags
- no_compatibility:

View File

@ -18,9 +18,13 @@ require_clang_version(4.0)
option(BUILD_TESTING "build test cases" OFF)
option(CRYFS_UPDATE_CHECKS "let cryfs check for updates and security vulnerabilities" ON)
option(DISABLE_OPENMP "allow building without OpenMP libraries. This will cause performance degradations." OFF)
# The following options are helpful for development and/or CI
option(USE_WERROR "build with -Werror flag")
option(USE_CLANG_TIDY "build with clang-tidy checks enabled" OFF)
option(CLANG_TIDY_WARNINGS_AS_ERRORS "treat clang-tidy warnings as errors" OFF)
if (MSVC)
option(DOKAN_PATH "Location of the Dokan library, e.g. C:\\Program Files\\Dokan\\DokanLibrary-1.1.0" "")
endif()

View File

@ -56,12 +56,18 @@ endif()
# Uses: target_enable_style_warnings(buildtarget)
#################################################
function(target_enable_style_warnings TARGET)
# Enable compiler options
if (NOT MSVC)
# TODO Add compiler warnings on MSVC
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# TODO
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wold-style-cast -Wcast-align -Wno-unused-command-line-argument) # TODO consider -Wpedantic -Wchkp -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wundef -Wno-unused -Wno-variadic-macros -Wno-parentheses -fdiagnostics-show-option -Wconversion and others?
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wold-style-cast -Wcast-align) # TODO consider -Wpedantic -Wchkp -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wundef -Wno-unused -Wno-variadic-macros -Wno-parentheses -fdiagnostics-show-option -Wconversion and others?
endif()
if (USE_WERROR)
target_compile_options(${TARGET} PRIVATE -Werror)
endif()
# Enable clang-tidy
if(USE_CLANG_TIDY)
set_target_properties(

View File

@ -97,9 +97,12 @@ namespace {
}
void set_handler(int signum, void(*handler)(int)) {
auto result = signal(signum, handler);
#pragma GCC diagnostic push // SIG_ERR uses old style casts
#pragma GCC diagnostic ignored "-Wold-style-cast"
if (SIG_ERR == result) {
LOG(ERR, "Failed to set signal {} handler. Errno: {}", signum, errno);
}
#pragma GCC diagnostic pop
}
}

View File

@ -57,11 +57,14 @@ namespace cpputils {
if (returncode == -1) {
throw std::runtime_error("Error calling pclose. Errno: " + std::to_string(errno));
}
#pragma GCC diagnostic push // WIFEXITSTATUS / WEXITSTATUS use old style casts
#pragma GCC diagnostic ignored "-Wold-style-cast"
if (!WIFEXITED(returncode)) {
// WEXITSTATUS is only valid if WIFEXITED is 0.
throw std::runtime_error("WIFEXITED returned " + std::to_string(WIFEXITED(returncode)));
}
return WEXITSTATUS(returncode);
#pragma GCC diagnostic pop
}
private: