CodeCommitsIssuesPull requestsActionsInsightsSecurity
fb2855c5586c99d89c3fccc47c47642d9273070e

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

cmake/add_warning.cmake

29lines · modecode

1include (CheckCXXCompilerFlag)
2include (CheckCCompilerFlag)
3
4# Try to add -Wflag if compiler supports it
5macro (add_warning flag)
6 string (REPLACE "-" "_" underscored_flag ${flag})
7 string (REPLACE "+" "x" underscored_flag ${underscored_flag})
8
9 check_cxx_compiler_flag("-W${flag}" SUPPORTS_CXXFLAG_${underscored_flag})
10 check_c_compiler_flag("-W${flag}" SUPPORTS_CFLAG_${underscored_flag})
11
12 if (SUPPORTS_CXXFLAG_${underscored_flag})
13 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W${flag}")
14 else ()
15 message (WARNING "Flag -W${flag} is unsupported")
16 endif ()
17
18 if (SUPPORTS_CFLAG_${underscored_flag})
19 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W${flag}")
20 else ()
21 message (WARNING "Flag -W${flag} is unsupported")
22 endif ()
23
24endmacro ()
25
26# Try to add -Wno flag if compiler supports it
27macro (no_warning flag)
28 add_warning(no-${flag})
29endmacro ()