使用 CMake 将命令行参数传递给 Visual Studio 进行配置文件引导优化

Passing command line arguments to Visual Studio using CMake for profile guided optimization

我正在使用 CMake 进行 C++ 项目。我正在尝试使用 profile guided optimization 所以我还需要将命令行参数传递给我的二进制文件的 Release 模式版本。 Visual Studio 需要它来创建性能配置文件。我已经有一个 launch.vs.json 配置 Debug 模式二进制文件,带有命令行参数:

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "name": "MyProject",
      "project": "CMakeLists.txt",
      "projectTarget": "MyProject.exe",
      "type": "default",
      "args": [
        "...", "..."
      ]
    }
  ]
}

当我切换到Release模式并选择MyProject启动项时,Visual Studio显示以下错误信息:

Unable to start debugging. The startup project could not be launched.

为什么这样不行?我也无法设置另一个配置文件并使 Visual StudioRelease 模式下识别它,但它在 Debug 模式下工作正常。

我现在通过添加另一个条目设法做到了:

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "name": "MyProject",
      "project": "CMakeLists.txt",
      "projectTarget": "MyProject.exe",
      "type": "default",
      "args": ["...", "..."]
    },
    {
      "name": "MyProject (Release\MyProject.exe)",
      "project": "CMakeLists.txt",
      "projectTarget": "MyProject.exe (Release\MyProject.exe)",
      "type": "default",
      "args": ["...", "..."]
    }
  ]
}