Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct use of VS_DEBUGGER_WORKING_DIRECTORY etc

I’m trying to use the new VS_DEBUGGER_WORKING_DIRECTORY and VS_DEBUGGER_COMMAND properties to facilitate debugging in a CMake-generated Visual Studio project file (in my case Visual Studio 2013).

Everything else in my configuration works except this…

I’ve noted from ‘regular’ Visual Studio project files (i.e. ones not generated from CMake) that, in the “Configuration Properties/Debugging” dialog, the ‘Command’ and ‘Working Directory’ fields are populated by default with $(TargetPath) and $(TargetDir) respectively. So in my CMakeLists.txt file, I have:

set_target_properties(myApplication PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "$(TargetDir)"
                                               VS_DEBUGGER_COMMAND                    "$(TargetPath)"
                                               VS_DEBUGGER_ENVIRONMENT              "%PATH%;C:\\Qt\\5.9.7\\msvc2013_64\\bin")

[In fact I've tried this with and without the quotes around $(TargetDir) and $(TargetPath) and the result is the same each time; they're absolutely necessary around the path.]

What happens is that I then build the application, go to the “Configuration Properties/Debugging” dialog and verify that it looks exactly the same as a normal project file, with $(TargetDir) and $(TargetPath) appearing exactly where they should do. It doesn't work though; when I try to debug I get a message saying "Unable to start debugging. Check your debugger settings..."

Initial failure; the fields are populated correctly, but no debugging ensues

So I delete the text $(TargetDir) and $(TargetPath) from the dialog, then type them in again exactly as before: and then it works perfectly.

Deleted the fields, and typed them in again exactly as before; now it works

What am I doing wrong?

like image 826
Eos Pengwern Avatar asked Apr 16 '19 17:04

Eos Pengwern


1 Answers

It turns out that the solution is to replace "$(TargetPath)" and "$(TargetDir)" with the CMake generator expressions "$<TARGET_FILE:myApplication>" and "$<TARGET_FILE_DIR:myApplication>", respectively, viz:

set_target_properties(myApplication PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:myApplication>"
                                               VS_DEBUGGER_COMMAND           "$<TARGET_FILE:myApplication>"
                                               VS_DEBUGGER_ENVIRONMENT       "PATH=%PATH%;${CMAKE_PREFIX_PATH}/bin")
like image 109
Eos Pengwern Avatar answered Nov 18 '22 04:11

Eos Pengwern