2020-01-13 10:24:35 +00:00
|
|
|
include (CheckCXXCompilerFlag)
|
2020-02-16 08:04:03 +00:00
|
|
|
include (CheckCCompilerFlag)
|
2020-01-10 10:25:14 +00:00
|
|
|
|
|
|
|
# Try to add -Wflag if compiler supports it
|
|
|
|
macro (add_warning flag)
|
|
|
|
string (REPLACE "-" "_" underscored_flag ${flag})
|
|
|
|
string (REPLACE "+" "x" underscored_flag ${underscored_flag})
|
2020-02-16 08:04:03 +00:00
|
|
|
|
|
|
|
check_cxx_compiler_flag("-W${flag}" SUPPORTS_CXXFLAG_${underscored_flag})
|
|
|
|
check_c_compiler_flag("-W${flag}" SUPPORTS_CFLAG_${underscored_flag})
|
|
|
|
|
|
|
|
if (SUPPORTS_CXXFLAG_${underscored_flag})
|
2020-01-10 10:25:14 +00:00
|
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W${flag}")
|
|
|
|
else ()
|
2021-11-24 22:50:54 +00:00
|
|
|
message (STATUS "Flag -W${flag} is unsupported")
|
2020-01-10 10:25:14 +00:00
|
|
|
endif ()
|
2020-02-16 08:04:03 +00:00
|
|
|
|
|
|
|
if (SUPPORTS_CFLAG_${underscored_flag})
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W${flag}")
|
|
|
|
else ()
|
2021-11-24 22:50:54 +00:00
|
|
|
message (STATUS "Flag -W${flag} is unsupported")
|
2020-02-16 08:04:03 +00:00
|
|
|
endif ()
|
|
|
|
|
2020-01-10 16:36:36 +00:00
|
|
|
endmacro ()
|
2020-01-10 10:25:14 +00:00
|
|
|
|
|
|
|
# Try to add -Wno flag if compiler supports it
|
|
|
|
macro (no_warning flag)
|
|
|
|
add_warning(no-${flag})
|
2020-01-10 16:36:36 +00:00
|
|
|
endmacro ()
|
2021-08-16 00:16:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
# The same but only for specified target.
|
|
|
|
macro (target_add_warning target flag)
|
|
|
|
string (REPLACE "-" "_" underscored_flag ${flag})
|
|
|
|
string (REPLACE "+" "x" underscored_flag ${underscored_flag})
|
|
|
|
|
|
|
|
check_cxx_compiler_flag("-W${flag}" SUPPORTS_CXXFLAG_${underscored_flag})
|
|
|
|
|
|
|
|
if (SUPPORTS_CXXFLAG_${underscored_flag})
|
|
|
|
target_compile_options (${target} PRIVATE "-W${flag}")
|
|
|
|
else ()
|
2021-11-24 22:50:54 +00:00
|
|
|
message (STATUS "Flag -W${flag} is unsupported")
|
2021-08-16 00:16:45 +00:00
|
|
|
endif ()
|
|
|
|
endmacro ()
|
|
|
|
|
|
|
|
macro (target_no_warning target flag)
|
|
|
|
target_add_warning(${target} no-${flag})
|
|
|
|
endmacro ()
|