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