@@ -4,6 +4,18 @@ add_requires("catch2 2.13.9")
4
4
set_arch (" x64" )
5
5
set_plat (" windows" )
6
6
7
+ add_repositories (" iconeus-repo https://github.com/Iconeus/xmake-repo.git" )
8
+
9
+ option (" cdm.format" )
10
+ set_default (true )
11
+ set_showmenu (true )
12
+ set_description (" Set this option if you wish for the source code to be auto-formatted" )
13
+ option_end ()
14
+
15
+ if has_config (" cdm.format" ) then
16
+ add_requires (" clang-format 16.0.6" )
17
+ end
18
+
7
19
-- Generates a hash key made of packages confs/version, for CI
8
20
task (" dephash" )
9
21
on_run (function ()
@@ -29,43 +41,10 @@ task("dephash")
29
41
}
30
42
task_end ()
31
43
32
- rule (" format_before_build" )
33
- before_build (function (target )
34
- import (" detect.sdks.find_vstudio" )
35
- import (" lib.detect.find_program" )
36
-
37
- local vstudio = find_vstudio ()
38
- local vs = vstudio [" 2022" ]
39
- if vs == nil then
40
- vs = vstudio [" 2019" ]
41
-
42
- if vs == nil then
43
- raise (" Visual Studio 2022 or 2019 is required" )
44
- end
45
- end
46
-
47
- local clangformat = find_program (" clang-format.exe" , {envs = {PATH = vs .vcvarsall .x64 .PATH }})
48
- if clangformat == nil or clangformat == " " then
49
- print (" clang-format.exe not found in" , vs .vcvarsall .x64 .PATH )
50
- raise (" clang-format is required. Please install the C++ Clang Compiler for Windows >= 15.0.1 in Visual Studio Install Individual components (Tools/Get Tools and Features...)" )
51
- end
52
-
53
- local sourcefiles = target :sourcefiles ()
54
- local headerfiles = target :headerfiles ()
55
-
56
- for k , v in pairs (sourcefiles ) do
57
- os .exec (clangformat .. " --style=file -i " .. v )
58
- end
59
- for k , v in pairs (headerfiles ) do
60
- os .exec (clangformat .. " --style=file -i " .. v )
61
- end
62
- end )
63
- rule_end ()
64
-
65
44
target (" cdm" )
66
45
set_kind (" phony" )
67
46
set_languages (" c++20" )
68
- add_rules (" format_before_build" )
47
+ add_rules (" @clang-format/ format_before_build" )
69
48
add_headerfiles (" *.hpp" )
70
49
add_includedirs (" ." )
71
50
target_end ()
@@ -99,7 +78,7 @@ for _,v in pairs(tests) do
99
78
set_kind (" binary" )
100
79
set_languages (" c++20" )
101
80
add_deps (" cdm" )
102
- add_rules (" format_before_build" )
81
+ add_rules (" @clang-format/ format_before_build" )
103
82
add_files (" tests/" .. v .. " .cpp" )
104
83
add_headerfiles (" *.hpp" )
105
84
add_headerfiles (" tests/*.hpp" )
0 commit comments