My workspace is structured like so:
${workspaceFolder}
|----- CMakeLists.txt
|
|----- build/
|
|----- projects/
|----- projectA/
| |----- src/
| |----- out/
| |----- resources/
| |----- CMakeLists.txt
|
... (3 more identically structured projects)
When debugging, I want CMake Tools to set the cwd to each project's out directory because I distribute the files from resources/ to out/ and access them using relative paths.
The cwd is currently set to ${workspaceFolder} which means none of the resources are found.
I have tried putting this in each project's CMakeLists.txt but it did not work
set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Any suggestions?
Edit: ${CMAKE_BINARY_DIR} is set to ${PROJECT_SOURCE_DIR}/out in each project's CMake Lists.txt
We can mark this as a feature request. In the meantime, you can use the cmake.debugConfig object to override certain debugger settings like "cwd" (current working directory).
cmake.debugConfig: {
"cwd": "${workspaceFolder}/projects/projectA/out"
}
This is not ideal for a project with multiple targets since you'll have to change the cwd each time you change debug targets, but it can get you by until the feature is implemented.
@bobbrow any guidance on how/where to do this?
I might be keen to implement it.
I found https://github.com/microsoft/vscode-cmake-tools/blob/6be029309ebb96d752e61c37d578faece4d82550/src/cmake-tools.ts#L1260 in async launchTarget(name?: string)
I suppose we could add a line something like this._launchTerminal.sendText("cd ${workingDirectory"); ?
That would require adding another cmake setting workingDirectory
I've been thinking about this and wasn't sure if this was the right approach. It would require a lot of manual target/path setting.
The mechanism that CMake provides to accumulate binaries/resources into a working location is INSTALL and the information should be mostly derivable from CMakeLists.txt, but I've been looking over the INSTALL documentation and it seems it allows for more scenarios than I anticipated. I want to sync with the Visual Studio team that owns the CMake experience and see what their thoughts are about this. I *think* that we could provide a debug selector that will also let you pick one of the paths specified in your INSTALL directive though I'm not sure how reliable the guessing will be since you can INSTALL to multiple locations.
Related #771
We can mark this as a feature request. In the meantime, you can use the
cmake.debugConfigobject to override certain debugger settings like "cwd" (current working directory).cmake.debugConfig: { "cwd": "${workspaceFolder}/projects/projectA/out" }This is not ideal for a project with multiple targets since you'll have to change the cwd each time you change debug targets, but it can get you by until the feature is implemented.
You can use the following in your settings.json without having to modify the cwd each time:
"cmake.debugConfig": {
"cwd": "${command:cmake.launchTargetDirectory}"
},
However, this does not work for non-debug launches. Any ideas?
Most helpful comment
We can mark this as a feature request. In the meantime, you can use the
cmake.debugConfigobject to override certain debugger settings like "cwd" (current working directory).This is not ideal for a project with multiple targets since you'll have to change the cwd each time you change debug targets, but it can get you by until the feature is implemented.