-
Notifications
You must be signed in to change notification settings - Fork 4
/
SetCompilerWarningAll.cmake
36 lines (30 loc) · 1.31 KB
/
SetCompilerWarningAll.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# - Enable warning all for gcc or use /W4 for visual studio
#
# TODO:
# - Make it more portable
## Strict warning level
IF (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)")
# Use the highest warning level for visual studio.
SET(CMAKE_CXX_WARNING_LEVEL 4)
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ELSE (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
ENDIF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
SET(CMAKE_C_WARNING_LEVEL 4)
IF (CMAKE_C_FLAGS MATCHES "/W[0-4]")
STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
ELSE (CMAKE_C_FLAGS MATCHES "/W[0-4]")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
ENDIF (CMAKE_C_FLAGS MATCHES "/W[0-4]")
ELSEIF (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUC)
# use -Wall for gcc
IF(NOT CMAKE_CXX_FLAGS MATCHES "-Wall$")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
ENDIF(NOT CMAKE_CXX_FLAGS MATCHES "-Wall$")
IF(NOT CMAKE_C_FLAGS MATCHES "-Wall$")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
ENDIF(NOT CMAKE_C_FLAGS MATCHES "-Wall$")
ELSE (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)")
MESSAGE(STATUS "Unknown build tool, cannot set warning flags for your")
ENDIF (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)")