Skip to content

Commit ba02325

Browse files
CMakeLists.txt: add GCC SAST to build
1 parent b137d25 commit ba02325

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ set(C_STD gnu11)
1313
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
1414
message("Debug build")
1515
set(C_FLAGS_DEBUG " -O0 -g -fasynchronous-unwind-tables -fexceptions ")
16-
set(C_FLAGS_WARNINGS " -Wall -Wextra -pedantic -Werror -Wformat=2 -Wconversion -Wdouble-promotion \
16+
set(C_FLAGS_WARNINGS " -Wall -Wextra -pedantic -Wformat=2 -Wconversion -Wdouble-promotion \
1717
-Wcast-align -Wredundant-decls -Winline -Wdisabled-optimization -Wnested-externs ")
18+
# -Werror
19+
1820
#More flags to try (these report some new warnings!): -Og -Wshadow -Wundef -Wcast-qual
1921
# and some extras: -Wmissing-prototypes -Wmissing-declarations
22+
## set(C_FLAGS_RUNTIME_CHECKS " -fsanitize=address,undefined ") #It's possible to enable RUNTIME warnings
23+
24+
# Enable GCC SAST
25+
# TODO: CodeChecker might complain on -fanalyzer flag
26+
set(C_FLAGS_WARNINGS_EXTRA " -fanalyzer -Wcast-qual -Wcast-align -Wredundant-decls -Winline -Wdisabled-optimization -Wnested-externs \
27+
-fstrict-aliasing ") #more: -Wmissing-prototypes -Wmissing-declarations
28+
2029

2130
#-DCMAKE_BUILD_TYPE=Release
2231
ELSE()
@@ -29,7 +38,7 @@ ELSE()
2938
#set(C_FLAGS_SECURITY_LIB " -fpic ")
3039
ENDIF()
3140

32-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=${C_STD} ${C_FLAGS_DEBUG} ${C_FLAGS_WARNINGS} ${C_FLAGS_SECURITY} -fno-common")
41+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=${C_STD} ${C_FLAGS_DEBUG} ${C_FLAGS_WARNINGS} ${C_FLAGS_WARNINGS_EXTRA} ${C_FLAGS_SECURITY} -fno-common")
3342
#set(CMAKE_C_COMPILER /usr/bin/gcc)
3443

3544
add_executable(array array.c)

0 commit comments

Comments
 (0)