From f2f3b4c71210958125d4945442641e0305fbeba9 Mon Sep 17 00:00:00 2001 From: Adam Kosiorek Date: Mon, 28 Jul 2014 14:01:45 +0200 Subject: Added lint target --- CMakeScripts/lint.cmake | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 CMakeScripts/lint.cmake (limited to 'CMakeScripts') diff --git a/CMakeScripts/lint.cmake b/CMakeScripts/lint.cmake new file mode 100644 index 00000000..04df3409 --- /dev/null +++ b/CMakeScripts/lint.cmake @@ -0,0 +1,48 @@ + +set(CMAKE_SOURCE_DIR ../) +set(LINT_COMMAND ${CMAKE_SOURCE_DIR}/scripts/cpp_lint.py) +set(SRC_FILE_EXTENSIONS h hpp hu c cpp cu cc) +set(EXCLUDE_FILE_EXTENSTIONS pb.h pb.cc) +set(LINT_DIRS include src/caffe examples tools python matlab) + +# find all files of interest +foreach(ext ${SRC_FILE_EXTENSIONS}) + foreach(dir ${LINT_DIRS}) + file(GLOB_RECURSE FOUND_FILES ${CMAKE_SOURCE_DIR}/${dir}/*.${ext}) + set(LINT_SOURCES ${LINT_SOURCES} ${FOUND_FILES}) + endforeach() +endforeach() + +# find all files that should be excluded +foreach(ext ${EXCLUDE_FILE_EXTENSTIONS}) + file(GLOB_RECURSE FOUND_FILES ${CMAKE_SOURCE_DIR}/*.${ext}) + set(EXCLUDED_FILES ${EXCLUDED_FILES} ${FOUND_FILES}) +endforeach() + +# exclude generated pb files +list(REMOVE_ITEM LINT_SOURCES ${EXCLUDED_FILES}) + +execute_process( + COMMAND ${LINT_COMMAND} ${LINT_SOURCES} + ERROR_VARIABLE LINT_OUTPUT + ERROR_STRIP_TRAILING_WHITESPACE +) + +string(REPLACE "\n" ";" LINT_OUTPUT ${LINT_OUTPUT}) + +list(GET LINT_OUTPUT -1 LINT_RESULT) +list(REMOVE_AT LINT_OUTPUT -1) +string(REPLACE " " ";" LINT_RESULT ${LINT_RESULT}) +list(GET LINT_RESULT -1 NUM_ERRORS) +if(NUM_ERRORS GREATER 0) + foreach(msg ${LINT_OUTPUT}) + string(FIND ${msg} "Done" result) + if(result LESS 0) + message(STATUS ${msg}) + endif() + endforeach() + message(FATAL_ERROR "Lint found ${NUM_ERRORS} errors!") +else() + message(STATUS "Lint did not find any errors!") +endif() + -- cgit v1.2.3