CLangFormat.cmake 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/zxcvbn/
  18. # objective-c directories
  19. src/touchid/
  20. src/autotype/mac/
  21. src/gui/osutils/macutils/)
  22. set(EXCLUDED_FILES
  23. # third-party files
  24. streams/qtiocompressor.cpp
  25. streams/qtiocompressor.h
  26. gui/KMessageWidget.h
  27. gui/KMessageWidget.cpp
  28. gui/MainWindowAdaptor.h
  29. gui/MainWindowAdaptor.cpp
  30. crypto/ssh/bcrypt_pbkdf.cpp
  31. crypto/ssh/blf.h
  32. crypto/ssh/blowfish.c
  33. tests/modeltest.cpp
  34. tests/modeltest.h
  35. # objective-c files
  36. core/ScreenLockListenerMac.h
  37. core/ScreenLockListenerMac.cpp)
  38. file(GLOB_RECURSE ALL_SOURCE_FILES RELATIVE ${CMAKE_SOURCE_DIR} src/*.cpp src/*.h tests/*.cpp tests/*.h)
  39. foreach(SOURCE_FILE ${ALL_SOURCE_FILES})
  40. foreach(EXCLUDED_DIR ${EXCLUDED_DIRS})
  41. string(FIND ${SOURCE_FILE} ${EXCLUDED_DIR} SOURCE_FILE_EXCLUDED)
  42. if(NOT ${SOURCE_FILE_EXCLUDED} EQUAL -1)
  43. list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
  44. endif()
  45. endforeach()
  46. foreach(EXCLUDED_FILE ${EXCLUDED_FILES})
  47. if(${SOURCE_FILE} MATCHES ".*${EXCLUDED_FILE}$")
  48. list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
  49. endif()
  50. endforeach()
  51. endforeach()
  52. add_custom_target(format)
  53. foreach(SOURCE_FILE ${ALL_SOURCE_FILES})
  54. add_custom_command(
  55. TARGET format
  56. PRE_BUILD
  57. COMMAND echo Formatting ${SOURCE_FILE}
  58. COMMAND clang-format -style=file -i \"${SOURCE_FILE}\"
  59. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
  60. endforeach()