Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Organizing a CMake project so that sources can be easily browsed in Visual C++

(I'm new to CMake and I am not so familiar with Visual Studio.)

I need to implement a relatively big library the solution/project files will be generated by CMake, and my problem is that I would like the organization of the files in VC GUI to reflect the directory structure on the disk.

Basically, the library is split into different parts. For instance one of them is called "common" and will implement some headers used by the library. On the disk it will be in a specific "common" directory, which may have one or more subdirectory.

src/
   common/
     ...
   portfolio/
     ...
   asset/
     contracts/
     physical_assets/
     ...
   mathutils/
   ...

I'd like to have the see the same thing within Visual Studio's Solution Explorer, but I only know how to split the solution into different projects. How can I do that?

like image 420
fulmicoton Avatar asked Dec 31 '09 09:12

fulmicoton


People also ask

How do I create a CMake project in Visual Studio?

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.

How do I import CMake project into Visual Studio?

On the Visual Studio main menu, choose File > Open > CMake. Navigate to the CMakeLists. txt file in the root of the bullet3 repo you just downloaded. As soon as you open the folder, your folder structure becomes visible in the Solution Explorer.

Is CMake better than Visual Studio?

CMake is a better build system than Visual Studio projects and solutions. It is compact and much more easier to maintain even for Windows only projects. See CMake for Visual Studio Developers for some reasons.


2 Answers

You can do that using SOURCE_GROUP, the CMake FAQ covers that.

like image 178
Georg Fritzsche Avatar answered Nov 16 '22 02:11

Georg Fritzsche


I don't think you can. If you use "Show All Files" you will get what you want, but only at the project level. Creating a VS project at the root may give you the possiblity of viewing all your files, but you will still need separate projects for each exe/dll/etc. you want to build. Remember that a solution in VS terms is a set of projects, not a directory tree.

like image 20
JesperE Avatar answered Nov 16 '22 04:11

JesperE