I am trying to use source_group
to show the files nicely in my IDE (Visual Studio 2022). The structure of my header files has some files in subfolders and others only in the include
folder (sorry I can only embed one photo):
include
├── DD
│ ├── comparator.hpp
│ ├── dd_solution.hpp
│ └── vertex.hpp
├── FORPFSSPSD
│ ├── FORPFSSPSD.h
│ ├── aliases.hpp
│ ├── plexity.hpp
│ └── ...
├── cyclefinder.h
├── delay.h
└── ...
And I use this CMake code to group the header files (LIB_COMMON_HEADERS
has the list of all headers):
source_group(
TREE "${PROJECT_SOURCE_DIR}/include"
PREFIX "Header Files"
FILES ${LIB_COMMON_HEADERS}
)
However, in Visual Studio 2022 it shows as follows:
Notice how the files immediately in the folder include/*.h
and not in a subfolder are not added in to the “Header files” group.
I’ve also noticed that if I define the subgrup as follows (removing /include
from the TREE
):
source_group(
TREE "${PROJECT_SOURCE_DIR}"
PREFIX "Header Files"
FILES ${LIB_COMMON_HEADERS}
)
Then the files are grouped but all inside the include
directory but not immediately inside the Header Files
group:
Header Files
└── include
├── DD
│ ├── comparator.hpp
│ ├── dd_solution.hpp
│ └── vertex.hpp
├── FORPFSSPSD
│ ├── FORPFSSPSD.h
│ ├── aliases.hpp
│ ├── plexity.hpp
│ └── ...
├── cyclefinder.h
├── delay.h
└── ...
Am I doing something wrong? Shouldn’t the first code already work properly? If my code is fine, is this a bug in CMake or Visual Studio 2022?