CMake: Add USE_WCONVERSION option

Makes it easier to test with -Wconversion, e.g. in Jenkins.

For now disable -Wsign-conversion. That is the default in g++,
but not clang++. Once we have fixed all -Wsign-conversion
warnings, we can enable it for both.

For now disable -Wenum-enum-conversion. Only present in clang++.
Not clear whether cleaning those up will be worth the effort.

Disable -ferror-limit in clang++. This ensures that it always
displays all errors.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
(cherry picked from commit 6e7a98b5f4)
This commit is contained in:
Frank Lichtenheld
2023-10-17 15:08:34 +02:00
committed by Yuriy Darnobyt
parent 53c35b1013
commit 3bd3915d0a

View File

@@ -10,6 +10,7 @@ set(DEP_DIR ${CORE_DIR}/../deps CACHE PATH "Dependencies")
option(USE_MBEDTLS "Use mbed TLS instead of OpenSSL")
option(USE_WERROR "Treat compiler warnings as errors (-Werror)")
option(USE_WCONVERSION "Enable -Wconversion")
if (DEFINED ENV{DEP_DIR})
message("Overriding DEP_DIR setting with environment variable $ENV{DEP_DIR}")
@@ -126,10 +127,17 @@ function(add_core_dependencies target)
# target_compile_options(${target} PRIVATE /W4)
else()
target_compile_options(${target} PRIVATE -Wall -Wsign-compare)
if (USE_WCONVERSION)
target_compile_options(${target} PRIVATE -Wconversion -Wno-sign-conversion)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# disable noisy warnings
target_compile_options(${target} PRIVATE -Wno-maybe-uninitialized)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# display all warnings
target_compile_options(${target} PRIVATE -ferror-limit=0 -Wno-enum-enum-conversion)
endif()
endif()
endfunction()