diff options
| author | Aotrix <[email protected]> | 2026-01-01 02:58:32 +0100 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2026-01-01 02:58:32 +0100 |
| commit | cfecefdf1a24ea690e0613b8c5d219b0511785c5 (patch) | |
| tree | db85fbfec2b9964794bf3dbf7019ec9b52da46c6 /lua | |
| parent | 8e58b7d7dcc73d1d8d53de15319fb98984c94905 (diff) | |
Retrieve targets from MakeFile
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/aotrix/compile.lua | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/lua/aotrix/compile.lua b/lua/aotrix/compile.lua index 9227e6c..9b0c58b 100644 --- a/lua/aotrix/compile.lua +++ b/lua/aotrix/compile.lua @@ -1,3 +1,5 @@ +local build_dir + ---Generates a table with available targets --- ---@return table @@ -5,12 +7,14 @@ function tableOfTargets() -- Ugly way to retrieve targets, but it works -- Do not hesitate to change the command - local generatorExecutable = io.popen([[sed -n "s/add_executable(\(.*\))/\1/p" CMakeLists.txt|sed "s/ .*//p"|uniq]]) - :lines() + local command = "cmake --build " .. build_dir .. + " -t help|sed 1d|grep -v -e " .. [["]] .. + "all\\|clean\\|depend\\|edit_cache\\|rebuild_cache" .. + [["]] .. " -e " .. [["]] .. "\\.\\{3\\} .*\\..*$" .. + [["]] .. "|sed " .. [["]] .. "s/\\.\\.\\. //" .. [["]] + local generatorExecutable = io.popen(command):lines() local choiceTable = {} - for line in generatorExecutable do - table.insert(choiceTable, line) - end + for line in generatorExecutable do table.insert(choiceTable, line) end return choiceTable end @@ -19,13 +23,9 @@ end ---@return nil function chooseTarget(pCallbackFunction) vim.ui.select(tableOfTargets(), { - prompt = 'Choose target:', - format_item = function(item) - return item - end, - }, - pCallbackFunction - ) + prompt = 'Choose target:', + format_item = function(item) return item end + }, pCallbackFunction) end ---@return nil @@ -62,7 +62,14 @@ 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 + +---@return nil +function defineBuildFolderPath() + -- TODO: One might not want a directory called "build" + build_dir = "build" end ---Compiles a target @@ -72,9 +79,7 @@ function compileTarget() function compile(pTarget) if not (pTarget == nil) and string.len(pTarget) > 0 then createFloatingTerminal() - local build_dir = "build" - local commandTable = { "if [ ! -d " .. build_dir .. " ]; then mkdir " .. build_dir, - "cmake -S . -B " .. build_dir .. "; fi", + local commandTable = { "cmake --build " .. build_dir .. " --target " .. pTarget, build_dir .. "/" .. pTarget } @@ -89,6 +94,7 @@ function compileTarget() end end + defineBuildFolderPath() chooseTarget(compile) end |
