diff options
author | Adam Kosiorek <a.kosiorek@samsung.com> | 2014-07-28 14:01:45 +0200 |
---|---|---|
committer | Jeff Donahue <jeff.donahue@gmail.com> | 2014-08-17 01:07:17 -0700 |
commit | f2f3b4c71210958125d4945442641e0305fbeba9 (patch) | |
tree | e4c9d16dbce4b956fa974d353e854cc7d921c03f | |
parent | bad9d1ea0dddf2d639ca98d93a57692b92976de5 (diff) | |
download | caffeonacl-f2f3b4c71210958125d4945442641e0305fbeba9.tar.gz caffeonacl-f2f3b4c71210958125d4945442641e0305fbeba9.tar.bz2 caffeonacl-f2f3b4c71210958125d4945442641e0305fbeba9.zip |
Added lint target
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 16 | ||||
-rw-r--r-- | CMakeScripts/lint.cmake | 48 |
3 files changed, 64 insertions, 1 deletions
diff --git a/.travis.yml b/.travis.yml index e8e9c8a3..c94d9cde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,6 +58,7 @@ script: - cmake -DBUILD_PYTHON=ON -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release -DCPU_ONLY=ON .. - make --keep-going --jobs=$NUM_THREADS - make runtest --keep-going --jobs=$NUM_THREADS + - make lint --jobs=$NUM_THREADS - make clean && rm -rf * ## Cleaning - cd .. diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bc6d07b..8df7412b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,8 +38,11 @@ set(${PROJECT_NAME}_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/include) include_directories(${${PROJECT_NAME}_INCLUDE_DIRS}) include_directories(${CMAKE_SOURCE_DIR}/src) +# CMake Scripts dir +set(CMAKE_SCRIPT_DIR ${CMAKE_SOURCE_DIR}/CMakeScripts) + # CMake module path for custom module finding -set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMakeScripts) +set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SCRIPT_DIR}) # CUDA is required globally if(NOT CPU_ONLY) @@ -68,8 +71,19 @@ if(BUILD_MATLAB) add_subdirectory(matlab) endif() +### Lint Target Setup ########################################################################## + +set(LINT_TARGET lint) +set(LINT_SCRIPT ${CMAKE_SCRIPT_DIR}/lint.cmake) +add_custom_target( + ${LINT_TARGET} + COMMAND ${CMAKE_COMMAND} -P ${LINT_SCRIPT} +) + ### Install ################################################################################# # Install Includes file(GLOB folders ${${PROJECT_NAME}_INCLUDE_DIRS}/*) install(DIRECTORY ${folders} DESTINATION include) + + 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() + |