target_include_directories() vs headers in target_sources()

target_include_directories is relevant to the preprocessor (which is usually part of the compiler), since it allows to resolve #include preprocessor directives.

Adding headers with target_sources is relevant to IDEs (Visual Studio, Xcode, etc.) so they can display these header files, even if they are not directly compiled.

So these 2 functions are doing quite different things, and I can’t think of any situation where you would have to choose between them.

I hope this helps.

2 Likes