From 86500e6987f267d1797c01f147efba7cde0cd476 Mon Sep 17 00:00:00 2001 From: Matej Kenda Date: Tue, 23 Dec 2025 15:58:15 +0100 Subject: [PATCH] chore(cmake): ENABLE_COMPILER_WARNINGS sets compiler options only for Poco code, not dependent libraries. --- CMakeLists.txt | 3 ++ cmake/DefinePlatformSpecific.cmake | 57 +++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8681ebdf7..613f03bd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -432,6 +432,9 @@ endif() add_subdirectory(dependencies) +# Enable detailed compiler warnings for Poco code only (after dependencies to exclude them) +poco_enable_detailed_compiler_warnings() + if(ENABLE_FOUNDATION) add_subdirectory(Foundation) list(APPEND Poco_COMPONENTS "Foundation") diff --git a/cmake/DefinePlatformSpecific.cmake b/cmake/DefinePlatformSpecific.cmake index c5eac2a4a..bb8900b39 100644 --- a/cmake/DefinePlatformSpecific.cmake +++ b/cmake/DefinePlatformSpecific.cmake @@ -62,24 +62,47 @@ if (DEFINED POCO_SANITIZEFLAGS AND NOT "${POCO_SANITIZEFLAGS}" STREQUAL "") add_link_options(${POCO_SANITIZEFLAGS}) endif() -if (ENABLE_COMPILER_WARNINGS) - message(STATUS "Enabling additional compiler warning flags.") - # Additional compiler-specific warning flags - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # using clang - add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-parameter) - # Warn when using 0 or NULL instead of nullptr constant - add_compile_options(-Wzero-as-null-pointer-constant) - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # using GCC - add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-parameter) - # Warn when using 0 or NULL instead of nullptr constant - add_compile_options(-Wzero-as-null-pointer-constant) - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - # using Visual Studio C++ - add_compile_options(/W4) +################################################################################# +# Compiler warnings for Poco code only +################################################################################# +# This function enables additional compiler warnings for Poco C++ code. +# It should be called from the root CMakeLists.txt AFTER add_subdirectory(dependencies) +# to ensure third-party code is not affected. +# +# The function uses $ generator expressions to apply +# warnings only to C++ files, providing an extra layer of protection since +# bundled dependencies are mostly C code. +# +function(poco_enable_detailed_compiler_warnings) + if (NOT ENABLE_COMPILER_WARNINGS) + return() endif() -endif() + + message(STATUS "Enabling additional compiler warning flags for Poco C++ code only.") + + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Clang and AppleClang + add_compile_options( + $<$:-Wall> + $<$:-Wextra> + $<$:-Wpedantic> + $<$:-Wno-unused-parameter> + $<$:-Wzero-as-null-pointer-constant> + ) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # GCC + add_compile_options( + $<$:-Wall> + $<$:-Wextra> + $<$:-Wpedantic> + $<$:-Wno-unused-parameter> + $<$:-Wzero-as-null-pointer-constant> + ) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # Visual Studio + add_compile_options($<$:/W4>) + endif() +endfunction(poco_enable_detailed_compiler_warnings) # Add a d postfix to the debug libraries if(BUILD_SHARED_LIBS)