Little question about command "target_sources(FILE_SET)"

I’m using the command target_sources(FILE_SET) to add header files for my project.

I find the following description in official documentation.

In my native opinion, I thouht if relative paths are specified, they are considered relative to BASE_DIRS specified dirs, cmake will compose/resolve the final absolute paths of each file items for me. So I don’t understand the meaning of BASE_DIRS parameter in target_sources() command. Can I think this argument is only used for checking the rightness of file items specified by FILES argument?

May anybody help me understand this question? Thank you very much!
BEST WISHES!

The purpose of BASE_DIRS is to be able to compute a “root” for each file listed. Without this information, when installing the headers, it is ambiguous how many path components should be preserved upon installation. Should /path/to/some/header/under/directories/header.h be installed to <include>/header.h, <include>/directories/header.h, <include>/under/directories/header.h, or any other possibility? That is what BASE_DIRS is for (and why each file must live under exactly one such BASE_DIRS entry).

1 Like

THANK YOU VERY MUCH! :smiling_face_with_three_hearts:

I’ve tried it in my project, changing the value of BASE_DIRS’ value, then executing install/cpack command, get the result what you explained above.

After all, I have another question about the explanation, I didn’t see similar description in official documentation


Can you tell me where to find the more detailed description about each parameter specified in each cmake command? SO that I wouldn’t have to issue such post to waste your time to solve this kind of questions. :thinking:

That would be the docs you have. If you have suggestions to make it clearer, the docs could always use improvement.

Alternatively, a step of the tutorial could explain this better in prose where it is used (and we should add an example if we don’t already have one).

Thanks!

I agree with you, an example is much better than tedious prose style!

I have no other questions, thank you for your support!

best wishes!

Issue filed: https://gitlab.kitware.com/cmake/cmake/-/issues/26153