[CMake] Failing to set VS_DEBUGGER_* on target added via add_custom_target.

Albrecht Fritzsche afritzsche at nvidia.com
Tue Dec 4 11:20:31 EST 2018


Hi,

I - being new to CMake - somehow fail to set VS_DEBUGGER_* property values on a project added via add_custom_target(). The settings of those property values seem to be lost and not written to any .vcxproj file. Doing the same to a target added via add_executable() works on the other hand as expected, ie the debug property values show up correctly in the corresponding .vcxproj. (This is all tried with Visual Studio 2015.)

What is the proposed way to achieve the settings of the property values on a project added via add_custom_target()? What am I doing wrong?

_Details_ I have the helloWorld.cpp and CMakeLists.txt next to a subdirectory ext, containing both the test01.cpp and test01.exe. Ie
  CMakeLists.txt
  helloWorld.cpp
  ext/
      test01.cpp
      test01.exe

The CMake code in a nutshell:

add_executable(helloWorld helloWorld.cpp)

set(test_name "test01")
set(test_target "${test_name}_build")
add_custom_target(${test_target}
    #COMMAND ${CMAKE_COMMAND} -E env "PATH=${BUILD_DRIVER_NVMAKE_DIRECTORY};$ENV{PATH}" nvmake ...
    COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/ext/${test_name}.exe" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>"
    SOURCES "${CMAKE_SOURCE_DIR}/ext/${test_name}.cpp"
)
set_property( TARGET ${test_target} PROPERTY FOLDER "nvmake tests" )
# from the following two set_property() calls only the first one has an effect in the generated .vcxproj files
set_property( TARGET helloWorld     PROPERTY VS_DEBUGGER_COMMAND "foo.exe" )
set_property( TARGET ${test_target} PROPERTY VS_DEBUGGER_COMMAND "foo.exe" )


I understand that using imported targets might be an even more appropriate solution for the problem at hand. But with imported targets, eg via add_executable(${test_target} IMPORTED), I fail to add those in a way that they show up as projects in Visual Studio. What is the recommended way for this approach?

Thanks for any hints,
Ali
PS The custom target ends up as a project of configuration type Utility - is there a way to change it to type Executable?

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181204/2f27db38/attachment-0001.html>


More information about the CMake mailing list