13

When we run a C++ program with Visual Studio, we often set "Command Arguments" insider Configuration Properties->Debugging if the program need some arguments. For example, we may run abc.exe -r 1 in the command line, and in order to run the program directly in Visual Studio, we can fill the Command Arguments with -r 1 . So my question is: can we set default Command Arguments with cmake? By doing so, there is no need to set them manually. Thanks.

feelfree
  • 11,175
  • 20
  • 96
  • 167
  • 1
    possible duplicate of [How to Set Path Environment Variable using CMake and Visual Studio to Run Test](http://stackoverflow.com/questions/1005901/how-to-set-path-environment-variable-using-cmake-and-visual-studio-to-run-test) – stijn Aug 05 '14 at 09:12
  • I believe you can do this by using cmake commands to generate a .user file. – drescherjm Aug 06 '14 at 08:53
  • Possible duplicate of [CMake: Adding command line arugments to project](http://stackoverflow.com/questions/30104520/cmake-adding-command-line-arugments-to-project) – Beginner Apr 19 '17 at 13:38

1 Answers1

4

You could add this into your CMakeLists.txt:

FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/abc.vcxproj.user"
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
    "<Project ToolsVersion=\"15.0\">\n"
    "  <PropertyGroup>\n"
    "    <LocalDebuggerCommandArguments>-r 1</LocalDebuggerCommandArguments>\n"
    "    <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>\n"
    "  </PropertyGroup>\n"
    "</Project>")

You might want to adapt this to your version of Visual Studio.

Arnaud
  • 3,765
  • 3
  • 39
  • 69