Merge lp:~hjd/widelands/compilation-warnings into lp:widelands

Proposed by Hans Joachim Desserud
Status: Merged
Merged at revision: 6480
Proposed branch: lp:~hjd/widelands/compilation-warnings
Merge into: lp:widelands
Diff against target: 52 lines (+19/-9)
1 file modified
CMakeLists.txt (+19/-9)
To merge this branch: bzr merge lp:~hjd/widelands/compilation-warnings
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+141946@code.launchpad.net

Description of the change

Related to the intial investigation of additional warnings in bug 1033615.

* WL_EXTRAWARNINGS doesn't exist anymore. If it is specified, cmake will warn it is an unused parameter. I have the impression very few people are using this, so I would rather move the warnings to the default configuration. I guess it was split out like this because -Wextra used to be extremely noise (several thousand extra lines).

* Warnings are grouped in three categories; generic, extra and gcc. Generic are the base warnings (-Wall -Wextra), extra adds additional warnings and gcc attempts to add warnings only availble in gcc.
Extra doesn't add a lot at the moment, but we might expand this in the future depending on the feedback on the bug report. Gcc has so far only added -Wlogical-op, mainly because it has already found a bug.

It is split this way because if an unknown warning is encountered, none of them is applied. This way, -Wall -Wextra should always be applied, if extra applies we get those warnings too and if it doesn't it will inform the user, and if the gcc warnings applies they are added too. In other words, if some of the extra warnings are not availble due to older compiler version or similar, we will always get a good base set of warnings. One thing I would like to see in the future is some way to check and add warnings individually so we get as many as possible. Maybe we could loop through the parameters sent to the compiler and only keep the ones supported.

This will be a gradual process though, as we figure out which warnings we want to add and which we want to silence. I think this is a good starting point though, and give us something we can build further upon.

I've rebuilt Widelands with both GCC and Clang with this revision, they both behave as expected and I got the same list of warnings as the previous run I uploaded to the warning bug reports.

PS. -Wno-attributes was removed because it didn't have any impact on the outcome. Were these warnings ignored due to false positives in the past?

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

A good idea i think. I merged this and have not seen any problems with building widelands so far. Testing for individual warnings will likely need a script to probe the compiler for what it supports.

-Wno-attributes was added by me IIRC because compilation on old gcc version made some noisy output because we use attribute hot in some places. My memory might fail me though, I am an old man after all.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2012-11-30 18:16:47 +0000
3+++ CMakeLists.txt 2013-01-04 15:56:24 +0000
4@@ -157,8 +157,9 @@
5
6 set (PARAMETER_COMPILERFLAG_OLDSTYLECAST_EXTENDED "-Wold-style-cast -isystem ${Boost_INCLUDE_DIR}")
7 set (PARAMETER_COMPILERFLAG_OLDSTYLECAST "-Wold-style-cast")
8-set (PARAMETER_COMPILERFLAG_GENERICWARNINGS "-Wno-attributes -Wall")
9-set (PARAMETER_COMPILERFLAG_EXTRAWARNINGS "-Wextra -Wsign-promo")
10+set (PARAMETER_COMPILERFLAG_GENERICWARNINGS "-Wall -Wextra")
11+set (PARAMETER_COMPILERFLAG_EXTRAWARNINGS "-Wsign-promo")
12+set (PARAMETER_COMPILERFLAG_GCCWARNINGS "-Wlogical-op")
13 set (PARAMETER_COMPILERFLAG_STRICT "-Werror -Wno-error=old-style-cast -Wno-error=deprecated-declarations -fdiagnostics-show-option")
14 IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
15 include(CheckCXXCompilerFlag) #this include should be safe
16@@ -198,12 +199,21 @@
17 IF (Compiler_generic_warnings_supported)
18 set (WL_COMPILERFLAG_GENERICWARNINGS " ${PARAMETER_COMPILERFLAG_GENERICWARNINGS}") #the space is on purpose!
19 ENDIF (Compiler_generic_warnings_supported)
20- IF (WL_EXTRAWARNINGS)
21- CHECK_CXX_COMPILER_FLAG(${PARAMETER_COMPILERFLAG_EXTRAWARNINGS} Compiler_extra_warnings_supported)
22- IF (Compiler_extra_warnings_supported)
23- set (WL_COMPILERFLAG_EXTRAWARNINGS " ${PARAMETER_COMPILERFLAG_EXTRAWARNINGS}") #the space is on purpose!
24- ENDIF (Compiler_extra_warnings_supported)
25- ENDIF (WL_EXTRAWARNINGS)
26+
27+ CHECK_CXX_COMPILER_FLAG(${PARAMETER_COMPILERFLAG_EXTRAWARNINGS} Compiler_extra_warnings_supported)
28+ IF (Compiler_extra_warnings_supported)
29+ set (WL_COMPILERFLAG_EXTRAWARNINGS " ${PARAMETER_COMPILERFLAG_EXTRAWARNINGS}") #the space is on purpose!
30+ ELSE (Compiler_extra_warnings_supported)
31+ message("Warning: couldn't set the following compiler options: ${PARAMETER_COMPILERFLAG_EXTRAWARNINGS}. Most likely these options are available in a newer release of your compiler.")
32+ ENDIF (Compiler_extra_warnings_supported)
33+
34+ CHECK_CXX_COMPILER_FLAG(${PARAMETER_COMPILERFLAG_GCCWARNINGS} Compiler_gcc_warnings_supported)
35+ IF (Compiler_gcc_warnings_supported)
36+ set (WL_COMPILERFLAG_GCCWARNINGS " ${PARAMETER_COMPILERFLAG_GCCWARNINGS}") #the space is on purpose!
37+ ELSE (Compiler_gcc_warnings_supported)
38+ message("Warning: could not add additional GCC-specific warning options: ${PARAMETER_COMPILERFLAG_GCCWARNINGS}. Most likely you are using a different compiler, like Clang/LLVM.")
39+ ENDIF (Compiler_gcc_warnings_supported)
40+
41
42 IF (WL_STRICT)
43 CHECK_CXX_COMPILER_FLAG(${PARAMETER_COMPILERFLAG_STRICT} Compiler_strict_mode_supported)
44@@ -215,7 +225,7 @@
45 ENDIF (CMAKE_BUILD_TYPE STREQUAL "Debug")
46
47 # CMAKE only defines "-g", but we need -DDEBUG also, and we need -DNOPARACHUTE (for SDL) in Debug
48-set (CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG -DNOPARACHUTE${WL_COMPILERFLAG_OLDSTYLECAST}${WL_COMPILERFLAG_GENERICWARNINGS}${WL_COMPILERFLAG_EXTRAWARNINGS}${WL_COMPILERFLAG_STRICT}" CACHE STRING "Set by widelands CMakeLists.txt" FORCE)
49+set (CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG -DNOPARACHUTE${WL_COMPILERFLAG_OLDSTYLECAST}${WL_COMPILERFLAG_GENERICWARNINGS}${WL_COMPILERFLAG_EXTRAWARNINGS}${WL_COMPILERFLAG_GCCWARNINGS}${WL_COMPILERFLAG_STRICT}" CACHE STRING "Set by widelands CMakeLists.txt" FORCE)
50
51 #This can be removed if no one uses gcc 4.5.1 or 4.5.2 any more
52 IF (CMAKE_COMPILER_IS_GNUCXX)

Subscribers

People subscribed via source and target branches

to status/vote changes: