简体   繁体   English

在CMake中包含Visual Studio解决方案

[英]Include Visual Studio solution in CMake

I have a large project that is split in two parts: 我有一个大项目,分为两个部分:

  • Part 1 needs to be cross platform, we use CMake to setup all the projects file for that. 第1部分需要跨平台,我们使用CMake为此设置所有项目文件。

  • Part 2 is for windows only. 第2部分仅适用于Windows。 It is configured in a .SLN file, and it depends on Part 1. 它在.SLN文件中配置,并且取决于第1部分。

We generate a Part1.sln using cmake, but at this point we have two different solutions (Part1.sln and Part2.sln), and it is annoying to constantly switch from one to the other. 我们使用cmake生成了Part1.sln,但是到了这一点,我们有两个不同的解决方案(Part1.sln和Part2.sln),并且不断地从一个切换到另一个很烦人。

Apparently using CMake for Part 2 is not an option because most of our developers can not edit cmake files and would like to modify the solutions directly from MSVC. 显然,对于第2部分,请不要使用CMake,因为大多数开发人员无法编辑cmake文件,并且希望直接从MSVC修改解决方案。

As far as I know it is not possible to "include" a visual studio solution inside another one, but I might be wrong on that. 据我所知,不可能在另一个解决方案中“包含” Visual Studio解决方案,但是我对此可能是错误的。

We would like to generate a single .SLN file that contains both part 1 and part 2, possibly using CMake itself or some other method. 我们想生成一个包含第1部分和第2部分的单个.SLN文件,可能使用CMake本身或其他方法。

You are right in that you cannot include a full Visual Studio solution file in another one. 没错,您不能在另一个文件中包含完整的Visual Studio解决方案文件。

However, the majority of the information from the Part 1 project that you are interested in is probably not in the solution itself, but in the individual .vcxproj project files. 但是,您感兴趣的第1部分项目中的大多数信息可能都不在解决方案本身中,而是在单独的.vcxproj项目文件中。 And those can be included by as many solutions as you want. 这些可以包含在您想要的许多解决方案中。

Since you say that using CMake on the Part 2 project is out of the question, you will not get a perfect solution here. 由于您说在第2部分项目上使用CMake是不可能的,因此您在这里将无法获得理想的解决方案。 Someone needs to do a CMake run on Part 1 to generate the project files. 有人需要在第1部分上运行CMake才能生成项目文件。 This could be done by a custom build step in a Part 2 project though. 不过,这可以通过第2部分项目中的自定义构建步骤来完成。 The Part 2 solution file would then contain hardcoded references to the projects generated by that CMake run. 然后,第2部分解决方案文件将包含对该CMake运行生成的项目的硬编码引用。

If you change the project structure in Part 1, you will have to adjust the Part 2 solution accordingly. 如果您在第1部分中更改项目结构,则必须相应地调整第2部分解决方案。 This gets particularly nasty if the inter-project dependencies for two projects from Part 1 change. 如果第1部分中两个项目的项目间依存关系发生更改,则这尤其令人讨厌。 Also, if you forget to run CMake on Part 1 before loading the solution, you will end up with a bunch of load failed projects, but that's not a big deal. 另外,如果您在加载解决方案之前忘记在第1部分上运行CMake,最终将导致一堆load failed项目,但这没什么大不了的。 Just run CMake and do a Right Click->Reload Project on the respective projects. 只需运行CMake并在相应项目上执行右键单击->重新加载项目即可。

We ended up using include_external_msproject . 我们最终使用了include_external_msproject The final solution consist of a main cmake file that mixes standard cmake files ( add_subdirectory ), and vcproj files. 最终的解决方案包括将标准cmake文件( add_subdirectory )和vcproj文件混合在一起的主cmake文件。 The only (minor) downside was that the inter-project dependencies in Part2.sln had to be re-implemented inside the top level CMakeLists.txt . 唯一的(次要)缺点是必须在顶级CMakeLists.txt内部重新实现Part2.sln中项目间的依赖关系。

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

相关问题 使用cmake和visual studio在一个解决方案中的几个项目 - Several projects in one solution with cmake and visual studio 将CMake项目添加到Visual Studio解决方案 - Adding a CMake project to a Visual Studio solution 是否可以在Visual Studio中将文件添加到CMake生成的解决方案文件夹? - Is it possible to add files to a CMake generated solution folder in Visual Studio? 检查是否从 CMake 生成 Visual Studio 解决方案或 Makefile - Check if generating a Visual Studio solution or Makefile from CMake 如何从 CMake 创建 Visual Studio 2015 解决方案 - How to create Visual Studio 2015 solution from CMake 如何将 CMake 包含和库添加到 Visual Studio 解决方案? - How to add CMake includes and libraries to Visual Studio Solution? Visual Studio 中的 CMake 项目:如何添加额外的包含和库目录? - CMake project in Visual Studio: How to add additional include and library directories? 如何在其他Visual Studio项目中包含CMake lib /项目? - How to include CMake lib/projects in other Visual Studio projects? 如何修复cmake生成的Visual Studio项目中的包含错误 - How to fix include errors in resulting Visual Studio project from cmake 如何在cmake生成的Visual Studio项目中包括目录? - How to include directories in cmake generated visual studio projects?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM