Skip to content
Snippets Groups Projects
Commit d5a32212 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add clazy as a CMake mechanism to perform static-analysis

The clazy-standalone is used.
By default it runs using checks of level0

To change the behaviour define the environment variable
   CLAZY_CHECKS=level0,level1,level2
for instance, this will use also checks of level1 and level2.

Beware that more than level0 may be false positives.

Refer to clazy documentation for more details.
parent e35f65e0
No related branches found
No related tags found
1 merge request!35Feature/clazy
...@@ -162,6 +162,23 @@ else () ...@@ -162,6 +162,23 @@ else ()
message(WARNING "clang-format no found!") message(WARNING "clang-format no found!")
endif() endif()
#------------------------------------------------------
# search for clang-format
find_program(CLAZY_STANDALONE clazy-standalone)
if (CLAZY_STANDALONE)
add_custom_target(clazy-standalone
COMMAND ${CMAKE_COMMAND}
-DPUGS_SOURCE_DIR="${PUGS_SOURCE_DIR}"
-DPUGS_BINARY_DIR="${PUGS_BINARY_DIR}"
-DCLAZY_STANDALONE="${CLAZY_STANDALONE}"
-P ${PUGS_SOURCE_DIR}/cmake/ClazyStandaloneProcess.cmake
COMMENT "running ${CLAZY_STANDALONE} ..."
)
else ()
message(WARNING "clazy-standalone no found!")
endif()
#------------------------------------------------------ #------------------------------------------------------
# C++ 17 flags # C++ 17 flags
if(${CMAKE_VERSION} VERSION_LESS "3.8.0") if(${CMAKE_VERSION} VERSION_LESS "3.8.0")
......
# --------------- runs clazy-standalone ---------------
if(PUGS_SOURCE_DIR AND CLAZY_STANDALONE)
# get C++ sources file list (ignoring packages)
file(GLOB_RECURSE ALL_SOURCE_FILES
${PUGS_SOURCE_DIR}/src/**.[hc]pp
${PUGS_SOURCE_DIR}/tests/**.[hc]pp)
# checks if VERBOSE was set
set(ECHO_CMD_TO "NONE")
if (DEFINED ENV{VERBOSE})
set(ECHO_CMD_TO "STDOUT")
endif()
# Trick to continue on error using make
if(DEFINED ENV{MAKEFLAGS})
string(FIND $ENV{MAKEFLAGS} "k" K_POSITION)
if (NOT(${K_POSITION} EQUAL "-1"))
set (CONTINUE_ON_ERROR "continue")
endif()
endif()
# apply style to the file list
foreach(SOURCE_FILE ${ALL_SOURCE_FILES})
string(REGEX REPLACE "^${PUGS_SOURCE_DIR}/" "" BASE_SOURCE_FILE "${SOURCE_FILE}")
execute_process(
COMMAND "${CMAKE_COMMAND}" -E env CLICOLOR_FORCE=1
"${CMAKE_COMMAND}" -E cmake_echo_color --green "Running clazy-standalone on ${BASE_SOURCE_FILE}")
execute_process(
COMMAND "${CLAZY_STANDALONE}" "-p=${PUGS_BINARY_DIR}" "${SOURCE_FILE}"
COMMAND_ECHO ${ECHO_CMD_TO}
RESULT_VARIABLE clazy_result)
if (NOT DEFINED CONTINUE_ON_ERROR)
if (NOT (${clazy_result} EQUAL "0"))
message(FATAL_ERROR)
endif()
endif()
endforeach()
endif()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment