-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler_flags.cmake
46 lines (40 loc) · 1.64 KB
/
compiler_flags.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
37
38
39
40
41
42
43
44
45
46
if(COMPILER_ENABLE_ALL_WARNINGS)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
set(gcc_warnings_flags -Wall
-Wextra
-Wpedantic
# Disable an extremly noisy on gtest with clang:
-Wno-gnu-zero-variadic-macro-arguments
-Werror=unused-function
-Werror=unused-variable
-Werror=unused-parameter)
message(STATUS "Enable compiler warnings: ${gcc_warnings_flags}")
# gcc/clang
add_compile_options(${gcc_warnings_flags})
elseif(MSVC)
# msvc
string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
add_compile_options(/W4)
endif()
endif()
if(COMPILER_ENABLE_UNUSED_X_AS_ERROR)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
set(gcc_error_flags -Werror=unused-function
-Werror=unused-variable
-Werror=unused-parameter)
message(STATUS "Enable compiler errors: ${gcc_error_flags}")
# gcc/clang
add_compile_options(${gcc_error_flags})
endif()
endif()
if(COMPILER_ENABLE_EFFECTIVE_CXX)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
message(STATUS "Enable Effective C++ warnings")
# gcc/clang
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Weffc++>)
else()
# Not supported
message(WARNING "COMPILER_ENABLE_EFFECTIVE_CXX is not supported")
endif()
endif()