blob: 5067d247441dc2b934eb6046acd36f77365064a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
-- Copyright (c) 2026 Progmasoft.
-- SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1
-- Materialize Catch2's checked-in CMake template for non-CMake build tools.
-- Keeping the template as the source of truth avoids maintaining a second
-- copy of upstream configuration declarations under a different license.
local M = {}
local function read_file(file_path)
local file = assert(io.open(file_path, "rb"), "cannot read " .. file_path)
local contents = file:read("*a")
file:close()
return contents
end
local function write_file(file_path, contents)
local file = assert(io.open(file_path, "wb"), "cannot write " .. file_path)
file:write(contents)
file:close()
end
--- Generates the default Catch2 user configuration header under output_root.
--- The generated path is output_root/catch2/catch_user_config.hpp.
function M.generate(output_root, repository_root)
local template_path = repository_root .. "/src/catch2/catch_user_config.hpp.in"
local template = read_file(template_path)
-- Neither Xmake nor Premake interprets CMake's #cmakedefine directives.
-- All feature toggles stay at Catch2's defaults; the two value settings
-- match Catch2's own CMake defaults and the root Bazel configuration.
local configured = template:gsub(
"#cmakedefine%s+([%w_]+)%s*([^\r\n]*)",
function(name)
if name == "CATCH_CONFIG_DEFAULT_REPORTER" then
return '#define CATCH_CONFIG_DEFAULT_REPORTER "console"'
elseif name == "CATCH_CONFIG_CONSOLE_WIDTH" then
return "#define CATCH_CONFIG_CONSOLE_WIDTH 80"
end
return "/* #undef " .. name .. " */"
end
)
configured = configured:gsub('"@CATCH_CONFIG_DEFAULT_REPORTER@"', '"console"')
configured = configured:gsub("@CATCH_CONFIG_CONSOLE_WIDTH@", "80")
configured = configured:gsub("@CATCH_CONFIG_FALLBACK_STRINGIFIER@", "")
local output_dir = output_root .. "/catch2"
os.mkdir(output_dir)
write_file(output_dir .. "/catch_user_config.hpp", configured)
end
-- Xmake imports call the module's main entry point; Premake can use generate.
function main(output_root, repository_root)
return M.generate(output_root, repository_root)
end
return M
|