MantisBT - CMake
View Issue Details
0015407CMakeCMakepublic2015-02-17 09:172016-06-10 14:31
S. Paris 
Kitware Robot 
normalfeaturealways
closedmoved 
WIN64Windows8.1 Pro
CMake 3.1.3 
 
0015407: source_group: Multiple REGEX and Checking
It would be really convenient to have the possibility for source_group to:
1. Specify multiple regular expressions in one or multiple commands:
   source_group("foo" REGULAR_EXPRESSIONS reg0 reg1)
   source_group("foo" REGULAR_EXPRESSION reg2)
   # Would result in "foo" being selected for files matching reg0, reg1, or reg2
2. Check if a source_group has been specified:
   get_source_group("foo" FILES result0 REGULAR_EXPRESSION result1)
   # Would fill result0 with the files defined for "foo" and result1 with the regexps defined for "foo"
source_group("foo" REGULAR_EXPRESSION reg0)
source_group("foo" REGULAR_EXPRESSION reg1)
# from here "foo" group will not be selected anymore for files matching reg0 but not reg1
1. should really be a piece of cake to implement, just make "cmsys::RegularExpression GroupRegex" in cmSourceGroup.h a "std::set<cmsys::RegularExpression>" as it is for GroupFiles; update cmSourceGroupCommand.cxx accordingly.

2. is using Makefile->GetSourceGroup() and is even simpler to implement isn't it?
No tags attached.
Issue History
2015-02-17 09:17S. ParisNew Issue
2015-02-18 10:45Ben BoeckelNote Added: 0037993
2015-02-18 12:14S. ParisNote Added: 0037994
2015-02-18 12:15S. ParisNote Edited: 0037994bug_revision_view_page.php?bugnote_id=37994#r1707
2016-06-10 14:29Kitware RobotNote Added: 0042716
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0037993)
Ben Boeckel   
2015-02-18 10:45   
One problem here is this documentation for source_group:

    If a source file matches multiple groups, the *last* group that
    explicitly lists the file with ``FILES`` will be favored, if any.
    If no group explicitly lists the file, the *last* group whose
    regular expression matches the file will be favored.

What happens with this:

    source_group(foo REGULAR_EXPRESSION .*foo.*)
    source_group(bar REGULAR_EXPRESSION .*bar.*)
    source_group(foo REGULAR_EXPRESSION .*baz.*)

for a file named "foobarbaz.cpp"? "bar" is the last group which matches, but "foo" is the group with the last regular expression which matches. IMO, the "bar" group should match since it is implied that each group is checked in order (not the declaration of the regular expressions), but this might be surprising (though documentation can help clarify it).

Also gives me the idea that it might make sense to support properties on source groups for things like FILES and REGULAR_EXPRESSION so that get_property/set_property can be used rather than new commands for querying them. With that, multi-regex could then be done with:

    get_property(sg_regex SOURCE_GROUP foo PROPERTY REGULAR_EXPRESSION)
    set_property(SOURCE_GROUP foo PROPERTY REGULAR_EXPRESSION "(${sg_regex}|new_regex)")
(0037994)
S. Paris   
2015-02-18 12:14   
(edited on: 2015-02-18 12:15)
What is not explicit in the documentation is that the Regexp is overridden when calling source_group multiple times for the same group.

So what bothers me in your example is that a file call "foo.cpp" will not be matched at all, when I would expect it to be matched by the group "foo" (using the first RegExp).

Regarding the set_property(SOURCE_GROUP foo PROPERTY REGULAR_EXPRESSION "(${sg_regex}|new_regex)"), it indeed makes it possible to check and update the regexp, but it is really not convenient to use...

(0042716)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.