浏览代码

ENH: Superbuild - When Gcc is used - Compiler flags are automatically set.

The following flags are added:

-fdiagnostics-show-option: This option instructs the diagnostic
machinery to add text to each diagnostic emitted, which indicates
which command line option directly controls that diagnostic, when
such an option is known to the diagnostic machinery.

-Wall:This enables all the warnings about constructions that some users consider questionable.
See http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options

-Wextra: This enables some extra warning flags that are not enabled by -Wall.
See http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options

-Wpointer-arith: Warn about anything that depends on the “size of” a
function type or of void. GNU C assigns these types a size of 1,
for convenience in calculations with void * pointers and pointers
to functions. In C++, warn also when an arithmetic operation
involves NULL. This warning is also enabled by -pedantic

-Winvalid-pch: Warn if a precompiled header (see Precompiled Headers) is found in
 the search path but can't be used.

-Wcast-align: Warn whenever a pointer is cast such that the required
alignment of the target is increased. For example, warn if a char *
is cast to an int * on machines where integers can only be accessed
at two- or four-byte boundaries.

-Wwrite-strings: When compiling C, give string constants the type
const char[length] so that copying the address of one into a
non-const char * pointer will get a warning. These warnings will
help you find at compile time code that can try to write into a
string constant, but only if you have been very careful about
using const in declarations and prototypes. Otherwise, it will
just be a nuisance. This is why we did not make -Wall request
these warnings.
When compiling C++, warn about the deprecated conversion from
string literals to char *. This warning is enabled by
default for C++ programs.

-fstack-protector-all: Emit extra code to check for buffer overflows,
such as stack smashing attacks. This is done by adding a guard
variable to functions with vulnerable objects. This includes
functions that call alloca, and functions with buffers larger
than 8 bytes. The guards are initialized when a function is entered
and then checked when the function exits. If a guard check fails,
an error message is printed and the program exits.
Like -fstack-protector except that all functions are protected.

-D_FORTIFY_SOURCE=2: See http://en.wikipedia.org/wiki/Exec_Shield

-Woverloaded-virtual: Warn when a function declaration hides virtual
functions from a base class.
See http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/C---Dialect-Options.html#C++%20Dialect%20Options

-Wstrict-null-sentinel: Warn also about the use of an uncasted NULL as sentinel.
See http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options

-Wsign-promo: Warn when overload resolution chooses a promotion from
unsigned or enumerated type to a signed type, over a conversion to
an unsigned type of the same size

The following one will be added later - Let's wati pythonQt is in it's dedicated
repository ... too verbose for the moment.

-Wold-style-cast: Warn if an old-style (C-style) cast to a non-void type is used within a C++ program.
The new-style casts (`dynamic_cast', `static_cast', `reinterpret_cast', and `const_cast') are less vulnerable
to unintended effects and much easier to search for.

Since Qt is not compliant .. and the output is way too verbose.
The following one are not added:
 -Wsign-conversion
 -Wconversion
Jean-Christophe Fillion-Robin 15 年之前
父节点
当前提交
a6f66c218d
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      CMakeLists.txt

+ 6 - 0
CMakeLists.txt

@@ -240,6 +240,12 @@ ENDIF()
 SET(CTK_C_FLAGS "${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}")
 SET(CTK_CXX_FLAGS "${VISIBILITY_CXX_FLAGS} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}")
 
+IF(CMAKE_CXX_COMPILER_ID AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
+  SET(cflags "-fdiagnostics-show-option -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -fstack-protector-all -D_FORTIFY_SOURCE=2")
+  SET(CTK_C_FLAGS "${cflags} ${CTK_C_FLAGS}")
+  SET(CTK_CXX_FLAGS "${cflags} -Woverloaded-virtual -Wold-style-cast -Wstrict-null-sentinel -Wsign-promo ${CTK_CXX_FLAGS}")
+ENDIF()
+
 #-----------------------------------------------------------------------------
 # QT
 #