How to set the usage requirements (includes) for current project


I have a library project, whose code and the main CMakeLists.txt are a src directory.
The root contains a CMakeLists.txt with some general settings and the install() stuff.

Thanks to the install() commands, the clients have to include .h as I wish (MyLib is added by the install process):
#include <MyLib/SubDir/SomeFile.h

But I’d like also the MyLib sources can include the .h in the same way (even if there is not MyLib directory). I suppose I should use ALIAS, but I am not sure how to use it.

Note my sources are defined by FILE SET, so I don’t use the target_include_directories() command.

I don’t think that’s possible, and it’s definitely not something CMake could do on its own. How #include directives are processed is up to the compiler (its preprocessor, to be exact). If there is a way to “fake” directories in #include directives, it will be documented in the compiler’s docs.

Use the same directory structure in your source tree that you want to use when installed. That is basically what the FILE_SET functionality is assuming you are doing, with the path below a BASE_DIRS controlling the header’s installed location and matching what consumers will need to #include.

OK, thank you !