From e047f876f02c49f4af04a66d796fd8cd7d6af94f Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sat, 30 Dec 2023 07:50:52 +0100 Subject: [PATCH 1/6] add a developer mode option This triggers more compilation warning. It is not on by default so the code will keep building without new warning in the future. It is meant for developers of the library to produce cleaner code and/or detect issues early. (cherry picked from commit fd4ad0cb08525c2a8a77f0f6391e33df0df51777) --- CMakeLists.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f610219d..d48e5969 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,11 +26,28 @@ feature_info_on_off(DISABLE_CMAKE_CONFIG "won't generate CMake config file" "wil option(ENABLE_WIN32_IO "Build the Windows I/O helper class" OFF) feature_info_on_off(ENABLE_WIN32_IO "will build Windows I/O code" "will not build Windows I/O code") +option(DEV_MODE "Developer mode with extra compilation checks" OFF) +feature_info_on_off(DEV_MODE "added developer mode extra compilation checks" "default build mode") + include(GNUInstallDirs) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) +include(CheckCXXCompilerFlag) +include(CMakeParseArguments) +function(add_cxx_flag_if_supported) + foreach(flagname ${ARGN}) + string(REPLACE "-" "_" TEST_RESULT ${flagname}) + check_cxx_compiler_flag(${flagname} HAVE_FLAG_${TEST_RESULT}) + # message(STATUS "supported ${flagname}: ${HAVE_FLAG_${TEST_RESULT}}") + + if (HAVE_FLAG_${TEST_RESULT}) + add_compile_options(${flagname}) + endif() + endforeach() +endfunction() + find_package(utf8cpp 3.2.0) if(NOT utf8cpp_FOUND) include(FetchContent REQUIRED) @@ -45,6 +62,16 @@ if(NOT utf8cpp_FOUND) FetchContent_MakeAvailable(utf8cpp) endif() +if(DEV_MODE) + message(STATUS "Using developer mode for ${CMAKE_CXX_COMPILER_ID}") + set(CMAKE_CXX_EXTENSIONS OFF) + add_cxx_flag_if_supported(-Wall -Wno-comment -Wfatal-errors -fstack-protector-strong -Wnon-virtual-dtor -Wextra + -Wunused -Wpedantic -Woverloaded-virtual -Wshadow + -Wno-self-assign -Wno-mismatched-tags -Wno-inconsistent-missing-override + -Wno-potentially-evaluated-expression -Wno-extra-semi -Wno-gnu-zero-variadic-macro-arguments) + add_cxx_flag_if_supported(-Qunused-arguments) +endif() + set(libebml_SOURCES src/Debug.cpp src/EbmlBinary.cpp From 9996ba9a4d0822edee76b86f9b2da950240b1d05 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sat, 3 Feb 2024 10:04:42 +0100 Subject: [PATCH 2/6] generate a warning for alignement issues And make sure clang doesn't pretend to use compiler flags when it just ignores them. (cherry picked from commit 8c3ae20675348889053113eca5e16badfbb8541e) --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d48e5969..7b9a36e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,10 +65,12 @@ endif() if(DEV_MODE) message(STATUS "Using developer mode for ${CMAKE_CXX_COMPILER_ID}") set(CMAKE_CXX_EXTENSIONS OFF) - add_cxx_flag_if_supported(-Wall -Wno-comment -Wfatal-errors -fstack-protector-strong -Wnon-virtual-dtor -Wextra + add_cxx_flag_if_supported(-Wno-error=unused-command-line-argument + -Wall -Wno-comment -Wfatal-errors -fstack-protector-strong -Wnon-virtual-dtor -Wextra -Wunused -Wpedantic -Woverloaded-virtual -Wshadow -Wno-self-assign -Wno-mismatched-tags -Wno-inconsistent-missing-override - -Wno-potentially-evaluated-expression -Wno-extra-semi -Wno-gnu-zero-variadic-macro-arguments) + -Wno-potentially-evaluated-expression -Wno-extra-semi -Wno-gnu-zero-variadic-macro-arguments + -Wcast-align) add_cxx_flag_if_supported(-Qunused-arguments) endif() From c626be20ab4c234de6d11fae77833a1e0b4e3685 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 3 Feb 2024 18:04:45 -0800 Subject: [PATCH 3/6] cmake: remove various warning suppressions Most of the have already been fixed. Signed-off-by: Rosen Penev (cherry picked from commit 3a015a4263dc7eb2882ccc02ee8f1e878f29d524) --- CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b9a36e3..e07bceb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,12 +66,9 @@ if(DEV_MODE) message(STATUS "Using developer mode for ${CMAKE_CXX_COMPILER_ID}") set(CMAKE_CXX_EXTENSIONS OFF) add_cxx_flag_if_supported(-Wno-error=unused-command-line-argument - -Wall -Wno-comment -Wfatal-errors -fstack-protector-strong -Wnon-virtual-dtor -Wextra - -Wunused -Wpedantic -Woverloaded-virtual -Wshadow - -Wno-self-assign -Wno-mismatched-tags -Wno-inconsistent-missing-override - -Wno-potentially-evaluated-expression -Wno-extra-semi -Wno-gnu-zero-variadic-macro-arguments + -Wall -Wextra -Wpedantic -Wfatal-errors -fstack-protector-strong + -Wno-self-assign -Wcast-align) - add_cxx_flag_if_supported(-Qunused-arguments) endif() set(libebml_SOURCES From 1acd3a70a47d4e7c95fd5fc8f535d89a7181bea3 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sun, 18 Feb 2024 16:51:49 +0100 Subject: [PATCH 4/6] disable most verbose warnings in MSVC They are very noisy and not very useful. the list of warnings can be found at https://learn.microsoft.com/en-us/cpp/preprocessor/compiler-warnings-that-are-off-by-default (cherry picked from commit f9af4fd060443d5ebbf615999863d77ced56bdc3) --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e07bceb5..1b04ed30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,8 @@ if(DEV_MODE) add_cxx_flag_if_supported(-Wno-error=unused-command-line-argument -Wall -Wextra -Wpedantic -Wfatal-errors -fstack-protector-strong -Wno-self-assign - -Wcast-align) + -Wcast-align + -W4) endif() set(libebml_SOURCES From 1e5cff6bcac14e4c05ab3ee1f96f142203d6423b Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sun, 5 Jan 2025 13:21:31 +0100 Subject: [PATCH 5/6] CMake: remove unnecessary -Wno-self-assign If the compiler complains we should handle it. (cherry picked from commit 802880aa768facba75b6ebf66da70afa724d3cb4) --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b04ed30..937e01b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,6 @@ if(DEV_MODE) set(CMAKE_CXX_EXTENSIONS OFF) add_cxx_flag_if_supported(-Wno-error=unused-command-line-argument -Wall -Wextra -Wpedantic -Wfatal-errors -fstack-protector-strong - -Wno-self-assign -Wcast-align -W4) endif() From 923236f43a2801e2825c2f3758b162fba62c436b Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sat, 2 May 2026 09:28:08 +0200 Subject: [PATCH 6/6] CMake: check actually needed system headers are used In dev mode. So CI builds must pass with this mode on. LIBCPP_REMOVE_TRANSITIVE_INCLUDES is a libc++ thing. (cherry picked from commit cb754b90c9145d415e1d963c495e0e5ceab6bffe) --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 937e01b3..76cf6555 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ endif() if(DEV_MODE) message(STATUS "Using developer mode for ${CMAKE_CXX_COMPILER_ID}") set(CMAKE_CXX_EXTENSIONS OFF) + add_definitions("-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES") add_cxx_flag_if_supported(-Wno-error=unused-command-line-argument -Wall -Wextra -Wpedantic -Wfatal-errors -fstack-protector-strong -Wcast-align