Skip to content

Commit 43232b6

Browse files
DenzellceWolf
authored andcommitted
resolve compile commands target lazily
1 parent 906fd48 commit 43232b6

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

lua/cmake-tools/const.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ local const = {
2121
-- copy: this will automatically copy compile commands file to target
2222
-- lsp: this will automatically set compile commands file location using lsp
2323
-- none: this will make this option ignored
24-
target = vim.loop.cwd(), -- path to directory, this is used only if action == "soft_link" or action == "copy"
24+
---@type string|fun(): string
25+
target = vim.loop.cwd, -- path or function returning path to directory, this is used only if action == "soft_link" or action == "copy"
2526
},
2627
cmake_kits_path = nil, -- this is used to specify global cmake kits path, see CMakeKits for detailed usage
2728
cmake_variants_message = {

lua/cmake-tools/init.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,11 @@ function cmake.copy_compile_commands()
14821482
end
14831483

14841484
local source = config:build_directory_path() .. "/compile_commands.json"
1485-
local destination = const.cmake_compile_commands_options.target .. "/compile_commands.json"
1485+
local target = const.cmake_compile_commands_options.target
1486+
if type(target) == "function" then
1487+
target = target()
1488+
end
1489+
local destination = target .. "/compile_commands.json"
14861490
utils.copyfile(source, destination)
14871491
end
14881492

@@ -1492,7 +1496,11 @@ function cmake.compile_commands_from_soft_link()
14921496
end
14931497

14941498
local source = config:build_directory_path() .. "/compile_commands.json"
1495-
local destination = const.cmake_compile_commands_options.target .. "/compile_commands.json"
1499+
local target = const.cmake_compile_commands_options.target
1500+
if type(target) == "function" then
1501+
target = target()
1502+
end
1503+
local destination = target .. "/compile_commands.json"
14961504
utils.softlink(source, destination)
14971505
end
14981506

0 commit comments

Comments
 (0)