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..."
So I delete the text $(TargetDir) and $(TargetPath) from the dialog, then type them in again exactly as before: and then it works perfectly.
What am I doing wrong?
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With