aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Kniager <jeremyk@lunarg.com>2021-06-10 15:00:11 -0600
committerjeremyk-lunarg <jeremyk@lunarg.com>2021-06-14 10:21:12 -0600
commit0143cbebff88ff1464a4da1ebf1a2f067e8489fa (patch)
treeabae628b783e923751dc5650f39db391ab7a7014
parentac9393317a5cf7b077ff7d40e65c7ab9bc53ce90 (diff)
downloadusermoji-0143cbebff88ff1464a4da1ebf1a2f067e8489fa.tar.xz
build: Add Werror and warning flags to builds
Added the Werror, Wall, and Wextra flags to builds in CMake. Change-Id: I58ff7c7d175b512906141b0e691f42b8eb4bf68f
-rw-r--r--CMakeLists.txt25
1 files changed, 25 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fea45156..90523aeb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -125,10 +125,22 @@ if(APPLE)
set(CMAKE_MACOSX_RPATH 1)
endif()
+option(BUILD_WERROR "Treat compiler warnings as errors" ON)
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
+ if(MAKE_C_COMPILER_ID MATCHES "Clang")
+ set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wno-sign-conversion -Wno-shorten-64-to-32 -Wno-string-conversion -Wno-implicit-in-conversion -Wno-enum-enum-conversion")
+ endif()
+
+ if(BUILD_WERROR)
+ if((CMAKE_COMPILER_IS_GNUCXX AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.3.0)) OR
+ (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0.0)))
+ set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Werror")
+ endif()
+ endif()
+
# For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since there's no consistent way to satisfy
# all compilers until they all accept the C++17 standard
if(CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.1))
@@ -145,6 +157,19 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif()
+elseif(MSVC)
+ if(BUILD_WERROR)
+ add_compile_options("/WX")
+ endif()
+ # Warn about nested declarations
+ add_compile_options("/w34456")
+ # Warn about potentially uninitialized variables
+ add_compile_options("/w34701")
+ add_compile_options("/w34703")
+ # Warn about different indirection types.
+ add_compile_options("/w34057")
+ # Warn about signed/unsigned mismatch.
+ add_compile_options("/w34245")
endif()
# Optional codegen target