diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index 0028a040268..e89036ec3ac 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -53,6 +53,7 @@ jobs: - "-DFLB_SIMD=On" - "-DFLB_SIMD=Off" - "-DFLB_ARROW=On" + - "-DFLB_COMPILER_STRICT_POINTER_TYPES=On" cmake_version: - "3.31.6" compiler: @@ -71,6 +72,10 @@ jobs: compiler: cc: clang cxx: clang++ + - flb_option: "-DFLB_COMPILER_STRICT_POINTER_TYPES=On" + compiler: + cc: clang + cxx: clang++ permissions: contents: read steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cf122fd233..1059ddb8779 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,6 +158,7 @@ option(FLB_SMALL "Optimise for small size" No) set(FLB_SECURITY "ReleaseOnly" CACHE STRING "Build with security optimizations") set_property(CACHE FLB_SECURITY PROPERTY STRINGS "On;Off;ReleaseOnly") option(FLB_COVERAGE "Build with code-coverage" No) +option(FLB_COMPILER_STRICT_POINTER_TYPES "Build with -Werror=incompatible-pointer-types" No) option(FLB_JEMALLOC "Build with Jemalloc support" No) option(FLB_REGEX "Build with Regex support" Yes) option(FLB_UTF8_ENCODER "Build with UTF8 encoding support" Yes) @@ -450,6 +451,17 @@ if(FLB_COVERAGE) set(CMAKE_BUILD_TYPE "Debug") endif() +if(FLB_COMPILER_STRICT_POINTER_TYPES) + if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang") + add_compile_options(-Werror=incompatible-pointer-types) + endif() + # Currently, AppleClang has more struct rules when using -Werror=incompatible-pointer-types. + # We still permit to discarding const qualifiers warnings. + if(CMAKE_C_COMPILER_ID MATCHES "AppleClang") + add_compile_options(-Wno-incompatible-pointer-types-discards-qualifiers) + endif() +endif() + # Enable Debug symbols if specified if(MSVC) set(CMAKE_BUILD_TYPE None) # Avoid flag conflicts (See CMakeList.txt:L18)