简体   繁体   English

Visual Studio CMake 在包含许多项目的克隆仓库上

[英]Visual Studio CMake on cloned repo with many projects

I have a git repo with many many projects in it.我有一个 git 回购协议,里面有很多项目。 I am trying to use MSVC with Clang-cl and CMake, Git.我正在尝试将 MSVC 与 Clang-cl 和 CMake、Git 一起使用。

I started out building a project directly in MSVC:我开始直接在 MSVC 中构建一个项目:

CMakePresets.json
CMakeLists.txt
asource.file.cpp

When I was happy with the working code, I moved these files into /repo/subfolder, and committed them.当我对工作代码感到满意时,我将这些文件移动到 /repo/subfolder 中,并提交了它们。

Now I am cloning my repo as a new project: I chose to "clone repository" at MSVC project creation, and I want to avoid building the /repo root CMake project.现在我将我的存储库克隆为一个新项目:我在 MSVC 项目创建时选择了“克隆存储库”,并且我想避免构建 /repo root CMake 项目。 Instead I want to build the /repo/subfolder CMake project.相反,我想构建 /repo/subfolder CMake 项目。 How can I achieve this?我怎样才能做到这一点?

Imagine I am on the Linux command line.想象一下我在 Linux 命令行上。 Instead of:代替:

cd myrepo
mkdir -p build && pushd build
cmake .. -G Ninja

I want to:我想要:

cd myrepo/subfolder
mkdir -p build && pushd build
cmake .. -G Ninja

The difference is that I want to make use of a CMake project in a subfolder instead of the root folder.不同之处在于我想在子文件夹而不是根文件夹中使用 CMake 项目。 I have been unable to build anything but the root project.除了根项目,我无法构建任何东西。

I've tried:我试过了:

  1. Right-click CMakeLists.txt and Configure CMake - it configures the top-level CMake project instead of the file I am clicking on.右键单击 CMakeLists.txt 并配置 CMake - 它配置顶级 CMake 项目而不是我正在单击的文件。
  2. Right-click CMakePresets.json and click all the "Add..." etc. there.右键单击 CMakePresets.json 并单击那里的所有“添加...”等。 It seems to edit the presets file itself.它似乎是在编辑预设文件本身。

I could not figure out how to have many CMake builds in one project cloned from a repo, but I figured out how to open any folder as its own CMake project:我无法弄清楚如何在一个项目中从 repo 克隆许多 CMake 构建,但我想出了如何打开任何文件夹作为它自己的 CMake 项目:

File -> Open -> CMake...文件 -> 打开 -> CMake...

Select the subfolder as your project. Select 子文件夹作为您的项目。 Then MSVC will trample your CMakePresets.json (truncating it to 0 bytes) which you can reset with Git -> Undo Changes.然后 MSVC 将践踏您的 CMakePresets.json(将其截断为 0 字节),您可以使用 Git -> 撤消更改对其进行重置。 Once you have undone the changes you will want to reset the CMake cache and reconfigure in order to avoid failed CMake compilation tests.撤消更改后,您将需要重置 CMake 缓存并重新配置,以避免 CMake 编译测试失败。

And now it should work.现在它应该可以工作了。 Unfortunately it doesn't seem to be very easy to clone a repo and then work with $project inside it.不幸的是,克隆一个 repo 然后在其中使用 $project 似乎不是很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM