Add SOURCE_GROUP properties for file set and source file

Fixes: #27627
This commit is contained in:
Marc Chevrier
2026-06-20 14:45:52 +02:00
parent 23c5b40924
commit faeeac60e8
6 changed files with 76 additions and 6 deletions

View File

@@ -23,16 +23,25 @@ This is intended to set up file tabs in Visual Studio.
The group is scoped in the directory where the command is called, and applies
to sources in targets created in that directory.
If the file is part of a file set, search for a group which explicitly lists
this file set. If no group has been found or the file is not part of a file
set, search for a group which explicitly lists the file.
If the file set or the source file matches multiple groups, the *last* group
that explicitly lists the file set with ``FILE_SETS`` or the file with
``FILES`` will be favored, if any.
If no group explicitly lists the file set or the file, the *last* group whose
regular expression matches the file will be favored.
To determine the group of a source file, the algorithm used is as follows:
1. The file is part of a file set:
a. Use the :prop_fs:`SOURCE_GROUP` file set property if any.
b. Search for the *last* group which explicitly lists this file set.
2. The file is not part of a file set or no group was defined for this file
set:
a. Use the :prop_sf:`SOURCE_GROUP` source property if any.
b. Search for the *last* group which explicitly lists this source file.
3. If no group explicitly lists the file set or the file, the *last* group
whose regular expression matches the file will be favored.
The ``<group>`` and ``<prefix>`` arguments may contain forward
slashes or backslashes to specify subgroups. Backslashes need to be escaped

View File

@@ -557,6 +557,7 @@ Properties on File Sets
/prop_fs/SKIP_PRECOMPILE_HEADERS
/prop_fs/SKIP_UNITY_BUILD_INCLUSION
/prop_fs/SOURCES
/prop_fs/SOURCE_GROUP
/prop_fs/TYPE
.. _`Test Properties`:
@@ -636,6 +637,7 @@ Properties on Source Files
/prop_sf/SKIP_LINTING
/prop_sf/SKIP_PRECOMPILE_HEADERS
/prop_sf/SKIP_UNITY_BUILD_INCLUSION
/prop_sf/SOURCE_GROUP
/prop_sf/Swift_DEPENDENCIES_FILE
/prop_sf/Swift_DIAGNOSTICS_FILE
/prop_sf/SYMBOLIC

View File

@@ -0,0 +1,19 @@
SOURCE_GROUP
------------
.. versionadded:: 4.5
Define a grouping for source files of the file set in IDE project generation.
The ``SOURCE_GROUP`` file set property take precedence over any other way to
specify the grouping of source files. See the :command:`source_group` command
for details.
Related properties:
* Use :prop_sf:`SOURCE_GROUP` to specify a group for the source file.
Related commands:
* :command:`source_group` to manage various ways to specify grouping of
sources.

View File

@@ -0,0 +1,19 @@
SOURCE_GROUP
------------
.. versionadded:: 4.5
Define a group for the source file in IDE project generation.
The ``SOURCE_GROUP`` source property take precedence if no file set grouping
are specified. See the :command:`source_group` command for details.
Related properties:
* Use :prop_fs:`SOURCE_GROUP` to specify a group for the source files of a file
set.
Related commands:
* :command:`source_group` to manage various ways to specify grouping of
sources.

View File

@@ -0,0 +1,6 @@
SOURCE_GROUP-properties
-----------------------
* The :prop_fs:`SOURCE_GROUP` file set property and :prop_sf:`SOURCE_GROUP`
source file property were added to provide a fine grain control over the
grouping of sources.

View File

@@ -4261,6 +4261,7 @@ cmSourceGroup* cmLocalGenerator::FindSourceGroup(
std::string const& config)
{
#if !defined(CMAKE_BOOTSTRAP)
std::string const SOURCE_GROUP{ "SOURCE_GROUP" };
std::string const& targetName = target->GetName();
cmGeneratorFileSet const* fileSet =
target->GetFileSetForSource(config, source);
@@ -4273,6 +4274,13 @@ cmSourceGroup* cmLocalGenerator::FindSourceGroup(
return indexIt->second;
}
cmValue fsSG = fileSet->GetProperty(SOURCE_GROUP);
if (!fsSG.IsEmpty()) {
cmSourceGroup* sg = this->GetMakefile()->GetOrCreateSourceGroup(*fsSG);
this->SourceGroupSearchIndex.emplace(fsKey, sg);
return sg;
}
cmSourceGroup* sourceGroup = cmSourceGroup::FindSourceGroup(
targetName, fsName, this->Makefile->GetSourceGroups());
if (sourceGroup) {
@@ -4290,6 +4298,13 @@ cmSourceGroup* cmLocalGenerator::FindSourceGroup(
return indexIt->second;
}
cmValue srcSG = source->GetProperty(SOURCE_GROUP);
if (!srcSG.IsEmpty()) {
cmSourceGroup* sg = this->GetMakefile()->GetOrCreateSourceGroup(*srcSG);
this->SourceGroupSearchIndex.emplace(source->GetFullPath(), sg);
return sg;
}
// look-up in source groups definitions
return this->FindSourceGroup(source->GetFullPath());
#else