views:

195

answers:

4

(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?

A: 

Not sure if this is what you're after, but: first make sure you have "Tools->Options->Projects and Solutions->Solution Explorer Mode" set to "Show All Files". Then if you create a VS project in the root source directory (probably the same as where your CMakeLists.txt goes), VS will show all files in that directory and all it's subirectories.

stijn
I couldn't find these options. My version is VC 7.1.)Besides I can see all the files but they all appear in the same directory in the solution explorer. Doesn't this happen with your version of Visual C++?
poulejapon
ah I'm using VS2008.. I'm seeing the entire directory structure as ot is on the disk.
stijn
+1  A: 

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.

JesperE
Thanks for your answer. I can manually create subdirectory in Visual C++ in the solution explorer (Right click Add->New directory) so I think it is not impossible but only not handled by CMake.
poulejapon
The problem is that the solution will be overridden next time you run CMake, so any changes you do to the solution in VS will be lost by then.
JesperE
+4  A: 

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

Georg Fritzsche
IT WORKED!!! thank you very much!
poulejapon
A: 

To clairfy this: To import a source tree with all subfolders, represented in the VS Explorer View like it is on the filesystem, you have to create a new Solution via the menu entry "Datei >> Neu >> Projekt aus vorhandenem Code" in VS2008 (german version) for example. This opens a wizard where you will find the mentioned "Show All Files" option. You don't need cmake for this.

I don't know any out-of-the-box solution to do the same via cmake. If someone does then please post the appropriate script.

crayor