Add an option to treat warnings as errors

pull/4509/head
U-DESKTOP-0R560PH\George 2022-04-30 08:08:34 -07:00
parent 461370946c
commit 694dc8a0c3
3 changed files with 24 additions and 14 deletions

View File

@ -95,7 +95,8 @@ The cmake-build-environment provides options to configure the build. The followi
- **ASSIMP_BUILD_SAMPLES ( default OFF )**: If the official samples are built as well (needs Glut). - **ASSIMP_BUILD_SAMPLES ( default OFF )**: If the official samples are built as well (needs Glut).
- **ASSIMP_BUILD_TESTS ( default ON )**: If the test suite for Assimp is built in addition to the library. - **ASSIMP_BUILD_TESTS ( default ON )**: If the test suite for Assimp is built in addition to the library.
- **ASSIMP_COVERALLS ( default OFF )**: Enable this to measure test coverage. - **ASSIMP_COVERALLS ( default OFF )**: Enable this to measure test coverage.
- **ASSIMP_ERROR_MAX( default OFF)**: Enable all warnings. - **ASSIMP_WARNINGS_AS_ERRORS( default OFF)**: Treat all warnings as errors.
- **ASSIMP_WARNINGS_MAX( default OFF)**: Enable all warnings.
- **ASSIMP_WERROR( default OFF )**: Treat warnings as errors. - **ASSIMP_WERROR( default OFF )**: Treat warnings as errors.
- **ASSIMP_ASAN ( default OFF )**: Enable AddressSanitizer. - **ASSIMP_ASAN ( default OFF )**: Enable AddressSanitizer.
- **ASSIMP_UBSAN ( default OFF )**: Enable Undefined Behavior sanitizer. - **ASSIMP_UBSAN ( default OFF )**: Enable Undefined Behavior sanitizer.

View File

@ -108,7 +108,11 @@ OPTION( ASSIMP_INSTALL
"Disable this if you want to use assimp as a submodule." "Disable this if you want to use assimp as a submodule."
ON ON
) )
OPTION ( ASSIMP_ERROR_MAX OPTION ( ASSIMP_WARNINGS_AS_ERRORS
"Treat all warnings as errors."
OFF
)
OPTION ( ASSIMP_WARNINGS_MAX
"Enable all warnings." "Enable all warnings."
OFF OFF
) )
@ -146,12 +150,10 @@ IF (WIN32)
# Multibyte character set is deprecated since at least MSVC2015 (possibly earlier) # Multibyte character set is deprecated since at least MSVC2015 (possibly earlier)
ADD_DEFINITIONS( -DUNICODE -D_UNICODE ) ADD_DEFINITIONS( -DUNICODE -D_UNICODE )
ENDIF() ENDIF()
# Link statically against c/c++ lib to avoid missing redistriburable such as # Link statically against c/c++ lib to avoid missing redistriburable such as
# "VCRUNTIME140.dll not found. Try reinstalling the app.", but give users # "VCRUNTIME140.dll not found. Try reinstalling the app.", but give users
# a choice to opt for the shared runtime if they want. # a choice to opt for the shared runtime if they want.
option(USE_STATIC_CRT "Link against the static runtime libraries." OFF) option(USE_STATIC_CRT "Link against the static runtime libraries." OFF)
# The CMAKE_CXX_FLAGS vars can be overriden by some Visual Studio generators, so we use an alternative # The CMAKE_CXX_FLAGS vars can be overriden by some Visual Studio generators, so we use an alternative
# global method here: # global method here:
if (${USE_STATIC_CRT}) if (${USE_STATIC_CRT})
@ -324,13 +326,26 @@ IF (ASSIMP_COVERALLS)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
ENDIF() ENDIF()
IF (ASSIMP_ERROR_MAX) IF (ASSIMP_WARNINGS_AS_ERRORS)
MESSAGE(STATUS "Treating all warnings as errors (for assimp library only)")
set(ASSIMP_ERROR_MAX ON)
IF (MSVC)
# TARGET_COMPILE_OPTIONS(assimp PRIVATE /WX)
# TARGET_COMPILE_OPTIONS(assimp_cmd PRIVATE /WX)
ADD_COMPILE_OPTIONS(/WX)
ELSE()
# TARGET_COMPILE_OPTIONS(assimp PRIVATE -Werror)
# TARGET_COMPILE_OPTIONS(assimp_cmd PRIVATE -Werror)
ADD_COMPILE_OPTIONS(-Werror)
ENDIF()
ENDIF()
IF (ASSIMP_WARNINGS_MAX)
MESSAGE(STATUS "Turning on all warnings") MESSAGE(STATUS "Turning on all warnings")
IF (MSVC) IF (MSVC)
ADD_COMPILE_OPTIONS(/W4) # NB: there is a /Wall option, pedantic mode ADD_COMPILE_OPTIONS(/W4) # NB: there is a /Wall option, pedantic mode
ELSE() ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") ADD_COMPILE_OPTIONS(-Wall)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
ENDIF() ENDIF()
ENDIF() ENDIF()
@ -694,6 +709,7 @@ ENDIF()
# Main assimp code # Main assimp code
ADD_SUBDIRECTORY( code/ ) ADD_SUBDIRECTORY( code/ )
IF ( ASSIMP_BUILD_ASSIMP_TOOLS ) IF ( ASSIMP_BUILD_ASSIMP_TOOLS )
# The viewer for windows only # The viewer for windows only
IF (WIN32) IF (WIN32)

View File

@ -1179,13 +1179,6 @@ ADD_LIBRARY(assimp::assimp ALIAS assimp)
TARGET_USE_COMMON_OUTPUT_DIRECTORY(assimp) TARGET_USE_COMMON_OUTPUT_DIRECTORY(assimp)
# enable warnings as errors ########################################
IF (MSVC)
TARGET_COMPILE_OPTIONS(assimp PRIVATE /WX)
ELSE()
TARGET_COMPILE_OPTIONS(assimp PRIVATE -Werror)
ENDIF()
# adds C_FLAGS required to compile zip.c on old GCC 4.x compiler # adds C_FLAGS required to compile zip.c on old GCC 4.x compiler
TARGET_COMPILE_FEATURES(assimp PRIVATE c_std_99) TARGET_COMPILE_FEATURES(assimp PRIVATE c_std_99)