Skip to content

Commit 113224a

Browse files
fix autoformatting
1 parent 6e69205 commit 113224a

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

xmake.lua

+14-35
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ add_requires("catch2 2.13.9")
44
set_arch("x64")
55
set_plat("windows")
66

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+
719
-- Generates a hash key made of packages confs/version, for CI
820
task("dephash")
921
on_run(function ()
@@ -29,43 +41,10 @@ task("dephash")
2941
}
3042
task_end()
3143

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-
6544
target("cdm")
6645
set_kind("phony")
6746
set_languages("c++20")
68-
add_rules("format_before_build")
47+
add_rules("@clang-format/format_before_build")
6948
add_headerfiles("*.hpp")
7049
add_includedirs(".")
7150
target_end()
@@ -99,7 +78,7 @@ for _,v in pairs(tests) do
9978
set_kind("binary")
10079
set_languages("c++20")
10180
add_deps("cdm")
102-
add_rules("format_before_build")
81+
add_rules("@clang-format/format_before_build")
10382
add_files("tests/"..v..".cpp")
10483
add_headerfiles("*.hpp")
10584
add_headerfiles("tests/*.hpp")

0 commit comments

Comments
 (0)