blob: c8bef796c986ea7aa2d460f7b597a7d9e4e3bfa6 (
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
|
-- Copyright (c) 2026 Progmasoft.
-- SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-2.0
-- Materialize the checked-in CMake template of the engine's configuration
-- header 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 user configuration header under output_root.
--- The generated path is output_root/Progmasoft/Catch3/UserConfig.hpp.
function M.generate(output_root, repository_root)
local template_path = repository_root .. "/src/Progmasoft/Catch3/UserConfig.hpp.in"
local template = read_file(template_path)
-- Neither Xmake nor Premake interprets CMake's #cmakedefine directives;
-- every feature toggle stays at its default.
local configured = template:gsub(
"#cmakedefine%s+([%w_]+)%s*([^\r\n]*)",
function(name)
return "/* #undef " .. name .. " */"
end
)
configured = configured:gsub("@CATCH_CONFIG_FALLBACK_STRINGIFIER@", "")
local output_dir = output_root .. "/Progmasoft/Catch3"
os.mkdir(output_dir)
write_file(output_dir .. "/UserConfig.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
|