From 96052ca2fbc58423d47b87630c67bb25ffb54138 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 18 Sep 2024 10:11:45 +0200 Subject: [PATCH 1/4] [build,c++] add CXXCompilerFlags to set warnings Just like with the C components and CompilerFlags.cmake add a configuration for C++ that disables specific warnings only found in C++ code. --- client/SDL/CMakeLists.txt | 1 + cmake/CXXCompilerFlags.cmake | 60 +++++++++++++++++++ .../modules/bitmap-filter/CMakeLists.txt | 1 + server/proxy/modules/demo/CMakeLists.txt | 1 + .../modules/dyn-channel-dump/CMakeLists.txt | 1 + 5 files changed, 64 insertions(+) create mode 100644 cmake/CXXCompilerFlags.cmake diff --git a/client/SDL/CMakeLists.txt b/client/SDL/CMakeLists.txt index 2965544b3..45ddd3b3d 100644 --- a/client/SDL/CMakeLists.txt +++ b/client/SDL/CMakeLists.txt @@ -39,6 +39,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/) include(CommonConfigOptions) include(ConfigureFreeRDP) +include(CXXCompilerFlags) option(WITH_DEBUG_SDL_EVENTS "[dangerous, not for release builds!] Debug SDL events" ${DEFAULT_DEBUG_OPTION}) option(WITH_DEBUG_SDL_KBD_EVENTS "[dangerous, not for release builds!] Debug SDL keyboard events" ${DEFAULT_DEBUG_OPTION}) diff --git a/cmake/CXXCompilerFlags.cmake b/cmake/CXXCompilerFlags.cmake new file mode 100644 index 000000000..c20baca2c --- /dev/null +++ b/cmake/CXXCompilerFlags.cmake @@ -0,0 +1,60 @@ +include(CheckCXXCompilerFlag) + +macro (checkCXXFlag FLAG) + check_cxx_compiler_flag("${FLAG}" CXXFLAG${FLAG}) + if(CXXFLAG${FLAG}) + string(APPEND CMAKE_CXX_FLAGS " ${FLAG}") + else() + message(WARNING "compiler does not support ${FLAG}") + endif() +endmacro() + +option(ENABLE_WARNING_VERBOSE "enable -Weveryting (and some exceptions) for compile" ON) +option(ENABLE_WARNING_ERROR "enable -Werror for compile" OFF) + +if (ENABLE_WARNING_VERBOSE) + if (MSVC) + # Remove previous warning definitions, + # NMake is otherwise complaining. + foreach (flags_var_to_scrub + CMAKE_CXX_FLAGS + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS_MINSIZEREL) + string (REGEX REPLACE "(^| )[/-]W[ ]*[1-9]" " " + "${flags_var_to_scrub}" "${${flags_var_to_scrub}}") + endforeach() + + set(C_WARNING_FLAGS + /W4 + /wo4324 + ) + else() + set(C_WARNING_FLAGS + -Weverything + -Wall + -Wpedantic + -Wno-padded + -Wno-switch-enum + -Wno-cast-align + -Wno-declaration-after-statement + -Wno-unsafe-buffer-usage + -Wno-reserved-identifier + -Wno-covered-switch-default + -Wno-ctad-maybe-unsupported + ) + endif() + + foreach(FLAG ${C_WARNING_FLAGS}) + CheckCXXFlag(${FLAG}) + endforeach() +endif() + + +if (ENABLE_WARNING_ERROR) + CheckCXXFlag(-Werror) +endif() + +set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} CACHE STRING "default CXXFLAGS") +message("Using CXXFLAGS ${CMAKE_CXX_FLAGS}") diff --git a/server/proxy/modules/bitmap-filter/CMakeLists.txt b/server/proxy/modules/bitmap-filter/CMakeLists.txt index 03c140331..60d6ce85e 100644 --- a/server/proxy/modules/bitmap-filter/CMakeLists.txt +++ b/server/proxy/modules/bitmap-filter/CMakeLists.txt @@ -44,6 +44,7 @@ message("project ${PROJECT_NAME} is using version ${PROJECT_VERSION}") set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../cmake/) include(CommonConfigOptions) +include(CXXCompilerFlags) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/server/proxy/modules/demo/CMakeLists.txt b/server/proxy/modules/demo/CMakeLists.txt index c16440aee..ab3ec829d 100644 --- a/server/proxy/modules/demo/CMakeLists.txt +++ b/server/proxy/modules/demo/CMakeLists.txt @@ -37,6 +37,7 @@ message("project ${PROJECT_NAME} is using version ${PROJECT_VERSION}") set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../cmake/) include(CommonConfigOptions) +include(CXXCompilerFlags) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/server/proxy/modules/dyn-channel-dump/CMakeLists.txt b/server/proxy/modules/dyn-channel-dump/CMakeLists.txt index dff349ca1..4e328bcbf 100644 --- a/server/proxy/modules/dyn-channel-dump/CMakeLists.txt +++ b/server/proxy/modules/dyn-channel-dump/CMakeLists.txt @@ -36,6 +36,7 @@ message("project ${PROJECT_NAME} is using version ${PROJECT_VERSION}") set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../cmake/) include(CommonConfigOptions) +include(CXXCompilerFlags) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) From c509aabc080f605096d526741785d7f5136bb55c Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 18 Sep 2024 10:54:06 +0200 Subject: [PATCH 2/4] [cmake] disable -Wdisabled-macro-expansion this warning does not yield useful results for FreeRDP, disable by default. --- cmake/CXXCompilerFlags.cmake | 1 + cmake/CompilerFlags.cmake | 1 + 2 files changed, 2 insertions(+) diff --git a/cmake/CXXCompilerFlags.cmake b/cmake/CXXCompilerFlags.cmake index c20baca2c..4429de483 100644 --- a/cmake/CXXCompilerFlags.cmake +++ b/cmake/CXXCompilerFlags.cmake @@ -42,6 +42,7 @@ if (ENABLE_WARNING_VERBOSE) -Wno-unsafe-buffer-usage -Wno-reserved-identifier -Wno-covered-switch-default + -Wno-disabled-macro-expansion -Wno-ctad-maybe-unsupported ) endif() diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index a946def2b..cdb2ae4da 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -42,6 +42,7 @@ if (ENABLE_WARNING_VERBOSE) -Wno-unsafe-buffer-usage -Wno-reserved-identifier -Wno-covered-switch-default + -Wno-disabled-macro-expansion ) endif() From 02b98e9287d3be33969cf21373d4da608e9a0cd6 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 18 Sep 2024 11:05:18 +0200 Subject: [PATCH 3/4] [client,sdl] use constexpr instead of defines --- client/SDL/SDL2/sdl_disp.cpp | 4 ++-- client/SDL/SDL3/sdl_disp.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/SDL/SDL2/sdl_disp.cpp b/client/SDL/SDL2/sdl_disp.cpp index 56e38b4c2..126902935 100644 --- a/client/SDL/SDL2/sdl_disp.cpp +++ b/client/SDL/SDL2/sdl_disp.cpp @@ -33,8 +33,8 @@ #include #define TAG CLIENT_TAG("sdl.disp") -#define RESIZE_MIN_DELAY 200 /* minimum delay in ms between two resizes */ -#define MAX_RETRIES 5 +static constexpr UINT64 RESIZE_MIN_DELAY = 200; /* minimum delay in ms between two resizes */ +static constexpr unsigned MAX_RETRIES = 5; BOOL sdlDispContext::settings_changed() { diff --git a/client/SDL/SDL3/sdl_disp.cpp b/client/SDL/SDL3/sdl_disp.cpp index eac2d9d1d..d85b34b7b 100644 --- a/client/SDL/SDL3/sdl_disp.cpp +++ b/client/SDL/SDL3/sdl_disp.cpp @@ -33,8 +33,8 @@ #include #define TAG CLIENT_TAG("sdl.disp") -#define RESIZE_MIN_DELAY 200 /* minimum delay in ms between two resizes */ -#define MAX_RETRIES 5 +static constexpr UINT64 RESIZE_MIN_DELAY = 200; /* minimum delay in ms between two resizes */ +static constexpr unsigned MAX_RETRIES = 5; BOOL sdlDispContext::settings_changed() { From 107a8d9f48c867e37d3761006a5afb1584d85cd3 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 18 Sep 2024 11:41:50 +0200 Subject: [PATCH 4/4] [compiler] disable C++ warnings Projects are set to require C++ 17, so disable all warnings complaining about compatibility with previous versions of the standard. --- cmake/CXXCompilerFlags.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/CXXCompilerFlags.cmake b/cmake/CXXCompilerFlags.cmake index 4429de483..4ad13efe3 100644 --- a/cmake/CXXCompilerFlags.cmake +++ b/cmake/CXXCompilerFlags.cmake @@ -44,6 +44,9 @@ if (ENABLE_WARNING_VERBOSE) -Wno-covered-switch-default -Wno-disabled-macro-expansion -Wno-ctad-maybe-unsupported + -Wno-c++98-compat + -Wno-c++98-compat-pedantic + -Wno-pre-c++17-compat ) endif()