[cmake-developers] FindPkgConfig, find_program and stuff

Alexander Neundorf neundorf at kde.org
Sun Aug 19 14:26:35 EDT 2012


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().

> 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.
 
> -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 ?

Alex



More information about the cmake-developers mailing list