From cfecefdf1a24ea690e0613b8c5d219b0511785c5 Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Thu, 1 Jan 2026 02:58:32 +0100 Subject: Retrieve targets from MakeFile --- lua/aotrix/compile.lua | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'lua/aotrix/compile.lua') 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 -- cgit v1.2.3