Treat warnings as errors in CI builds

The CMake files now add "-Werror"/"/WX" if the "WERROR" CMake variable
is true.  By default it is not; the CI builds set this.

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2019-06-05 12:13:10 +02:00 committed by eboasson
parent 32b683bf37
commit f6fc1751e9
3 changed files with 29 additions and 11 deletions

View file

@ -164,6 +164,7 @@ script:
-DCMAKE_INSTALL_PREFIX=$(pwd)/install
-DUSE_SANITIZER=${ASAN}
-DBUILD_TESTING=on
-DWERROR=on
-G "${GENERATOR}" ../src
- ${SCAN_BUILD} cmake --build . --config ${BUILD_TYPE} --target install
- CYCLONEDDS_URI='<CycloneDDS><DDSI2E><Internal><EnableExpensiveChecks>all</EnableExpensiveChecks></Internal></DDSI2E></CycloneDDS>' ctest -T test -C ${BUILD_TYPE}

View file

@ -36,7 +36,7 @@ build_script:
- mkdir build
- cd build
- conan install -s arch=%ARCH% -s build_type=%CONFIGURATION% ..
- cmake -DBUILD_TESTING=on -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_INSTALL_PREFIX=%CD%/install -G "%GENERATOR%" ../src
- cmake -DBUILD_TESTING=on -DWERROR=ON -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_INSTALL_PREFIX=%CD%/install -G "%GENERATOR%" ../src
- cmake --build . --config %CONFIGURATION% --target install -- /maxcpucount
- cd install/share/CycloneDDS/examples/helloworld
- mkdir build

View file

@ -22,6 +22,11 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# By default don't treat warnings as errors, else anyone building it with a different compiler that
# just happens to generate a warning, as well as anyone adding or modifying something and making a
# small mistake would run into errors. CI builds can be configured differently.
option(WERROR "Treat compiler warnings as errors" OFF)
FUNCTION(PREPEND var prefix)
SET(listVar "")
FOREACH(f ${ARGN})
@ -86,18 +91,30 @@ endif()
# Set reasonably strict warning options for clang, gcc, msvc
# Enable coloured ouput if Ninja is used for building
if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_C_COMPILER_ID} STREQUAL "AppleClang")
add_definitions(-Wall -Wextra -Wconversion -Wunused -Wmissing-prototypes)
if(${CMAKE_GENERATOR} STREQUAL "Ninja")
add_definitions(-Xclang -fcolor-diagnostics)
if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
#message(STATUS clang)
add_compile_options(-Wall -Wextra -Wconversion -Wunused -Wmissing-prototypes)
if(${WERROR})
add_compile_options(-Werror)
endif()
elseif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
add_definitions(-Wall -Wextra -Wconversion -Wmissing-prototypes)
if(${CMAKE_GENERATOR} STREQUAL "Ninja")
add_definitions(-fdiagnostics-color=always)
if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
add_compile_options(-Xclang -fcolor-diagnostics)
endif()
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
#message(STATUS gcc)
add_compile_options(-Wall -Wextra -Wconversion -Wmissing-prototypes)
if(${WERROR})
add_compile_options(-Werror)
endif()
if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
add_compile_options(-fdiagnostics-color=always)
endif()
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
#message(STATUS msvc)
add_compile_options(/W3)
if(${WERROR})
add_compile_options(/WX)
endif()
elseif(${CMAKE_C_COMPILER_ID} STREQUAL "MSVC")
add_definitions(/W3)
endif()
# I don't know how to enable warnings properly so that it ends up in Xcode projects as well