Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Command Arguments in VC Debugging option be set with cmake

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.

like image 905
feelfree Avatar asked Aug 05 '14 08:08

feelfree


People also ask

How do you pass command line arguments in cmake?

If you create the cache variable in the CMakeLists. txt file and then pass the argument via calling cmake, won't the CMakeList. txt file keep overwriting the argument value? No, the cache is populated on the first run with either the default value, or the value supplied on the command line if it is provided.

How to debug using cmake?

You can also start a debug session from Solution Explorer. First, switch to CMake Targets View in the Solution Explorer window. Then, right-click on an executable and select Debug. This command automatically starts debugging the selected target based on your active configuration.

How do you pass command line arguments in Visual Studio C++?

To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line. They will be passed to the program via the argv array.

How use cmake command line?

Running CMake from the command line From the command line, cmake can be run as an interactive question and answer session or as a non-interactive program. To run in interactive mode, just pass the option “-i” to cmake. This will cause cmake to ask you to enter a value for each value in the cache file for the project.


Video Answer


1 Answers

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.

like image 67
Arnaud Avatar answered Nov 10 '22 04:11

Arnaud