+ # Compile options
+ add_compile_options(
+ /EHsc
+ "$<$<BOOL:${FATAL_WARNINGS}>:/WX>"
+ )
+
+ # Increase warning level on MSVC
+ # CMake puts /W3 in CMAKE_CXX_FLAGS which will be appended later, so we need to replace
+ string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+
+ # Silence warnings that are hard or impossible to avoid
+ # C4127: conditional expression is constant [in qvector.h as of Qt 5.15.2]
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4127")
+ # C4456: declaration of 'identifier' hides previous local declaration [caused by foreach macro, among others]
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4456")
+ # C4458: declaration of 'identifier' hides class member [caused by MOC for Peer::_id]
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4458")
+ # C4996: deprecation warnings [unavoidable due to wide range of supported Qt versions]
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996")
+ # C5240: 'nodiscard': attribute is ignored in this syntactic position [in qcolor.h as of Qt 5.15.2]
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd5240")
+
+ # Link against the correct version of the C runtime
+ set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt ${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
+ set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
+ set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/NODEFAULTLIB:libcmt /DEFAULTLIB:msvcrt ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}")
+ set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/NODEFAULTLIB:libcmtd /DEFAULTLIB:msvcrtd ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
+
+else()
+ # For other compilers, we rely on default settings (unless someone provides a good set of options; patches welcome!)
+ message(WARNING "${CMAKE_CXX_COMPILER_ID} is not a supported C++ compiler.")