##// END OF EJS Templates
Remove ui files from clang-format
perrinel -
r238:84afba26f11f
parent child
Show More
@@ -1,128 +1,139
1 1 #
2 2 # use_clangformat.cmake
3 3 #
4 4 # The following functions are defined in this document:
5 5 #
6 6
7 7 # ADD_CLANGFORMAT_TARGETS(<globExpression> ...
8 8 # [ADD_TO_ALL]
9 9 # [NAME <name>]
10 10 # [NAME_ALL <nameall>]
11 11 # [STYLE style]
12 12 # [RECURSE])
13 13 #
14 14 # Two custom targets will be created:
15 15 # * format_reports is run as part of the build, and is not rerun unless one of
16 16 # the file formatted is modified (only created if ADD_TO_ALL is provided);
17 17 # * format must be explicitely called (make format) and is rerun even if the
18 18 # files to format have not been modified. To achieve this behavior, the commands
19 19 # used in this target pretend to produce a file without actually producing it.
20 20 # Because the output file is not there after the run, the command will be rerun
21 21 # again at the next target build.
22 22 #
23 23 # If ADD_TO_ALL is provided then a target will be added to the default build
24 24 # targets so that each time a source file is compiled, it is formatted with
25 25 # clang-format.
26 26 #
27 27 # NAME and NAME_ALL customize the name of the targets (format and format_reports
28 28 # by default respectively).
29 29 #
30 30 # STYLE sets the style used by clang-format (default to "file").
31 31 #
32 32 # RECURSE selects if the glob expressions should be applied recursively or not.
33 33 FUNCTION(ADD_CLANGFORMAT_TARGETS)
34 34 # Default values
35 35 SET(target "format")
36 36 SET(target_all "format_all")
37 37 SET(style "file")
38 38 SET(recurse OFF)
39 39 SET(addToAll OFF)
40 40 SET(globs)
41 41
42 42 # Parse the options
43 43 MATH(EXPR lastIdx "${ARGC} - 1")
44 44 SET(i 0)
45 45 WHILE(i LESS ${ARGC})
46 46 SET(arg "${ARGV${i}}")
47 47 IF("${arg}" STREQUAL "ADD_TO_ALL")
48 48 SET(addToAll ON)
49 49 ELSEIF("${arg}" STREQUAL "NAME")
50 50 clangformat_incr(i)
51 51 SET(target "${ARGV${i}}")
52 52 ELSEIF("${arg}" STREQUAL "NAME_ALL")
53 53 clangformat_incr(i)
54 54 SET(target_all "${ARGV${i}}")
55 55 ELSEIF("${arg}" STREQUAL "STYLE")
56 56 clangformat_incr(i)
57 57 SET(style "${ARGV${i}}")
58 58 ELSEIF("${arg}" STREQUAL "RECURSE")
59 59 SET(recurse ON)
60 60 ELSE()
61 61 LIST(APPEND globs ${arg})
62 62 ENDIF()
63 63 clangformat_incr(i)
64 64 ENDWHILE()
65 65
66
66 67 # Retrieve source files to format
67 68 IF(recurse)
68 69 FILE(GLOB_RECURSE srcs ${globs})
69 70 ELSE()
70 71 FILE(GLOB srcs ${globs})
71 72 ENDIF()
72 73
73 74 IF(NOT CLANGFORMAT_EXECUTABLE)
74 75 MESSAGE(FATAL_ERROR "Unable to find clang-format executable")
75 76 ENDIF()
76 77
77 78 # Format each source file with clang-format
78 79 SET(touchedFiles)
79 80 SET(fakedTouchedFiles)
80 81 SET(reportNb 0)
81 82 # Create the directory where the touched files will be saved
82 83 SET(formatDirectory "${CMAKE_CURRENT_BINARY_DIR}/format")
83 84 FILE(MAKE_DIRECTORY ${formatDirectory})
85 # STRING(REPLACE "*.ui" "" srcs ${srcs})
86 FOREACH(item ${globs})
87 STRING(REGEX MATCH ".*\.ui$" item ${item})
88 IF(item)
89 LIST(APPEND UIS ${item})
90 ENDIF(item)
91 ENDFOREACH(item ${globs})
92
93 LIST(REMOVE_ITEM srcs ${UIS})
94 message("format lang: ${srcs}" )
84 95 FOREACH (s ${srcs})
85 96 SET(touchedFile ${formatDirectory}/format_touchedfile_${reportNb})
86 97 IF(addToAll)
87 98 ADD_CUSTOM_COMMAND(
88 99 OUTPUT ${touchedFile}
89 100 COMMAND ${CLANGFORMAT_EXECUTABLE}
90 101 -style="${style}"
91 102 -i
92 103 ${s}
93 104 # Create a file so that this command is executed only if the source
94 105 # file is modified
95 106 COMMAND ${CMAKE_COMMAND} -E touch ${touchedFile}
96 107 DEPENDS ${s}
97 108 COMMENT "Formatting code with clang-format of ${s}"
98 109 )
99 110 ENDIF()
100 111
101 112 SET(fakedTouchedFile ${formatDirectory}/format_fakedtouchedfile_${reportNb})
102 113 ADD_CUSTOM_COMMAND(
103 114 OUTPUT ${fakedTouchedFile}
104 115 COMMAND ${CLANGFORMAT_EXECUTABLE}
105 116 -style="${style}"
106 117 -i
107 118 ${s}
108 119 DEPENDS ${s}
109 120 COMMENT "Formatting code with clang-format of ${s}"
110 121 )
111 122
112 123 LIST(APPEND touchedFiles ${touchedFile})
113 124 LIST(APPEND fakedTouchedFiles ${fakedTouchedFile})
114 125 clangformat_incr(reportNb)
115 126 ENDFOREACH()
116 127
117 128 # Create the custom targets that will trigger the custom command created
118 129 # previously
119 130 IF(addToAll)
120 131 ADD_CUSTOM_TARGET(${target_all} ALL DEPENDS ${touchedFiles})
121 132 ENDIF()
122 133 ADD_CUSTOM_TARGET(${target} DEPENDS ${fakedTouchedFiles})
123 134
124 135 ENDFUNCTION(ADD_CLANGFORMAT_TARGETS)
125 136
126 137 macro(clangformat_incr var_name)
127 138 math(EXPR ${var_name} "${${var_name}} + 1")
128 139 endmacro()
General Comments 0
You need to be logged in to leave comments. Login now