Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  • Part 2 is for windows only. It is configured in a .SLN file, and it depends on Part 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.

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.

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.

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.

like image 394
sbabbi Avatar asked Feb 05 '16 10:02

sbabbi


People also ask

How do I add a CMake project to a Visual Studio solution?

Building CMake projects Select the preferred configuration and press F5, or choose the Run (green triangle) button on the toolbar. The project automatically builds first, just like a Visual Studio solution. Right-click on CMakeLists. txt in Solution Explorer and select Build from the context menu.

Can't find any instance of Visual Studio CMake?

In general the key to solving this problem always seems to be reinstalling/modifying Visual Studio, which ends up repairing the environment so that cmake can find the Visual Studio instance.


2 Answers

We ended up using include_external_msproject. The final solution consist of a main cmake file that mixes standard cmake files (add_subdirectory), and vcproj files. The only (minor) downside was that the inter-project dependencies in Part2.sln had to be re-implemented inside the top level CMakeLists.txt.

like image 200
sbabbi Avatar answered Sep 27 '22 05:09

sbabbi


You are right in that you cannot include a full Visual Studio solution file in another one.

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. 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. Someone needs to do a CMake run on Part 1 to generate the project files. This could be done by a custom build step in a Part 2 project though. The Part 2 solution file would then contain hardcoded references to the projects generated by that CMake run.

If you change the project structure in Part 1, you will have to adjust the Part 2 solution accordingly. This gets particularly nasty if the inter-project dependencies for two projects from Part 1 change. 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. Just run CMake and do a Right Click->Reload Project on the respective projects.

like image 23
ComicSansMS Avatar answered Sep 25 '22 05:09

ComicSansMS