向项目添加命令行参数 [英] Adding command line arguments to project

查看:85
本文介绍了向项目添加命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与 SO 有点类似,但并不相同。

My question is somewhat similar to this SO but not the same.

我使用以下内容创建了 HelloWorld 程序:

I created a HelloWorld program with the following:

add_executable( HelloWorld ${SRC} )

当我生成项目文件(例如,Visual Studio .sln文件或XCode .xcodeproj文件)。我想点击运行按钮,并在执行程序时将一些命令行参数传递给 HelloWorld ,如下所示:

When I generate a project file (for example a Visual Studio .sln file, or an XCode .xcodeproj file). I want to hit the run button and pass in some command line arguments to HelloWorld when it executes the program, like the following:

./HelloWorld --gtest_filter=Test_Cases1*

另请参见 SO ,以了解如何在Visual Studio中完成此操作。

Also see this SO for how this is done in Visual Studio.

是否可以在CMakeList文件中执行此操作?如果没有,为什么?

Is it possible to do this in CMakeList file? If not, why?

推荐答案

CMake对此没有内置支持。原因是Visual Studio项目属性的调试选项卡中的设置未存储在项目文件中( .vc [x] proj ),但在特定于用户和计算机的 .user 文件中,而CMake不会生成这些文件。

CMake has no built-in support for this. The reason is that the settings from the Debugging tab of Visual Studio Project properties are not stored in the project file (.vc[x]proj), but in a user-and-machine-specific .user file, and CMake does not generate these.

您可以自己在CMake中进行编码(我在工作中为我们的框架做了此操作)。该文件只是XML,因此您可以根据需要预先填充它。它的结构很容易理解。调试程序的命令行参数存储在XML元素< DebugSettings> 内的 CommandArguments 属性中。 (例如,嵌套在< Configurations>< Configuration> 中)。

You can code it yourself in CMake (I did that for our framework at work). The file is just XML, so you can pre-populate it according to your needs. Its structure is pretty easy to understand. The command-line arguments for the program being debugged are stored in the CommandArguments attribute inside a <DebugSettings> XML element (nested in <Configurations><Configuration>), for example.

这篇关于向项目添加命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆