humotion / stylecheck / CpplintWrapper.cmake @ 06d6a491
History | View | Annotate | Download (3.588 KB)
| 1 | 6a2d467f | Simon Schulz | # We use Google's cpplint for style checking. |
|---|---|---|---|
| 2 | # This is optional and graceful; meaning we do not quit building even if there are warnings. |
||
| 3 | # We are not that pedantic. However, we will keep an eye on the count of warnings. |
||
| 4 | # Related parameters: |
||
| 5 | # Setting variable ENABLE_CPPLINT to true will enable cpplint. |
||
| 6 | set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5 2.4) # Prefer Python-2 |
||
| 7 | find_package(PythonInterp) |
||
| 8 | if(PYTHONINTERP_FOUND) |
||
| 9 | message(STATUS "Found Python. Python version is ${PYTHON_VERSION_STRING}.")
|
||
| 10 | if(${PYTHON_VERSION_MAJOR} EQUAL 3)
|
||
| 11 | message(WARNING "OUCH! The Python found is Python 3. Cpplint.py doesn't run on it so far.") |
||
| 12 | message(WARNING "Cpplint won't detect errors. Install Python 2 to fix this issue.") |
||
| 13 | endif(${PYTHON_VERSION_MAJOR} EQUAL 3)
|
||
| 14 | if(ENABLE_CPPLINT) |
||
| 15 | set(RUN_CPPLINT true) |
||
| 16 | else(ENABLE_CPPLINT) |
||
| 17 | message(STATUS "ENABLE_CPPLINT was not given. Skipped running cpplint") |
||
| 18 | set(RUN_CPPLINT false) |
||
| 19 | endif(ENABLE_CPPLINT) |
||
| 20 | else(PYTHONINTERP_FOUND) |
||
| 21 | message(STATUS "python executable not found. Skipped running cpplint") |
||
| 22 | set(RUN_CPPLINT false) |
||
| 23 | endif(PYTHONINTERP_FOUND) |
||
| 24 | |||
| 25 | # Followings are our coding convention. |
||
| 26 | set(LINT_FILTER) # basically everything Google C++ Style recommends. Except... |
||
| 27 | |||
| 28 | # This the only rule cpplint.py disables by default. Enable it. |
||
| 29 | # However, the default implementation of build/include_alpha in cpplint.py is a bit sloppy. |
||
| 30 | # It doesn't correctly take care of "/" in include. |
||
| 31 | # Thus we changed cpplint.py for this. |
||
| 32 | set(LINT_FILTER ${LINT_FILTER},+build/include_alpha)
|
||
| 33 | |||
| 34 | # for logging and debug printing, we do need streams |
||
| 35 | set(LINT_FILTER ${LINT_FILTER},-readability/streams)
|
||
| 36 | |||
| 37 | # We use C++11 with some restrictions. |
||
| 38 | # set(LINT_FILTER ${LINT_FILTER},-build/c++11)
|
||
| 39 | # |
||
| 40 | |||
| 41 | # Consider disabling them if they cause too many false positives. |
||
| 42 | # set(LINT_FILTER ${LINT_FILTER},-build/include_what_you_use)
|
||
| 43 | # set(LINT_FILTER ${LINT_FILTER},-build/include_order)
|
||
| 44 | |||
| 45 | mark_as_advanced(LINT_FILTER) |
||
| 46 | |||
| 47 | set(LINT_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/cpplint.py")
|
||
| 48 | mark_as_advanced(LINT_SCRIPT) |
||
| 49 | set(LINT_WRAPPER "${CMAKE_CURRENT_LIST_DIR}/cpplint-wrapper.py")
|
||
| 50 | mark_as_advanced(LINT_WRAPPER) |
||
| 51 | |||
| 52 | # 100 chars per line, which is suggested as an option in the style guide |
||
| 53 | set(LINT_LINELENGTH 100) |
||
| 54 | mark_as_advanced(LINT_LINELENGTH) |
||
| 55 | |||
| 56 | # Registers a CMake target to run cpplint over all files in the given folder. |
||
| 57 | # Parameters: |
||
| 58 | # target_name: |
||
| 59 | # The name of the target to define. Your program should depend on it to invoke cpplint. |
||
| 60 | # src_folder: |
||
| 61 | # The folder to recursively run cpplint. |
||
| 62 | # root_folder: |
||
| 63 | # The root folder used to determine desired include-guard comments. |
||
| 64 | # bin_folder: |
||
| 65 | # The temporary build folder to store a cpplint history file. |
||
| 66 | function(CPPLINT_RECURSIVE target_name src_folder root_folder bin_folder) |
||
| 67 | if(RUN_CPPLINT) |
||
| 68 | message(STATUS "${target_name}: src=${src_folder}, root=${root_folder}, bin=${bin_folder}")
|
||
| 69 | file(MAKE_DIRECTORY ${bin_folder})
|
||
| 70 | add_custom_target(${target_name}
|
||
| 71 | COMMAND |
||
| 72 | ${PYTHON_EXECUTABLE} ${LINT_WRAPPER}
|
||
| 73 | --cpplint-file=${LINT_SCRIPT}
|
||
| 74 | --history-file=${bin_folder}/.lint_history
|
||
| 75 | --linelength=${LINT_LINELENGTH}
|
||
| 76 | --filter=${LINT_FILTER}
|
||
| 77 | --root=${root_folder}
|
||
| 78 | ${src_folder}
|
||
| 79 | WORKING_DIRECTORY ${bin_folder}
|
||
| 80 | COMMENT "[CPPLINT-Target] ${src_folder}")
|
||
| 81 | else(RUN_CPPLINT) |
||
| 82 | add_custom_target(${target_name} COMMAND ${CMAKE_COMMAND} -E echo NoLint)
|
||
| 83 | endif(RUN_CPPLINT) |
||
| 84 | endfunction(CPPLINT_RECURSIVE) |