1

Is there a possibility to set different working directories (VS_DEBUGGER_WORKING_DIRECTORY) for Debug and Release builds in a CMake generated Visual Studio project?

If I write

set_target_properties(${PROJECT_BIN} PROPERTIES 
    VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Debug")

Selecting Project Properties > Debugging > Working Directory will display

C:/Users/Alexandru/Documents/MyProject/Build/Debug

for both Debug and Release configurations, but I want

C:/Users/Alexandru/Documents/MyProject/Build/Release

for the Release configuration.

I also tried setting VS_DEBUGGER_WORKING_DIRECTORY_DEBUG and VS_DEBUGGER_WORKING_DIRECTORY_RELEASE but it seems these properties don't exist.

Alexandru Irimiea
  • 2,513
  • 4
  • 26
  • 46

1 Answers1

3

If there are no configuration specific properties and generator expressions like $<CONFIG> don't work (tested it with VS_DEBUGGER_WORKING_DIRECTORYto no avail), you can still use VS variables:

set_target_properties(${PROJECT_BIN} PROPERTIES 
    VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$(Configuration)")
Florian
  • 39,996
  • 9
  • 133
  • 149
  • Where can I put this so that it works. I put this at the beginning (after project(name)...) of the CMake.txt file, but it doesn't work. – 123iamking Sep 17 '17 at 07:35
  • @123iamking The above command changes a library or executable target's properties. To have the target in question known, it has to come in your `CMakeLists.txt` after that target is defined. CMake does not support forward declarations of target properties. Sometimes there are global variables available that define any upcoming target's defaults, but not is this particular case. – Florian Sep 17 '17 at 19:09
  • Can you make a simple CMake that make a project that has working directory in the bin folder, Please? :) I'm fairly new to CMake. Thank you very much. – 123iamking Sep 18 '17 at 02:32