Skip to content

fix: CMakeRun defaults to Debug configuration regardless of build type.#318

Merged
Civitasv merged 1 commit intoCivitasv:masterfrom
UtterVitriol:master
May 17, 2025
Merged

fix: CMakeRun defaults to Debug configuration regardless of build type.#318
Civitasv merged 1 commit intoCivitasv:masterfrom
UtterVitriol:master

Conversation

@UtterVitriol
Copy link
Copy Markdown
Contributor

@UtterVitriol UtterVitriol commented May 14, 2025

When executing a :CMakeRun with the build type of "Release", the target is attempted to be executed from the nonexistent "\Release\Debug" directory.

C:\Users\uttervitriol\source\repos\learn_cmake>cmd /C "cd C:\Users\uttervitriol\source\repos\learn_cmake\out\Release\Debug\ && .\DoThing.exe
"& echo %errorlevel% > C:\Users\uttervitriol\AppData\Local\nvim-data\cmake-tools-tmp\exit_code && del /Q C:\Users\uttervitriol\AppData\Local
\nvim-data\cmake-tools-tmp\.lock
The system cannot find the path specified.

After looking into it, it seems that the function Config:get_codemodel_targets() contains the bug producing this error.

The file (path_to_cmake)/out/(Release/Debug/etc)/.cmake/api/v1/replycodmodel.....json contains a key "configurations" whose value is an array of configurations for different build types (Release, Debug, etc).

Inside of Config:get_codemodel_targets() is this line:

return Result:new(Types.SUCCESS, codemodel_json["configurations"][1]["targets"], "find it")

codemodel_json["configurations"][1] This simply grabs the first configuration in the array regardless of the build type (in my case it seems to always be Debug).

I replaced the above line of code with the snippet below:

  for _, config in ipairs(codemodel_json["configurations"]) do
    if config["name"] == self.build_type then
      return Result:new(Types.SUCCESS, config["targets"], "find it")
    end
  end
  return Result:new(Types.CANNOT_FIND_CODEMODEL_FILE, nil, "Unable to find codemodel file")

This simply loops through the array of configurations, checking its name against the currently selected build type.
I'm not sure if it's possible for the current build type to not be in the codemodel file, so I added a error at the end.

After changes:

C:\Users\uttervitriol\source\repos\learn_cmake>cmd /C "cd C:\Users\uttervitriol\source\repos\learn_cmake\out\Release\Release\ && .\DoThing.exe"& echo %errorlevel% > C:\Users\uttervitriol\AppData\Local\nvim-data\cmake-tools-tmp\exit_code && del /Q C:\Users\uttervitriol\
AppData\Local\nvim-data\cmake-tools-tmp\.lock
Why hello there

main.cpp

#include <cstdio>
int
main ()
{
    printf("Why hello there\n");
}

@UtterVitriol UtterVitriol changed the title fix: get_codemodel_targets build type only returning Debug fix: CMakeRun defaults to Debug configuration regardless of build type. May 15, 2025
@Civitasv
Copy link
Copy Markdown
Owner

Thank you for addressing this!​​

The root cause was indeed a compatibility issue with ​​Multi-Configuration Generators​​ (e.g., Visual Studio, Xcode, and Ninja Multi-Config). While the plugin currently lacks full support for these workflows.

If you encounter similar issues, I’d greatly appreciate if you could report them here. Your contributions help improve the tool for everyone! 🙌

@Civitasv Civitasv merged commit 72abb00 into Civitasv:master May 17, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants