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

Add a command that returns the resolved value of cmake.buildDirectory #695

Closed
zrno opened this issue May 31, 2019 · 9 comments
Closed

Add a command that returns the resolved value of cmake.buildDirectory #695

zrno opened this issue May 31, 2019 · 9 comments
Labels
duplicate a duplicate of an already present issue enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: debug/launch

Comments

@zrno
Copy link

zrno commented May 31, 2019

Brief Issue Summary

Using ${config:cmake.buildDirectory} in launch.json with visual cpp debugger doesn't work. After a successful cmake configure the ${config:cmake.buildDirectory} is not correctly resolved. In my example in settings.json the cmake.buildDirectory looks like this:
"cmake.buildDirectory": "${workspaceFolder}/../CMakeBuild/vscode/NSW-51770/${buildKit}/${buildType}",

The ${buildKit} and ${buildType} are not resolved but just copied into the resulting string.

Expected:

cmake.buildDirectory is correctly resolved

Platform and Versions

  • Operating System: Windows
  • CMake Version: 3.14
  • VSCode Version: 1.34
  • CMake Tools Extension Version: 1.1.3
  • Compiler/Toolchain: Visual C++ 2019
@KoeMai
Copy link
Contributor

KoeMai commented May 31, 2019

The config build directory is the expansion template for cmake extension. It is used to generate the build directory. If you want to get the directory for debugging then try the lauchTargetDirectory.

@zrno
Copy link
Author

zrno commented Jun 3, 2019

Thanks for the answer. I can not use launchTargetDirectory as I have multiple targets in my project. The launch.json has several targets listed. Example launch.json:

"configurations": [
    {
        "name": "Target1 Launch",
        "program": "${config:cmake.buildDirectory}/Target1/Target1.exe",
    },
    {
        "name": "Target2 Launch",
        "program": "${config:cmake.buildDirectory}/Target2/Target2.exe",
    },

Using ${config:cmake.buildDirectory} isn't working. Any solution for that?

@KoeMai
Copy link
Contributor

KoeMai commented Jun 4, 2019

With the present extension it is not possible. It requires a new command.

@zrno
Copy link
Author

zrno commented Jun 4, 2019

Thanks for the fast response. Anything I need to do to open a feature request? Or is this open issue already enough?

@bobbrow
Copy link
Member

bobbrow commented Jul 17, 2019

Do you need to list out all of your targets in the launch.json?

The following works for me today:

        {
            "name": "Launch CMake active target",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${command:cmake.launchTargetPath}"
        }

It looks like command:cmake.launchTargetDirectory is not available in 1.1.3, but when we release the next update it will be available to set as the value for "cwd" should you need it.

If that doesn't work for you, we can leave this issue open as a feature request for a new command to return the resolved build directory.

@bobbrow bobbrow added enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: debug/launch labels Jul 17, 2019
@bobbrow bobbrow changed the title Using ${config:cmake.buildDirectory} in launch.json with visual cpp debugger doesn't work Add a command that returns the resolved value of cmake.buildDirectory Jul 17, 2019
@giantmustache
Copy link

The launchTargetDirectory is not always the same as the buildDirectory.

For example, if I have multiple targets in my project, I will get a subdirectory:

  • project1
    • CMakeLists.txt contains add_executable()
  • project2
    • CMakeLists.txt contains add_executable()

The build directory would be

  • bin --> would be buildDirectory
    • project1 --> would be launchTargetDirectory
      • project1.exe
    • project2 --> would be launchTargetDirectory
      • project2.exe

@bobbrow
Copy link
Member

bobbrow commented Jul 18, 2019

@giantmustache, you are correct. There are cases where the build directory might be desirable, but for the simple case launchTargetDirectory would put you in the same directory as the executable (launchTargetPath).

@giantmustache
Copy link

giantmustache commented Jul 19, 2019

I was able to work around this using vs power tools. For those looking for an answer:

I created a new command in my workspace settings like so:

"ego.power-tools": {
	"commands": {
		"expandedBuildDirectory": {
			"script": "expandedBuildDirectory.js"
		}
	}
}

Then I created the command as follows:

// expandedBuildDirectory.js
exports.execute = async (args) => {
	const vscode = args.require('vscode');

	// tried to use path first, but that contains a / at the front of the path
	const buildFolder = vscode.workspace.getConfiguration('cmake').get('buildDirectory').replace('${workspaceRoot}', vscode.workspace.workspaceFolders[0].uri.fsPath);
	return buildFolder.replace(/\\/g, '/');
};

You can call the command simply via ${command:expandedBuildDirectory}

@bobbrow
Copy link
Member

bobbrow commented Jul 22, 2019

As I have been reviewing the existing issues, I found that there is already one tracking this request. #564

@bobbrow bobbrow closed this as completed Jul 22, 2019
@bobbrow bobbrow added the duplicate a duplicate of an already present issue label Jul 22, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate a duplicate of an already present issue enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: debug/launch
Projects
None yet
Development

No branches or pull requests

4 participants