7

When using VS solution folders in CMake using:

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_target_properties(MyProject PROPERTIES FOLDER "MyProjects")

I'm also automatically enabling a CMakePredefinedTargets folder:

enter image description here

Is there a way to avoid this behaviour?

Resetting PREDEFINED_TARGETS_FOLDER can rename the folder but not remove it. Setting the FOLDER property for INSTALL, etc. does not seem to be valid either.

Thanks.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
maranov
  • 73
  • 6
  • 1
    I've given your statement that "resetting `PREDEFINED_TARGETS_FOLDER` won't help" a test. And for me resetting it was helping to get the predefined targets at root level again (see my answer below). So can you please give it a try? And if it's not working could you please add some details about your `CMakeLists.txt` or your environment in general? – Florian Mar 22 '16 at 21:29
  • Hi all, If I want to place two (or more) projects into the same folder, how can I do so ? For example: Lets say I have two projects (project1 and project2) which I wish to have under the Test folder (as in the above example) ? – Guy Avraham Sep 15 '16 at 12:35

1 Answers1

4

Edit: After looking into the CMake code I was pretty sure you could set PREDEFINED_TARGETS_FOLDER to "". I've tested it and with CMake 3.3.2 and VS2015 using

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "")

the predefined targets are at root level again.

And, yes if the global USE_FOLDERS property if ON then the predefined targets are hard-wired to always be grouped in the PREDEFINED_TARGETS_FOLDER folder. So setting the FOLDER property of e.g. INSTALL won't help.

As a reference see cmGlobalVisualStudioGenerator.cxx where this behavior was explicitly deactivated for the ALL_BUILD target:

#if 0
    // Can't activate this code because we want ALL_BUILD
    // selected as the default "startup project" when first
    // opened in Visual Studio... And if it's nested in a
    // folder, then that doesn't happen.
    //
    // Organize in the "predefined targets" folder:
    //
    if (this->UseFolderProperty())
    {
        allBuild->SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
    }     
#endif
Florian
  • 39,996
  • 9
  • 133
  • 149
  • I've seem to misinterpret the [`PREDEFINED_TARGETS_FOLDER`](https://cmake.org/cmake/help/v3.5/prop_gbl/PREDEFINED_TARGETS_FOLDER.html) docs. It does actually work as you say. Thanks. – maranov Mar 23 '16 at 07:35
  • @maranov You are welcome. And I wanted to add that I personally find the grouping of the predefined targets very useful. What I do in my own CMake projects is `set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "_CMakePredefinedTargets")`. The leading underscore makes sure that the predefined targets are always at the top. Otherwise the folders are sorted alphabetically and sometimes hard to find it the middle of all my other folders/projects on root level. – Florian Mar 23 '16 at 08:28