Skip to content
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

Add an option to treat warnings as errors #4509

Merged
merged 9 commits into from
May 6, 2022
3 changes: 2 additions & 1 deletion Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_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_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_ASAN ( default OFF )**: Enable AddressSanitizer.
- **ASSIMP_UBSAN ( default OFF )**: Enable Undefined Behavior sanitizer.
Expand Down
24 changes: 20 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ OPTION( ASSIMP_INSTALL
"Disable this if you want to use assimp as a submodule."
ON
)
OPTION ( ASSIMP_ERROR_MAX
OPTION ( ASSIMP_WARNINGS_AS_ERRORS
"Treat all warnings as errors."
OFF
kimkulling marked this conversation as resolved.
Show resolved Hide resolved
)
OPTION ( ASSIMP_WARNINGS_MAX
"Enable all warnings."
OFF
)
Expand Down Expand Up @@ -324,13 +328,24 @@ IF (ASSIMP_COVERALLS)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
ENDIF()

IF (ASSIMP_ERROR_MAX)
IF (ASSIMP_WARNINGS_AS_ERRORS)
MESSAGE(STATUS "Treating all warnings as errors (for assimp library only)")
set(ASSIMP_WARNINGS_MAX ON)
IF (MSVC)
TARGET_COMPILE_OPTIONS(assimp PRIVATE /WX)
# ADD_COMPILE_OPTIONS(/WX)
ELSE()
TARGET_COMPILE_OPTIONS(assimp PRIVATE -Werror)
# ADD_COMPILE_OPTIONS(-Werror)
ENDIF()
ENDIF()

IF (ASSIMP_WARNINGS_MAX)
MESSAGE(STATUS "Turning on all warnings")
IF (MSVC)
ADD_COMPILE_OPTIONS(/W4) # NB: there is a /Wall option, pedantic mode
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
ADD_COMPILE_OPTIONS(-Wall)
ENDIF()
ENDIF()

Expand Down Expand Up @@ -694,6 +709,7 @@ ENDIF()

# Main assimp code
ADD_SUBDIRECTORY( code/ )

IF ( ASSIMP_BUILD_ASSIMP_TOOLS )
# The viewer for windows only
IF (WIN32)
Expand Down
7 changes: 0 additions & 7 deletions code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1179,13 +1179,6 @@ ADD_LIBRARY(assimp::assimp ALIAS 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
TARGET_COMPILE_FEATURES(assimp PRIVATE c_std_99)

Expand Down