如何为 Visual Studio 2017 RC CMake 项目设置工作目录 [英] How to set working directory for Visual Studio 2017 RC CMake Project

查看:86
本文介绍了如何为 Visual Studio 2017 RC CMake 项目设置工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Visual Studio 2017 RC 打开一个 CMake 项目,然后我发现工作目录始终是输出目录.

I use Visual Studio 2017 RC to open a CMake project and then I find the working directory is always the output directory.

有没有办法将工作目录设置到输出文件目录以外的地方?

Is there any way to set the working directory to somewhere other than the directory of output file?

(因为没有.sln文件,不能用老方法设置工作目录)

(Because there is no .sln file, I cannot set the working directory in the old way)

更新我不是从 CMake 脚本调用程序.我在 Visual Studio 中运行目标程序.我想更改目标程序的工作目录.

Update I am not calling programs from CMake scripts. I am running the target program in Visual Studio. And I want to change the working directory for the target program.

推荐答案

截至发稿 (2017-03-23),无法通过 CMakeLists.txt 设置工作目录.以下是一些解决方法:

As of writing (2017-03-23), it is not possible to set working directory via CMakeLists.txt. Here are some workarounds:

根据 这个错误报告,您可以在调试和启动设置中添加设置(右键单击相关的 CMakeLists.txt).这将打开 launch.vs.json 文件,您可以在其中使用 currentDir 变量添加工作目录.这是一个例子:

According to this bug report, you can add the setting inside your Debug and Launch Settings (right click the relevant CMakeLists.txt). This opens the launch.vs.json file, where you can add the working directory using the currentDir variable. Here's an example:

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "default",
      "project": "CMakeLists.txt",
      "projectTarget": "path\to\target",
      "name": "My Awesome Project",
      "currentDir": "${workspaceRoot}/src"
    }
  ]
}

如果您愿意,可以继续签入该文件;它可能位于 .vs/launch.vs.json.

If you want you can go ahead and check that file in; it probably sits in .vs/launch.vs.json.

  • 查看 Visual C++ 团队博文.但它没有提到 currentDir.
  • 语法似乎与 Visual Studio Code 使用的语法非常相似,尽管关键字都是不同的——例如,VSCode 使用 cwd 而不是 currentDir.
  • See the Visual C++ Team blog post. It doesn't mention currentDir though.
  • The syntax appears to be very similar to that used by Visual Studio Code, although the keywords are all different - VSCode uses cwd instead of currentDir, for example.

另请参阅:CMake 是否提供了一种方法来设置运行/调试项目时使用的给定构建系统的工作目录?

VS_DEBUGGER_WORKING_DIRECTORY 是 3.8.0 版中的新 CMake 目标属性.设置如下:

VS_DEBUGGER_WORKING_DIRECTORY is a new CMake target property in version 3.8.0. Set it like this:

set_target_properties(
    MyProject PROPERTIES
    VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")

你需要使用独立CMake的老方法,生成.sln/.vcxproj文件,用Visual Studio打开解决方案,因为CMake的版本集成了VisualStudio 2017 是 3.6.这导致...

You need to use the old method of standalone CMake, generate .sln/.vcxproj files, open solution with Visual Studio, because the version of CMake integrated with Visual Studio 2017 is 3.6. Which leads to...

不知道什么时候会发生;团队目前正在考虑更新到 CMake 3.7 所以它会再长一段时间.但是,当这种情况发生时,它可能会支持 VS_DEBUGGER_WORKING_DIRECTORY 属性.

It's unknown when this will happen; the team are currently looking at updating to CMake 3.7 so it'll be a while longer. However when this happens chances are it will support the VS_DEBUGGER_WORKING_DIRECTORY property.

这篇关于如何为 Visual Studio 2017 RC CMake 项目设置工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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