Civitasv / cmake-tools.nvim

CMake integration in Neovim
GNU General Public License v3.0
324 stars 54 forks source link

target filename #244

Open jeanpaulrichter opened 2 weeks ago

jeanpaulrichter commented 2 weeks ago

Hi, this is more of a question to be honest: I need the full path of a built executable. Eventually I came up with this:

local target cmake.get_launch_target()
local filename = cmake.get_model_info()[target].nameOnDisk
local path = cmake.get_launch_path(target) .. filename

which works fine, but I was wondering if there is a simpler/preferred way of achieving this without the kind of undocumented get_model_info()? If not, maybe a cmake.get_launch_file or something would be worth considering.

EDIT: another thing: get_launch_path() always returns the same path even if the current build preset changes the configuration. i.e:

"configurePresets": [
{
...
"generator": "Ninja Multi-Config",
"cacheVariables": {
   "CMAKE_CONFIGURATION_TYPES": "Release;RelWithDebInfo;Debug"
}
...
}],
"buildPresets": [
  {
   ...
   configuration: "Debug",
  },
  {
   ...
   configuration: "Release",
  },
]

Anyways thanks for the great plugin!

Civitasv commented 1 week ago

I've added two getters: Use cmake.get_launch_target_path() to get full path of launch target path. Use cmake.get_build_target_path() to get full path of build target path.

jeanpaulrichter commented 1 week ago

thx! The "Ninja Multi-Config" generator might still be a minor problem though. Because it generates all configurations in CMAKE_CONFIGURATION_TYPES at once in the same folder, RUNTIME_OUTPUT_DIRECTORY is also the same, but with subfolders for "Release", "Debug" etc. cmake.get_build_target_path() & cmake.get_launch_target_path() atm seem to ignore the currently selected buildPreset and its configuration: They always return the path of the first configuration in CMAKE_CONFIGURATION_TYPES. So if CMAKE_CONFIGURATION_TYPES="Debug;Release" they will return the path of the debug target even if the selected buildPreset sets the configuration to "Release". Most of the time I'm only interested in the debug target anyway so I kinda can live with it though :) .