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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With