[CMake] [RFC] How to use pkg-config under Windows (... and OSX) ?

Alexander Neundorf a.neundorf-work at gmx.net
Tue Nov 15 12:07:16 EST 2011


Hi,

cmake ships with a FindPkgConfig.cmake file, which is used by some Find-
modules.
Also in KDE, we have quite a lot of Find-modules which use 
FindPkgConfig.cmake.

Now, some of them put a 

if(UNIX)
  find_package(PkgConfig)
endif()

around it, some use it on all platforms.

In theory it works also on Windows, and also on OSX, so that this if() would 
not be necessary.

But our (KDEs) Windows developer team says that even if pkg-config is found 
under Windows, and even if it reports something, they actively want to ignore 
it.

The reason for this is that for those packages under Windows the user decides 
at install-time where the package will be installed, while the pc-files for 
pkg-config have been generated at build-time with the install directory the 
developer chose at build-time.
This directory chosen by the developer and hardcoded into the pc-files and the 
actual install directory chosen by the user can very well be different.

If this is the case, then pkg-config reports wrong include and wrong link 
directories, and the build will work worse than without pkg-config.

Similar issues may exist under OSX, for libraries which are installed as a 
package where the user can decide at install time where to put them.


So, I am looking for a, if possible, generic solution to his problem.

Options I see:

1) exclude it from being used under Windows in the Find-modules:
if(UNIX)
  find_package(PkgConfig)
endif()

2) completely exclude it under Windows by putting something like the following 
into FindPkgConfig.cmake:
if(WIN32)
  return()
endif()

3) don't exclude it, but hope it reports good results (our Windows developers 
disagree)
 
4) add cache option whether pkg-config should be used under Windows, so 
something like the following would be in FindPkgConfig.cmake:

if (NOT CMAKE_USE_PKGCONFIG_UNDER_WIN32)
  return()
endif()


5) something else...

Comments ?


Alex


More information about the CMake mailing list