Trigger rebuild when a system header changes

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Trigger rebuild when a system header changes

Lassi Niemistö



It seems CMake has a special handling for system header dependencies. I.e. if my .c file includes /usr/include/someheader.h, modifying the someheader.h does not cause the .c file to be rebuilt.


How to work around this issue? We have some custom libraries that get installed to system paths and they change relatively often. It is error-prone for the developers to accidentally keep using the library with old header compiled in.


Things I have tried this far:
* add_dependencies(target /path/to/header.h) 
à no luck

* add_library(include_deplib /path/to/header.h) + target_link_libraries(target include_deplib) à needs additional tweaking to be legal, still does not work

* OBJECT_DEPENDS property pointing to the .h fileà This works but I need to do this for each c. file separately


I wonder if this should be this difficult, I am probably missing something? Can I just somehow enable tracking system headers also as expected-to-change dependencies?




Powered by

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:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: