No CMakePredefinedTargets when using solution fold

2019-06-22 05:29发布

问题:

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:

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.

回答1:

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