Skip to content

Commit cc15e1b

Browse files
cosmo0920patrick-stephens
authored andcommitted
build: Implement strict pointer types option
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 7eab11a commit cc15e1b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ option(FLB_SMALL "Optimise for small size" No)
158158
set(FLB_SECURITY "ReleaseOnly" CACHE STRING "Build with security optimizations")
159159
set_property(CACHE FLB_SECURITY PROPERTY STRINGS "On;Off;ReleaseOnly")
160160
option(FLB_COVERAGE "Build with code-coverage" No)
161+
option(FLB_COMPILER_STRICT_POINTER_TYPES "Build with -Werror=incompatible-pointer-types" No)
161162
option(FLB_JEMALLOC "Build with Jemalloc support" No)
162163
option(FLB_REGEX "Build with Regex support" Yes)
163164
option(FLB_UTF8_ENCODER "Build with UTF8 encoding support" Yes)
@@ -450,6 +451,17 @@ if(FLB_COVERAGE)
450451
set(CMAKE_BUILD_TYPE "Debug")
451452
endif()
452453

454+
if(FLB_COMPILER_STRICT_POINTER_TYPES)
455+
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
456+
add_compile_options(-Werror=incompatible-pointer-types)
457+
endif()
458+
# Currently, AppleClang has more struct rules when using -Werror=incompatible-pointer-types.
459+
# We still permit to discarding const qualifiers warnings.
460+
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang")
461+
add_compile_options(-Wno-incompatible-pointer-types-discards-qualifiers)
462+
endif()
463+
endif()
464+
453465
# Enable Debug symbols if specified
454466
if(MSVC)
455467
set(CMAKE_BUILD_TYPE None) # Avoid flag conflicts (See CMakeList.txt:L18)

0 commit comments

Comments
 (0)