SOURCE_GROUP does not work for regular expressions AND no-name groups
This issue was created automatically from an original Mantis Issue. Further discussion may take place here. The original description is reproduced below:
CMake creates the default source groups (in context of MSVC "filters") "Header Files" and "Source Files" for convenience and puts all files to the appropriate group. This behavior can be overwritten by specifying own source groups and put each and every file to them. If there is any file left, both default source groups will be created. OK, fine so far.
Imagine the following scenario where you want to put each file into a source group that matches its path:
- Foo.h
- Foo.cpp
- Bar/Bar.h
- Bar/Bar.cpp
The following snippet works:
source_group("" FILES Foo.h Foo.cpp) # no-name group -> no filter
source_group(Bar FILES Bar/Bar.h Bar/Bar.cpp)
add_executable(FooBar Foo.h Foo.cpp Bar/Bar.h Bar/Bar.cpp)
No "Header Files" nor "Source Files" filters are generated, only the "Bar" filter containing Bar.h and Bar.cpp. Foo.h and Foo.cpp are located at the top level of the project. Perfect!
Of course you have more files in a real world scenario so you may prefer to use the regular expression versions of source_group which work well except for the case of a no-name group:
source_group("" "[^/]+\\.(cpp|h)") # BUG!
source_group(Bar "Bar/[^/]+\\.(cpp|h)")
For simplicity you can reduce the regular expressions to something like "Foo\.(cpp|h)" and "Bar/Bar\.(cpp|h)", it doesn't matter.
With a regular expression no-name groups do not work at all. "Header Files" and "Source Files" filters are created and everything is put into them instead.