Commit cc9e47c995fc9bb5526f8e83a27c5f2af6a6f6d9

Edward Thomson 2019-06-15T18:51:40

win32: support upgrading warnings to errors (/WX) For MSVC, support warnings as errors by providing the /WX compiler flags. (/WX is the moral equivalent of -Werror.) Disable warnings as errors ass part of xdiff, since it contains warnings. But as a component of git itself, we want to avoid skew and keep our implementation as similar as possible to theirs. We'll work with upstream to fix these issues, but in the meantime, simply let those continue to warn.

diff --git a/cmake/Modules/EnableWarnings.cmake b/cmake/Modules/EnableWarnings.cmake
index 72e1523..b61ed7e 100644
--- a/cmake/Modules/EnableWarnings.cmake
+++ b/cmake/Modules/EnableWarnings.cmake
@@ -7,5 +7,9 @@ MACRO(DISABLE_WARNINGS flag)
 ENDMACRO()
 
 IF(ENABLE_WERROR)
-	ADD_C_FLAG_IF_SUPPORTED(-Werror)
+	IF(MSVC)
+		ADD_COMPILE_OPTIONS(-WX)
+	ELSE()
+		ADD_C_FLAG_IF_SUPPORTED(-Werror)
+	ENDIF()
 ENDIF()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7ab1832..750085b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -314,12 +314,20 @@ ELSE()
 	ENDIF()
 	FILE(GLOB SRC_OS unix/*.c unix/*.h)
 ENDIF()
+
 FILE(GLOB SRC_GIT2 *.c *.h
 	allocators/*.c allocators/*.h
 	streams/*.c streams/*.h
 	transports/*.c transports/*.h
 	xdiff/*.c xdiff/*.h)
 
+# the xdiff dependency is not (yet) warning-free, disable warnings as
+# errors for the xdiff sources until we've sorted them out
+IF(MSVC)
+	SET_SOURCE_FILES_PROPERTIES(xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS -WX-)
+	SET_SOURCE_FILES_PROPERTIES(xdiff/xutils.c PROPERTIES COMPILE_FLAGS -WX-)
+ENDIF()
+
 # Determine architecture of the machine
 IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
 	SET(GIT_ARCH_64 1)