[英]How do I add command line launch arguments to a Release target in a CMake-managed C++ project in MSVC 2019?
My goal is to run eg MyTarget.exe "C:\Users\MHebes\config.json
from MSVC.我的目标是从 MSVC 运行例如
MyTarget.exe "C:\Users\MHebes\config.json
。
I can do this in Debug mode, but can't get it to work in Release.我可以在调试模式下做到这一点,但不能让它在发布中工作。
If I right-click on my top-level CMakeLists.txt, I can see the launch.vs.json
for the current open folder:如果我右键单击我的顶级 CMakeLists.txt,我可以看到当前打开文件夹的
launch.vs.json
:
..\..\..\..\AppData\Local\Microsoft\VisualStudio\16.0_45505961\OpenFolder\launch_schema.json : ..\..\..\..\AppData\Local\Microsoft\VisualStudio\16.0_45505961\OpenFolder\launch_schema.json :
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "MyTarget.exe (apps\\MyTarget\\Debug\\MyTarget.exe)",
"name": "Debug launch target for MyTarget",
"args": [
"C:/Users/MHebes/config.json"
]
}
]
}
I don't fully understand this in the first place, since the launch.vs.json docs don't mention anything about a "configurations"
list but this was how it was auto-populated when I added a new configuration.首先我并不完全理解这一点,因为launch.vs.json 文档没有提到任何关于
"configurations"
列表的内容,但这就是我添加新配置时自动填充的方式。 Regardless, this works in debug mode—the "Debug launch target for MyTarget" option shows up in the Select Startup Item...
list when Debug
is selected in the dropdown.无论如何,这在调试模式下有效——“调试 MyTarget 的启动目标”选项显示在
Select Startup Item...
列表中,当在下拉列表中选择Debug
时。
I have added a Release
/ RelWithDebugInfo
configuration to my CMakeSettings.json
.我在
CMakeSettings.json
中添加了Release
/ RelWithDebugInfo
配置。
But when I actually switch the build to Release
, the Select Startup Item...
list is only populated with default CMakeTargets.但是当我实际将构建切换到
Release
时, Select Startup Item...
列表仅填充了默认的 CMakeTargets。
How do I add command-line launch arguments to Release builds?如何将命令行启动 arguments 添加到发布版本?
My end goal is that when I Start Debugging in Release mode, it will build a Release exe and run it with some args.我的最终目标是,当我在发布模式下开始调试时,它将构建一个发布 exe 并使用一些参数运行它。
I think I figured it out.我想我想通了。 I added another configuration with a different target:
我添加了另一个具有不同目标的配置:
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "MyTarget.exe (apps\\MyTarget\\Debug\\MyTarget.exe)",
"name": "Debug launch target for MyTarget",
"args": [
"C:/Users/MHebes/config.json"
]
},
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "MyTarget.exe (apps\\MyTarget\\RelWithDebInfo\\MyTarget.exe)",
"name": "RelWithDebInfo launch target for MyTarget",
"args": [
"C:/Users/MHebes/config.json"
]
}
]
}
The Microsoft Docs page on Configure CMake debugging sessions says: 配置 CMake 调试会话上的 Microsoft Docs 页面说:
projectTarget
: Specifies the CMake target to invoke when building the project.projectTarget
:指定在构建项目时要调用的 CMake 目标。 Visual Studio autopopulates this property if you enter launch.vs.json from the Debug Menu or Targets View.如果您从“调试”菜单或“目标”视图输入 launch.vs.json,Visual Studio 会自动填充此属性。 This value must match the name of an existing debug target listed in the Startup Item dropdown.
此值必须与“启动项”下拉列表中列出的现有调试目标的名称相匹配。
Since Visual studio populates the Startup list with names that include the path to the executable, and because that path is dependent on the configuration name (ie buildRoot
in CMakeSettings.json
includes ${name}
in the path by default), this explains why projectTarget
must include the configuration path.由于 Visual Studio 使用包含可执行文件路径的名称填充启动列表,并且因为该路径取决于配置名称(即
buildRoot
中的CMakeSettings.json
默认在路径中包含${name}
),这解释了为什么projectTarget
必须包含配置路径。
This seems like an insane interface to me.这对我来说似乎是一个疯狂的界面。 Maybe I'm doing something wrong.
也许我做错了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.