diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a51c3e4fcd..eb8b7ed7215 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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. diff --git a/cmake/leveldb.cmake b/cmake/leveldb.cmake index 139c6a5b3a8..36c549ebc5e 100644 --- a/cmake/leveldb.cmake +++ b/cmake/leveldb.cmake @@ -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" diff --git a/cmake/module/TryAppendCXXFlags.cmake b/cmake/module/TryAppendCXXFlags.cmake index dc0a9b7f8f5..ebb7414c0ee 100644 --- a/cmake/module/TryAppendCXXFlags.cmake +++ b/cmake/module/TryAppendCXXFlags.cmake @@ -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()