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

查看:906
本文介绍了如何为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:

根据此错误报告,则可以在 Debug and Launch Settings (调试和启动设置)中添加设置(右键单击相关的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.

  • 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打开解决方案,因为与Visual Studio 2017集成的CMake版本是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天全站免登陆