[CMake] Sub dependencies?
Andreas Pakulat
apaku at gmx.de
Fri Aug 12 03:11:52 EDT 2011
On 12.08.11 11:23:46, Doug wrote:
> That works if it's all in a single project, but it's not.
>
> I totally understand you can do this:
>
> add_library(foo)
> target_link_library(foo bar)
> add_executable(exec)
> target_link_library(exec foo)
>
> If you have _this_ structure:
>
> .../liba/CMakeLists.txt
> ....
>
> .../blah/libb/CMakeLists.txt
> ....
>
> ..../some/other/path/exec/CMakeLists.txt
>
> Then in exec you can you use find_package(libb REQUIRED)
>
> However, when I compile it I still get dependency resolution errors on liba
> (libpng in my case).
>
> I'm guessing thats because to resolve libb all you get a include path and a
> library path; find package has no way to load the CMakeLists.txt in libb/
> and parse it, add the dependency to liba.
>
> Seems like there should be a way to do this though.
>
> Am I wrong?
>
> Should the values in libb's CMakeLists.txt be propagating through?
No. Whats supposed to happen is that find_package will give you a
cmake-variable containing the absolute path to the png-library. And that
variable you should use in your target_link_libraries call:
target_link_libraries( exec ${PNG_LIBRARY} )
If you look at the cmake manual for target_link_libraries you'll notice
that the 'target' in its name refers to its first argument. The second
and all following arguments are basically just link-flags for the
linker.
Andreas
More information about the CMake
mailing list