Skip to content

Commit fb75ebb

Browse files
committed
cmake: Add compiler diagnostic flags
1 parent e821f0a commit fb75ebb

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,52 @@ include(cmake/introspection.cmake)
417417

418418
include(cmake/ccache.cmake)
419419

420+
add_library(warn_interface INTERFACE)
421+
target_link_libraries(core_interface INTERFACE warn_interface)
422+
if(MSVC)
423+
try_append_cxx_flags("/W3" TARGET warn_interface SKIP_LINK)
424+
try_append_cxx_flags("/wd4018" TARGET warn_interface SKIP_LINK)
425+
try_append_cxx_flags("/wd4244" TARGET warn_interface SKIP_LINK)
426+
try_append_cxx_flags("/wd4267" TARGET warn_interface SKIP_LINK)
427+
try_append_cxx_flags("/wd4715" TARGET warn_interface SKIP_LINK)
428+
try_append_cxx_flags("/wd4805" TARGET warn_interface SKIP_LINK)
429+
target_compile_definitions(warn_interface INTERFACE
430+
_CRT_SECURE_NO_WARNINGS
431+
_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
432+
)
433+
else()
434+
try_append_cxx_flags("-Wall" TARGET warn_interface SKIP_LINK)
435+
try_append_cxx_flags("-Wextra" TARGET warn_interface SKIP_LINK)
436+
try_append_cxx_flags("-Wgnu" TARGET warn_interface SKIP_LINK)
437+
# Some compilers will ignore -Wformat-security without -Wformat, so just combine the two here.
438+
try_append_cxx_flags("-Wformat -Wformat-security" TARGET warn_interface SKIP_LINK)
439+
try_append_cxx_flags("-Wvla" TARGET warn_interface SKIP_LINK)
440+
try_append_cxx_flags("-Wshadow-field" TARGET warn_interface SKIP_LINK)
441+
try_append_cxx_flags("-Wthread-safety" TARGET warn_interface SKIP_LINK)
442+
try_append_cxx_flags("-Wloop-analysis" TARGET warn_interface SKIP_LINK)
443+
try_append_cxx_flags("-Wredundant-decls" TARGET warn_interface SKIP_LINK)
444+
try_append_cxx_flags("-Wunused-member-function" TARGET warn_interface SKIP_LINK)
445+
try_append_cxx_flags("-Wdate-time" TARGET warn_interface SKIP_LINK)
446+
try_append_cxx_flags("-Wconditional-uninitialized" TARGET warn_interface SKIP_LINK)
447+
try_append_cxx_flags("-Wduplicated-branches" TARGET warn_interface SKIP_LINK)
448+
try_append_cxx_flags("-Wduplicated-cond" TARGET warn_interface SKIP_LINK)
449+
try_append_cxx_flags("-Wlogical-op" TARGET warn_interface SKIP_LINK)
450+
try_append_cxx_flags("-Woverloaded-virtual" TARGET warn_interface SKIP_LINK)
451+
try_append_cxx_flags("-Wsuggest-override" TARGET warn_interface SKIP_LINK)
452+
try_append_cxx_flags("-Wimplicit-fallthrough" TARGET warn_interface SKIP_LINK)
453+
try_append_cxx_flags("-Wunreachable-code" TARGET warn_interface SKIP_LINK)
454+
try_append_cxx_flags("-Wdocumentation" TARGET warn_interface SKIP_LINK)
455+
try_append_cxx_flags("-Wself-assign" TARGET warn_interface SKIP_LINK)
456+
try_append_cxx_flags("-Wundef" TARGET warn_interface SKIP_LINK)
457+
458+
# Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
459+
# unknown options if any other warning is produced. Test the -Wfoo case, and
460+
# set the -Wno-foo case if it works.
461+
try_append_cxx_flags("-Wunused-parameter" TARGET warn_interface SKIP_LINK
462+
IF_CHECK_PASSED "-Wno-unused-parameter"
463+
)
464+
endif()
465+
420466
# Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review.
421467
try_append_cxx_flags("-fno-extended-identifiers" TARGET core_interface SKIP_LINK)
422468

0 commit comments

Comments
 (0)