Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only relink shared libraries when headers change in CMake

Using CMake, is there a way to generate build systems that don't relink everything downstream if a shared library's source code changes without its headers changing?

In Makefiles, I've used rules with an order only prerequisite on the shared library itself and regular prerequisites on the library headers to get this effect.

I know this isn't strictly guaranteed to produce a correct build, e.g. you could delete a function definition from the shared library, but this is for quickly rebuilding a debug build and in my experience it almost always has produced a correct build. I think there was once or twice that I ran into a runtime linker error but on that odd occasion it's not much trouble to run the build as usual.

Still, if there are good reasons that this is actually a terrible idea and shouldn't be done that could be an answer too.

like image 893
Praxeolitic Avatar asked Jan 09 '15 18:01

Praxeolitic


1 Answers

In CMake 2.8.11 and later you can set CMAKE_LINK_DEPENDS_NO_SHARED to get this behavior.

http://thread.gmane.org/gmane.comp.programming.tools.cmake.user/43246/focus=44469

http://www.cmake.org/cmake/help/v3.1/prop_tgt/LINK_DEPENDS_NO_SHARED.html

like image 167
steveire Avatar answered Oct 16 '22 17:10

steveire