[cmake-developers] FindPkgConfig, find_program and stuff

Rolf Eike Beer eike at sf-mail.de
Sun Aug 19 14:38:50 EDT 2012


Am Sonntag, 19. August 2012, 20:26:35 schrieb Alexander Neundorf:
> On Sunday 19 August 2012, Rolf Eike Beer wrote:
> > I scanned through the patches Gentoo applies to CMake to find out which
> > ones should be dropped in 2.8.9. I found this one:
> > 
> > diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake
> > index c47f583..5783d37 100644
> > --- a/Modules/FindPkgConfig.cmake
> > +++ b/Modules/FindPkgConfig.cmake
> > @@ -87,7 +87,12 @@
> > 
> >  set(PKG_CONFIG_VERSION 1)
> >  set(PKG_CONFIG_FOUND   0)
> > 
> > -find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config DOC "pkg-config
> > executable") +if(NOT PKG_CONFIG_EXECUTABLE)
> > +       set(PKG_CONFIG_EXECUTABLE $ENV{PKG_CONFIG})
> > +       if(NOT PKG_CONFIG_EXECUTABLE)
> > +               find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config DOC
> > "pkg- config executable")
> > +       endif(NOT PKG_CONFIG_EXECUTABLE)
> > +endif(NOT PKG_CONFIG_EXECUTABLE)
> > 
> >  mark_as_advanced(PKG_CONFIG_EXECUTABLE)
> >  
> >  if(PKG_CONFIG_EXECUTABLE)
> 
> They should test first whether $ENV{PKG_CONFIG} is set and use it only if it
> is set. Or use the path from $ENV{PKG_CONFIG} as PATHS or HINTS for
> find_program().

It wouldn't be the first Gentoo patch for CMake I don't like, so I did not 
comment at this.

> > While thinking if we could do that better I found 2 things:
> > 
> > -Not related to this patch: autoconf searches for prefixed pkg-config
> > first, i.e. prefixed with the compiler prefix. We should probably do the
> > same when cross- compiling.
> 
> I am completely at a loss with pkg-config and cross compiling.
> In some cases there is a pkg-config for the target (i.e. can't be executed
> on the host), in some cases it's some script which can be executed on the
> host, another option is to set just the pkg-config related environment
> variables so that they point into the target file hierarchy, and as you say
> it seems there is also sometimes a <prefix>-pkg-config.
> 
> I don't know what should be done.

Neither do I. I just tell my observations, maybe someone who has actually read 
the spec will show up ;)

> > -We have a way to give hints about the paths via an environment variable
> > for find_program, but I think it would make sense to also allow
> > environment variables specifying the absolute path to the executable
> > itself as part of the find_program API.
> 
> Well, you can do
> $ cmake -DPKG_CONFIG_EXECUTABLE=/wherever/it/is/pkg-config ..
> already right now. Isn't this good enough ?

Well yes, sure. My thought was just a bit more general than this particular 
case. There may be cases where it is common to set an environment variable to 
point to an executable (independently of CMake). Something like $EDITOR. Then 
it would IMHO be useful if one could easily point CMake to look into just that 
environment variable without additional tricks. One could even think of 
implementing CMakes compiler search as doing find_program(... PROGRAM_ENV CC) 
or something like this.

Eike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20120819/5650d97a/attachment.sig>


More information about the cmake-developers mailing list