Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target filename #244

Open
jeanpaulrichter opened this issue Jun 24, 2024 · 4 comments
Open

target filename #244

jeanpaulrichter opened this issue Jun 24, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@jeanpaulrichter
Copy link

jeanpaulrichter commented Jun 24, 2024

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!

@jeanpaulrichter jeanpaulrichter added the enhancement New feature or request label Jun 24, 2024
@Civitasv
Copy link
Owner

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
Copy link
Author

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 :) .

@lceWolf
Copy link
Collaborator

lceWolf commented Jan 9, 2025

Can you please check whether this problem still exists after the last presets refactoring?

@jeanpaulrichter
Copy link
Author

As far as I can tell the problem persists, but maybe I am just doing it wrong, so here is my test CMakePresets.json :

{
    "version": 3,
    "cmakeMinimumRequired": {
      "major": 3,
      "minor": 26,
      "patch": 0
    },
    "configurePresets": [
      {
        "name": "linux-x64",
        "displayName": "Linux x64",
        "generator": "Ninja Multi-Config",
        "binaryDir": "${sourceDir}/obj/linux-x64",
        "architecture": {
          "value": "x64",
          "strategy": "external"
        },
        "cacheVariables": {
          "CMAKE_CONFIGURATION_TYPES": "Release;Debug"
        }
      }
    ],
    "buildPresets": [
      {
        "name": "linux_x64d",
        "displayName": "Linux x64 Debug",
        "configurePreset": "linux-x64",
        "configuration": "Debug"
      },
      {
        "name": "linux_x64",
        "displayName": "Linux x64 Release",
        "configurePreset": "linux-x64",
        "configuration": "Release"
      }
    ],
    "testPresets": [],
    "vendor": {
      "example.com/ExampleIDE/1.0": {
        "autoFormat": false
      }
    }
  }

Switching preset via :CMakeSelectBuildPreset I can build both obj/linux-x64/Debug/test and obj/linux-x64/Release/test .

But in both cases I fail to get the correct target path when build preset "Linux x64 Debug" is selected:

local target = cmake.get_launch_target()
local filename = cmake.get_model_info()[target].nameOnDisk
local path = cmake.get_launch_path(target) .. filename
-- path = ../obj/linux-x64/Release/test
local path = cmake.get_build_target_path()
-- path = ../obj/linux-x64/Release/test

But when I switch Debug and Release in CMakePresets.json :

"CMAKE_CONFIGURATION_TYPES": "Debug;Release"

get_build_target_path() will return obj/linux-x64/Debug/test even if I select "Linux x64 Release" with :CMakeSelectBuildPreset and successfully build /obj/linux-x64/Release/test via :CMakeBuild .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants