[CMake] Avoiding a relink

Philip Lowman philip at yhbt.com
Fri Feb 27 14:19:53 EST 2009


On Fri, Feb 27, 2009 at 2:09 PM, Bill O'Hara <billtohara at gmail.com> wrote:

> Lets say I have a CMakeLists.txt like this:
>
> add_library(foo STATIC foo.c bar.c)
> add_executable(test test.c)
> target_link_libraries(test foo)
>
> where test.c uses only functions defined in foo.c but not bar.c (assume
> some other target will use foo as well and use functions from both foo.c and
> bar.c).
>
> Is it possible to avoid the relink of test when foo is changed because of a
> change in bar.c? Just as an optimization to avoid unnecessary relinks to
> speed up the user experience?


You could just link test.c against bar.c if that's all it needs, or just
compile "bar.c" directly into the test app.

Barring that I don't see a way to tell CMake that the "test" executable only
cares about symbols from certain source files in a static library.  The
static library is a collection of all of the symbols.  When it is
regenerated due to dependencies CMake will relink test against it.

For your particular case, if you're using a shared library you could just
type "make foo" and then run test without relinking it.  Of course, CMake
will still relink test on a regular "make" as it should.

-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090227/bd6017ca/attachment.htm>


More information about the CMake mailing list