Set the Visual Studio Debugger working directory to the output directory in CMake

The default Visual Studio debugger working directory is $(ProjectDir).

I really want it to be installed in $(TargetDir)(where is .exeit that I run).

This answer contains the correct syntax, so I tried the following:

if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
  set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${PROJECT_BUILD_DIR}/Debug)
endif()

However, these are hard codes Debugthat I don't like.

I tried $<CONFIG>at the end, but this was not valid in Visual Studio (expression is not evaluated).

I also tried $(TargetDir), but this does not work. But if I manually delete the variable $(TargetDir)and paste it back in, it will work.

How to set the debugger working directory to an executable output directory without hard coding?

+4
source share
1 answer

This can be done by setting the debugger working directory as follows:

set_property(TARGET my_target PROPERTY VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})

CMAKE_CFG_INTDIR enables the build variable, which provides the current target configuration in Visual Studio.

+1
source

Source: https://habr.com/ru/post/1689143/


All Articles