CMakeLists.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #=============================================================================
  2. # CMake - Cross Platform Makefile Generator
  3. # Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. #
  5. # Distributed under the OSI-approved BSD License (the "License");
  6. # see accompanying file Copyright.txt for details.
  7. #
  8. # This software is distributed WITHOUT ANY WARRANTY; without even the
  9. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. # See the License for more information.
  11. #=============================================================================
  12. #-----------------------------------------------------------------------------
  13. # CMake uses KWStyle for checking the coding style
  14. # Search for a built-from-source KWStyle under Dashboards/Support on a typical
  15. # dashboard machines:
  16. #
  17. set(home "$ENV{HOME}")
  18. if(NOT home)
  19. string(REPLACE "\\" "/" home "$ENV{USERPROFILE}")
  20. endif()
  21. find_program(KWSTYLE_EXECUTABLE
  22. NAMES KWStyle
  23. PATHS
  24. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware Inc.\\KWStyle 1.0.0]/bin"
  25. "${home}/Dashboards/Support/KWStyle/bin"
  26. )
  27. mark_as_advanced(KWSTYLE_EXECUTABLE)
  28. set(CMAKE_USE_KWSTYLE_DEFAULT OFF)
  29. if(KWSTYLE_EXECUTABLE)
  30. set(CMAKE_USE_KWSTYLE_DEFAULT ON)
  31. endif()
  32. option(CMAKE_USE_KWSTYLE
  33. "Add StyleCheck target and KWStyle test: run KWStyle to check for coding standard violations."
  34. ${CMAKE_USE_KWSTYLE_DEFAULT})
  35. mark_as_advanced(CMAKE_USE_KWSTYLE)
  36. if(CMAKE_USE_KWSTYLE)
  37. option(KWSTYLE_USE_VIM_FORMAT "Set KWStyle to generate errors with a VIM-compatible format." OFF)
  38. option(KWSTYLE_USE_MSVC_FORMAT "Set KWStyle to generate errors with a VisualStudio-compatible format." OFF)
  39. mark_as_advanced(KWSTYLE_USE_VIM_FORMAT)
  40. mark_as_advanced(KWSTYLE_USE_MSVC_FORMAT)
  41. if(KWSTYLE_USE_VIM_FORMAT)
  42. set(KWSTYLE_ARGUMENTS -vim ${KWSTYLE_ARGUMENTS})
  43. endif()
  44. if(KWSTYLE_USE_MSVC_FORMAT)
  45. set(KWSTYLE_ARGUMENTS -msvc ${KWSTYLE_ARGUMENTS})
  46. endif()
  47. configure_file(${CMake_SOURCE_DIR}/Utilities/KWStyle/CMake.kws.xml.in
  48. ${CMake_BINARY_DIR}/CMake.kws.xml)
  49. configure_file(${CMake_SOURCE_DIR}/Utilities/KWStyle/CMakeMoreChecks.kws.xml.in
  50. ${CMake_BINARY_DIR}/CMakeMoreChecks.kws.xml)
  51. configure_file(${CMake_SOURCE_DIR}/Utilities/KWStyle/CMakeFiles.txt.in
  52. ${CMake_BINARY_DIR}/CMakeKWSFiles.txt)
  53. add_custom_command(
  54. OUTPUT ${CMake_BINARY_DIR}/KWStyleReport.txt
  55. COMMAND ${KWSTYLE_EXECUTABLE}
  56. ARGS -xml ${CMake_BINARY_DIR}/CMake.kws.xml -o ${CMake_SOURCE_DIR}/Utilities/KWStyle/CMakeOverwrite.txt -v ${KWSTYLE_ARGUMENTS} -D ${CMake_BINARY_DIR}/CMakeKWSFiles.txt
  57. COMMENT "Coding Style Checker"
  58. )
  59. add_custom_target(MoreStyleChecks
  60. COMMAND ${KWSTYLE_EXECUTABLE}
  61. -xml ${CMake_BINARY_DIR}/CMakeMoreChecks.kws.xml -html ${CMake_BINARY_DIR}/html -o ${CMake_SOURCE_DIR}/Utilities/KWStyle/CMakeOverwrite.txt -v ${KWSTYLE_ARGUMENTS} -D ${CMake_BINARY_DIR}/CMakeKWSFiles.txt
  62. COMMENT "Coding Style Checker, more checks enabled"
  63. )
  64. add_custom_target(StyleCheck DEPENDS ${CMake_BINARY_DIR}/KWStyleReport.txt)
  65. endif()