I'm pretty new to cmake and I came across a question which I could not find
any information about in the official documentation or blog posts.

When adding a target through add_library / add_executable - should the
header files of the target also be listed?
The question also applies to target_sources I guess.

On one hand - as far as I can tell it compiles perfectly fine without doing
so, and the implicit dependency is also recognized (e.g if the header
changes - the target will be recompiled)
In addition most of the online examples do not list headers.

On the other hand - it seems wrong not to list them. They ARE part of the
target, even if they do not passed to the compiler directly.
I can also assume that some IDEs will want to know about the existence of
these headers and their relationship with the target.

So what is the correct answer? should header files be listed as part of the

Another question - how does cmake know to create the dependency between the
target and the header file, even when it is not listed explicitly?

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 

Follow this link to subscribe/unsubscribe:

Reply via email to