[CMake] add_subdirectory and link_directories

Hendrik Sattler post at hendrik-sattler.de
Tue Jan 11 06:00:15 EST 2011


Zitat von "Thomas Petazzoni" <thomas.petazzoni at free-electrons.com>:
> On Tue, 11 Jan 2011 01:42:47 +0100
> Michael Hertling <mhertling at online.de> wrote:
>
>> Since CMake prefers to specify libraries by path instead of using
>> -l/-L or the like, there's usually no need for the LINK_DIRECTORIES()
>> command, IMO.
>
> Sorry to jump into the discussion, but I'm having a problem that I
> think is related to that.
>
> I have an application that links against Qt and another library which
> is found using pkg-config (and the PkgConfig CMake module). Due to the
> fact that I'm cross-compiling, the library is in a non-standard
> location (i.e: $HOME/something/usr/lib instead of /usr/lib).
> Unfortunately, the xxx_LIBRARIES variable filled by the PkgConfig
> module only contains "-lfoobar". So I'd like to either :
>
>  *) Tell the PkgConfig module to add the full path to the library, which
>     it seems is the CMake way of doing things.
>
>  *) Tell CMake about this $HOME/something/usr/lib path for which a -L
>     flag should be added. I've tried changing LINK_DIRECTORIES, but it
>     then completely breaks the build.
>
> Any clue ?

Ask the pkg-config guys to fix pkg-config to make it suitable for such a case?
It's already done in pkg-config but only on Windows. As a work-around,  
use the undocumented "pcfiledir" variable (see  
http://cgit.freedesktop.org/pkg-config/tree/pkg.c#n1235), go two  
directory levels up (strip lib/pkg-config from the end) and call  
pkg-config with this as "prefix" variable. Now, it magically does
it almost right (depending pkg-config modules may not be right).
Someone just needs to change the cmake module to do just that when  
cross-compiling :-/

OR: don't use or rely on pkg-config when cross-compiling.

HS



More information about the CMake mailing list