[Piglit] [PATCH 1/2] cmake: Warn when placing declarations after statements.

jfonseca at vmware.com jfonseca at vmware.com
Tue Jan 17 11:29:10 PST 2012


From: José Fonseca <jfonseca at vmware.com>

Unfortunately this will enable the warning even on OS specific directories
will never be built with MSVC, but it looks like the use of this C99 is
actually very scarce, even on those OS specific directories.
---
 CMakeLists.txt |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 179340e..d4b5b2a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,6 +56,14 @@ if (NOT MSVC)
 	IF (CXX_COMPILER_FLAG_WALL)
 		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
 	ENDIF (CXX_COMPILER_FLAG_WALL)
+
+	# Unfortunately MSVC does not support C99.  Among all features enabled
+	# by C99, declarations after statements is the most frequently used.
+	# For portability sake, we request gcc to warn when this is used.
+	CHECK_C_COMPILER_FLAG("-Wall" C_COMPILER_FLAG_WDECL_AFTER_STMT)
+	IF (C_COMPILER_FLAG_WDECL_AFTER_STMT)
+		SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wdeclaration-after-statement")
+	ENDIF (C_COMPILER_FLAG_WDECL_AFTER_STMT)
 else ()
 	# -Wall or (/Wall) is actually supported by MSVC and would be detected
 	# by CHECK_C_COMPILER_FLAG above, but is very pedantic, causing
-- 
1.7.7.3



More information about the Piglit mailing list