diff --git a/Help/command/source_group.rst b/Help/command/source_group.rst index 7072c75d91..60e3bf82e7 100644 --- a/Help/command/source_group.rst +++ b/Help/command/source_group.rst @@ -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 ```` and ```` arguments may contain forward slashes or backslashes to specify subgroups. Backslashes need to be escaped diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index fc16f2d266..5b4e11c972 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -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 diff --git a/Help/prop_fs/SOURCE_GROUP.rst b/Help/prop_fs/SOURCE_GROUP.rst new file mode 100644 index 0000000000..b4b8b29ce0 --- /dev/null +++ b/Help/prop_fs/SOURCE_GROUP.rst @@ -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. diff --git a/Help/prop_sf/SOURCE_GROUP.rst b/Help/prop_sf/SOURCE_GROUP.rst new file mode 100644 index 0000000000..9209fb2af0 --- /dev/null +++ b/Help/prop_sf/SOURCE_GROUP.rst @@ -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. diff --git a/Help/release/dev/SOURCE_GROUP-properties.rst b/Help/release/dev/SOURCE_GROUP-properties.rst new file mode 100644 index 0000000000..117c0ed64d --- /dev/null +++ b/Help/release/dev/SOURCE_GROUP-properties.rst @@ -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. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index b8ad9e5661..71415887e3 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -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