summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/aotrix/compile.lua18
1 files changed, 15 insertions, 3 deletions
diff --git a/lua/aotrix/compile.lua b/lua/aotrix/compile.lua
index 3fcb54c..9227e6c 100644
--- a/lua/aotrix/compile.lua
+++ b/lua/aotrix/compile.lua
@@ -62,7 +62,7 @@ function executeCommandInTerminal(command)
-- 'clear' is used to hide the command
local exit_message = "\nPress enter to exit..."
vim.api.nvim_chan_send(channel,
- "clear && " .. command .. " && echo '" .. exit_message .. "' && read -s && exit" .. "\n")
+ "clear && " .. command .. "; echo '" .. exit_message .. "' && read -s && exit" .. "\n")
end
---Compiles a target
@@ -72,8 +72,20 @@ function compileTarget()
function compile(pTarget)
if not (pTarget == nil) and string.len(pTarget) > 0 then
createFloatingTerminal()
- local command = "cmake --build build --target " .. pTarget .. " && ./build/" .. pTarget
- executeCommandInTerminal(command)
+ local build_dir = "build"
+ local commandTable = { "if [ ! -d " .. build_dir .. " ]; then mkdir " .. build_dir,
+ "cmake -S . -B " .. build_dir .. "; fi",
+ "cmake --build " .. build_dir .. " --target " .. pTarget,
+ build_dir .. "/" .. pTarget
+ }
+ local commandConcatenation = ""
+ for i, command in ipairs(commandTable) do
+ commandConcatenation = commandConcatenation .. command
+ if i < #commandTable then
+ commandConcatenation = commandConcatenation .. " && "
+ end
+ end
+ executeCommandInTerminal(commandConcatenation)
end
end