This commit is contained in:
Erik Fröjdh
2021-10-12 11:42:02 +02:00
committed by GitHub
parent e84f5bec0b
commit 7426110e8a
2 changed files with 70 additions and 35 deletions

View File

@ -1,10 +1,64 @@
include(CheckCXXCompilerFlag)
function(sls_add_flag_if_available flag target)
check_cxx_compiler_flag(${flag} flag_supported)
if(flag_supported)
include(CheckCCompilerFlag)
function(enable_cxx_warning flag target)
string(REPLACE "-W" "HAS_" flag_name ${flag})
check_cxx_compiler_flag(${flag} ${flag_name})
if(${flag_name})
target_compile_options(${target} INTERFACE ${flag})
message("Adding: ${flag} to ${target}")
else()
message("Flag: ${flag} not supported")
endif()
endfunction()
function(enable_c_warning flag target)
string(REPLACE "-W" "HAS_" flag_name ${flag})
check_c_compiler_flag(${flag} ${flag_name})
if(${flag_name})
target_compile_options(${target} INTERFACE ${flag})
message("Adding: ${flag} to ${target}")
else()
message("Flag: ${flag} not supported")
endif()
endfunction()
function(disable_cxx_warning flag target)
string(REPLACE "-W" "HAS_" flag_name ${flag})
check_cxx_compiler_flag(${flag} ${flag_name})
if(${flag_name})
string(REPLACE "-W" "-Wno-" neg_flag ${flag})
message("Adding: ${neg_flag} to ${target}")
target_compile_options(${target} INTERFACE ${neg_flag})
else()
message("Warning: ${flag} not supported no need to disable")
endif()
endfunction()
function(disable_c_warning flag target)
string(REPLACE "-W" "HAS_" flag_name ${flag})
check_c_compiler_flag(${flag} ${flag_name})
if(${flag_name})
string(REPLACE "-W" "-Wno-" neg_flag ${flag})
message("Adding: ${neg_flag} to ${target}")
target_compile_options(${target} INTERFACE ${neg_flag})
else()
message("Warning: ${flag} not supported no need to disable")
endif()
endfunction()
function(sls_disable_c_warning flag)
disable_c_warning(${flag} slsProjectCSettings)
endfunction()
function(sls_enable_cxx_warning flag)
enable_cxx_warning(${flag} slsProjectWarnings)
endfunction()
function(sls_disable_cxx_warning flag)
disable_cxx_warning(${flag} slsProjectWarnings)
endfunction()