cmake: Adjust diagnostic flags for clang-cl

This commit is contained in:
Hennadii Stepanov 2025-03-10 17:52:02 +00:00
parent 7803eb4a51
commit 88a082b2aa
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
3 changed files with 20 additions and 10 deletions

View file

@ -411,19 +411,23 @@ include(cmake/ccache.cmake)
add_library(warn_interface INTERFACE)
target_link_libraries(core_interface INTERFACE warn_interface)
if(MSVC)
# For both cl and clang-cl compilers.
try_append_cxx_flags("/W3" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("/wd4018" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("/wd4146" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("/wd4244" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("/wd4267" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("/wd4715" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("/wd4805" TARGET warn_interface SKIP_LINK)
target_compile_definitions(warn_interface INTERFACE
_CRT_SECURE_NO_WARNINGS
_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
)
else()
try_append_cxx_flags("-Wall" TARGET warn_interface SKIP_LINK)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
try_append_cxx_flags("/wd4018" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("/wd4146" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("/wd4244" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("/wd4267" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("/wd4715" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("/wd4805" TARGET warn_interface SKIP_LINK)
else()
try_append_cxx_flags("-Wextra" TARGET warn_interface SKIP_LINK)
try_append_cxx_flags("-Wgnu" TARGET warn_interface SKIP_LINK)
# Some compilers will ignore -Wformat-security without -Wformat, so just combine the two here.

View file

@ -80,12 +80,14 @@ target_include_directories(leveldb
add_library(nowarn_leveldb_interface INTERFACE)
if(MSVC)
target_compile_options(nowarn_leveldb_interface INTERFACE
/wd4722
)
target_compile_definitions(nowarn_leveldb_interface INTERFACE
_CRT_NONSTDC_NO_WARNINGS
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(nowarn_leveldb_interface INTERFACE
/wd4722
)
else()
try_append_cxx_flags("-Wconditional-uninitialized" TARGET nowarn_leveldb_interface SKIP_LINK
IF_CHECK_PASSED "-Wno-conditional-uninitialized"

View file

@ -120,7 +120,11 @@ function(try_append_cxx_flags flags)
endfunction()
if(MSVC)
try_append_cxx_flags("/WX /options:strict" VAR working_compiler_werror_flag SKIP_LINK)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
try_append_cxx_flags("/WX /options:strict" VAR working_compiler_werror_flag SKIP_LINK)
else()
try_append_cxx_flags("/WX" VAR working_compiler_werror_flag SKIP_LINK)
endif()
else()
try_append_cxx_flags("-Werror" VAR working_compiler_werror_flag SKIP_LINK)
endif()