If I link a library, do I also get the header files it uses without having to declare it in target_include_directories or target_sources

If I use target_sources() to add a couple of header files to a library target, and then link that library to another target using target_link_libraries(), do I automatically inherit the include paths for those headers?

In other words, if I include one of those headers inside a source file of the new library, will the compiler automatically know where to find it? Or do I still need to explicitly specify the include directories using target_include_directories()?

I’m trying to understand whether adding headers via target_sources() is enough to propagate their include paths to dependent targets, or whether include directories must always be exported separately.

Kind regards

Plain target_sources() adding a bare header won’t do it for you, but if you add the header to a file set (which is done using target_sources() with the FILE_SET keyword), then header search paths will be handled for you. Read up on file sets in the target_sources() documentation to understand how it works. It requires you to think about your directory structure and what directories you want to be propagated to consumers of a target. It isn’t quite “CMake figures everything out for you” (because it can’t, you have to make some decisions).