[CMake] Correct use of VS_DEBUGGER_WORKING_DIRECTORY etc.

Stephen Morris s-morris at n-eos.com
Wed Apr 17 04:34:10 EDT 2019


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")



________________________________
From: Stephen Morris
Sent: 16 April 2019 17:36
To: cmake at cmake.org
Subject: 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..."

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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190417/eb8f7cb8/attachment-0001.html>


More information about the CMake mailing list