source_group: add genex support

Fixes: #19813
This commit is contained in:
HannaWAR
2025-11-21 11:44:30 +03:00
committed by hanna.rusakovich
parent efed08ac1a
commit 2628c52e04
12 changed files with 85 additions and 0 deletions

View File

@@ -36,6 +36,10 @@ The options are:
``<name>``. Relative paths are interpreted with respect to the
current source directory.
.. versionadded:: 4.3
Arguments to ``FILES`` may use
:manual:`generator expressions <cmake-generator-expressions(7)>`.
``REGULAR_EXPRESSION``
Any source file whose name matches the regular expression will
be placed in group ``<name>``.

View File

@@ -0,0 +1,4 @@
source_group-genex
------------------
* The :command:`source_group` supports generator expressions

View File

@@ -1579,6 +1579,12 @@ bool cmGlobalGenerator::Compute()
this->AddExtraIDETargets();
#ifndef CMAKE_BOOTSTRAP
for (auto const& localGen : this->LocalGenerators) {
localGen->ResolveSourceGroupGenex();
}
#endif
// Trace the dependencies, after that no custom commands should be added
// because their dependencies might not be handled correctly
for (auto const& localGen : this->LocalGenerators) {

View File

@@ -319,6 +319,13 @@ void cmLocalGenerator::TraceDependencies() const
}
}
#ifndef CMAKE_BOOTSTRAP
void cmLocalGenerator::ResolveSourceGroupGenex()
{
this->Makefile->ResolveSourceGroupGenex(this);
}
#endif
void cmLocalGenerator::GenerateTestFiles()
{
if (!this->Makefile->IsOn("CMAKE_TESTING_ENABLED")) {

View File

@@ -84,6 +84,13 @@ public:
*/
void TraceDependencies() const;
#ifndef CMAKE_BOOTSTRAP
/**
* Resolve source group genex.
*/
void ResolveSourceGroupGenex();
#endif
virtual void AddHelperCommands() {}
/**

View File

@@ -2082,6 +2082,14 @@ namespace {
}
#if !defined(CMAKE_BOOTSTRAP)
void cmMakefile::ResolveSourceGroupGenex(cmLocalGenerator* lg)
{
for (cmSourceGroup& sourceGroup : this->SourceGroups) {
sourceGroup.ResolveGenex(lg, {});
}
}
cmSourceGroup* cmMakefile::GetSourceGroup(
std::vector<std::string> const& name) const
{

View File

@@ -612,6 +612,12 @@ public:
bool CanIWriteThisFile(std::string const& fileName) const;
#if !defined(CMAKE_BOOTSTRAP)
/**
* Resolve source group genex.
*/
void ResolveSourceGroupGenex(cmLocalGenerator* lg);
/**
* Get the vector source groups.
*/

View File

@@ -6,6 +6,8 @@
#include <cm/memory>
#include "cmGeneratorExpression.h"
#include "cmSourceFile.h"
#include "cmStringAlgorithms.h"
class cmSourceGroupInternals
@@ -59,6 +61,26 @@ void cmSourceGroup::SetGroupRegex(char const* regex)
}
}
void cmSourceGroup::ResolveGenex(cmLocalGenerator* lg,
std::string const& config)
{
std::set<std::string> files;
for (std::string const& file : this->GroupFiles) {
files.emplace(cmGeneratorExpression::Evaluate(file, lg, config));
}
this->GroupFiles = std::move(files);
if (!this->Internal) {
return;
}
for (cmSourceGroup& group : this->Internal->GroupChildren) {
group.ResolveGenex(lg, config);
}
}
void cmSourceGroup::AddGroupFile(std::string const& name)
{
this->GroupFiles.insert(name);

View File

@@ -11,6 +11,7 @@
#include "cmsys/RegularExpression.hxx"
class cmLocalGenerator;
class cmSourceFile;
class cmSourceGroupInternals;
@@ -38,6 +39,11 @@ public:
*/
void SetGroupRegex(char const* regex);
/**
* Resolve genex.
*/
void ResolveGenex(cmLocalGenerator* lg, std::string const& config);
/**
* Add a file name to the explicit list of files for this group.
*/

View File

@@ -21,6 +21,7 @@ run_cmake(RuntimeLibrary)
run_cmake(SourceGroupCMakeLists)
run_cmake(SourceGroupTreeCMakeLists)
run_cmake(SourceGroupFileSet)
run_cmake(SourceGroupFileSetGenex)
run_cmake(VsConfigurationType)
run_cmake(VsTargetsFileReferences)
run_cmake(VsCustomProps)

View File

@@ -0,0 +1,11 @@
set(vcFiltersFile "${RunCMake_TEST_BINARY_DIR}/SourceGroupFileSetGenex.vcxproj.filters")
if(NOT EXISTS "${vcFiltersFile}")
set(RunCMake_TEST_FAILED "Filters file ${vcFiltersFile} does not exist.")
return()
endif()
file(STRINGS "${vcFiltersFile}" lines)
include(${RunCMake_TEST_SOURCE_DIR}/SourceGroupHelpers.cmake)
find_source_group("${lines}" "Header Files\\SourceGroupFileSetGenex")

View File

@@ -0,0 +1,3 @@
add_library(SourceGroupFileSetGenex INTERFACE)
target_sources(SourceGroupFileSetGenex PUBLIC FILE_SET HEADERS FILES "$<$<BOOL:TRUE>:iface.h>")
source_group("Header Files/SourceGroupFileSetGenex" FILES "$<$<BOOL:TRUE>:iface.h>")