Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add files to a CMake generated solution folder in Visual Studio?

This question is more or less a warmup of this question:

how to get cmake to add files to msvcs solution tree

It never got a valid answer so I want to repose it slightly different:

Is it possible to use the cmake solution folders that where introduced with cmake 2.8.3 to add files directly to the vs solution? I want to do the cmake equivalent of VS->Solution->Add->Existing Item. So my file will appear in a folder that belongs to the solution and not to a project.

I found examples how the solution folders can be used to group targets into folders with code like this:

set_property( GLOBAL PROPERTY USE_FOLDERS ON)
set_property(TARGET ${TARGET_NAME} PROPERTY FOLDER "Test") 

So can I add a file instead of a target to the folder?

like image 688
Knitschi Avatar asked Nov 27 '13 19:11

Knitschi


2 Answers

This is probably not possible.

CMake organizes its assets into projects and targets. The project is what corresponds to Visual Studio's solution file while each target will generate a Visual Studio project inside the respective solution.

The problem is now that CMake does not allow to add files to CMake projects. In fact, a CMake project is little more than a collection of targets and offers almost no customization options. Hence the USE_FOLDERS option you mentioned can only be used to group VS projects inside a solution, but not single files.

The closest to what you ask would probably be to add a custom target that holds your files. However, this will still generate a VS project (which also contains a bunch of other stuff besides your files) inside the solution and not a plain folder.

like image 52
ComicSansMS Avatar answered Nov 13 '22 19:11

ComicSansMS


If I understand the question correctly, I think I know how to do it:

set(FILES_TO_ADD
    file1
    file2
    file3)

source_group("Group Name" FILES ${FILES_TO_ADD})

The source_group command creates the folder inside the Visual Studio project.

like image 28
Irigi Avatar answered Nov 13 '22 18:11

Irigi