When defining a CMake target which is a library or executable, resulting from compiling various source files, one can either specify just the source files, or also specify some or all of the header files they include, from within the project, as dependencies.
In his Meeting C++ 2019 talk (and also in 2018), presenter Deniz Bahadir recommends that we specify targets' C++ header files using target_sources()
, with some of them being PUBLIC or INTERFACE. (Of course it doesn't really matter if one adds headers via add_executable()
with the list of dependencies, or using a later target_sources()
command).
Both of these seem to work fine. The question is - what are the pros and cons of specifying the headers, beyond the con of being more verbose?
Note: I'm asking specifically regarding C++, but the question stands for C or any languages which can include headers.