CLangFormat.cmake 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 2 or (at your option)
  6. # version 3 of the License.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. set(EXCLUDED_DIRS
  16. # third-party directories
  17. src/thirdparty
  18. # objective-c directories
  19. src/quickunlock/touchid
  20. src/autotype/mac
  21. src/gui/osutils/macutils)
  22. set(EXCLUDED_FILES
  23. # third-party files
  24. src/streams/qtiocompressor.\\*
  25. src/gui/KMessageWidget.\\*
  26. src/gui/MainWindowAdaptor.\\*
  27. src/gui/tag/TagsEdit.\\*
  28. tests/modeltest.\\*
  29. # objective-c files
  30. src/core/ScreenLockListenerMac.\\*)
  31. set(FIND_EXCLUDE_DIR_EXPR "")
  32. foreach(EXCLUDE ${EXCLUDED_DIRS})
  33. list(APPEND FIND_EXCLUDE_DIR_EXPR -o -path "${EXCLUDE}" -prune)
  34. endforeach()
  35. set(FIND_EXCLUDE_FILE_EXPR "")
  36. foreach(EXCLUDE ${EXCLUDED_FILES})
  37. if(FIND_EXCLUDE_FILE_EXPR)
  38. list(APPEND FIND_EXCLUDE_FILE_EXPR -o)
  39. endif()
  40. list(APPEND FIND_EXCLUDE_FILE_EXPR -path "${EXCLUDE}")
  41. endforeach()
  42. if(FIND_EXCLUDE_FILE_EXPR)
  43. set(FIND_EXCLUDE_FILE_EXPR -a -not "\\(" ${FIND_EXCLUDE_FILE_EXPR} "\\)")
  44. endif()
  45. add_custom_target(format)
  46. add_custom_command(
  47. TARGET format
  48. PRE_BUILD
  49. COMMAND find src tests "\\(" -name "\\*.h" -o -name "\\*.cpp" ${FIND_EXCLUDE_DIR_EXPR} "\\)"
  50. ${FIND_EXCLUDE_FILE_EXPR} -type f -print0 | xargs -0 -P0 -n10 clang-format -style=file -i
  51. COMMENT "Formatting source files..."
  52. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})