cmake: always enable warnings without -Werror

Warnings are useful, let's enable them by default.
This commit is contained in:
Peter Wu 2016-02-16 14:57:05 +01:00
parent a909eb6b23
commit f4b2a4ab00
2 changed files with 8 additions and 5 deletions

View File

@ -285,12 +285,17 @@ if(HAVE_EPOLL AND HAVE_TIMERFD_CREATE)
set(ENABLE_TINY_NGHTTPD 1) set(ENABLE_TINY_NGHTTPD 1)
endif() endif()
set(WARNCFLAGS)
set(WARNCXXFLAGS)
if(ENABLE_WERROR) if(ENABLE_WERROR)
extract_valid_c_flags(WARNCFLAGS -Werror)
extract_valid_c_flags(WARNCXXFLAGS -Werror)
endif()
if(NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC")
# For C compiler # For C compiler
extract_valid_c_flags(WARNCFLAGS extract_valid_c_flags(WARNCFLAGS
-Wall -Wall
-Wextra -Wextra
-Werror
-Wmissing-prototypes -Wmissing-prototypes
-Wstrict-prototypes -Wstrict-prototypes
-Wmissing-declarations -Wmissing-declarations
@ -338,11 +343,11 @@ if(ENABLE_WERROR)
extract_valid_cxx_flags(WARNCXXFLAGS extract_valid_cxx_flags(WARNCXXFLAGS
# For C++ compiler # For C++ compiler
-Wall -Wall
-Werror
-Wformat-security -Wformat-security
) )
endif() endif()
set(EXTRACFLAG)
extract_valid_c_flags(EXTRACFLAG extract_valid_c_flags(EXTRACFLAG
-fvisibility=hidden -fvisibility=hidden
) )

View File

@ -1,11 +1,10 @@
# Convenience function that checks the availability # Convenience function that checks the availability
# of certain C or C++ compiler flags and returns the valid ones. # of certain C or C++ compiler flags and appends valid ones.
include(CheckCCompilerFlag) include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
function(extract_valid_c_flags varname) function(extract_valid_c_flags varname)
set(valid_flags "")
foreach(flag IN LISTS ARGN) foreach(flag IN LISTS ARGN)
string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag}) string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag})
set(flag_var "C_FLAG_${flag_var}") set(flag_var "C_FLAG_${flag_var}")
@ -18,7 +17,6 @@ function(extract_valid_c_flags varname)
endfunction() endfunction()
function(extract_valid_cxx_flags varname) function(extract_valid_cxx_flags varname)
set(valid_flags "")
foreach(flag IN LISTS ARGN) foreach(flag IN LISTS ARGN)
string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag}) string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag})
set(flag_var "CXX_FLAG_${flag_var}") set(flag_var "CXX_FLAG_${flag_var}")