[CMake] target_link_libraries fails dependencies

Andreas Pakulat apaku at gmx.de
Wed Nov 14 07:01:37 EST 2012


Hi,

On Wed, Nov 14, 2012 at 12:34 PM, Andrea Galeazzi <galeazzi at korg.it> wrote:
> I'm using cmake_policy(SET CMP0015 NEW) to link external libraries (I don't
> have the sources of them) in order to avoid to specify the absolute path of
> each library. So I wrote the following commands:
> link_directories(path1 path2 ...)
> target_link_libraries(${my_TARGET_NAME} lib1 lib2)
>
> but when lib1 or lib2 changes, my_TARGET_NAME doesn't rebuild the
> executable. On the other hand if I use the absolute path in
> target_link_libraries (path1/lib1.a) everything works fine.
> Is this behavior a bug of CMake or is not possible to detect this kind of
> dependencies at all?

That is not a bug in CMake. When you specify only library names CMake
cannot setup dependencies in the generated makefiles (or whatever
generator you use), since it has no clue where the library file is as
you leave the knowledge about that to the linker. So you either need
to specify the absolute path to lib1 and lib2 or trigger a clean build
of the target when the libs change.

Since it seems you already setup the paths to the libraries via
link_directories it should actually be rather easy for you to drop
that and simply use the absolute path in target_link_libraries I'd
say.

Andreas


More information about the CMake mailing list