You are free to use pkg-config in FindXXX.cmake modules, as long as the following conditions are met:

You are free to use pkg-config in FindXXX.cmake modules, as long as the following conditions are met:

* the FindXXX.cmake must also work without pkg-config, as long as the package is either installed to one of the default locations (as /usr or /usr/local) or if CMAKE_PREFIX_PATH is set accordingly

* the FindXXX.cmake must also work without pkg-config, as long as the package is either installed to one of the default locations (as /usr or /usr/local) or if CMAKE_PREFIX_PATH is set accordingly

−

* use only FIND_PACKAGE(PkgConfig), don't use INCLUDE(UsePkgConfig), this one is deprecated

+

* use only find_package(PkgConfig), don't use include(UsePkgConfig), this one is deprecated

−

* make sure the variables created by PKG_CHECK_MODULES() are all prefixed with "PC_", so they don't mix up with other variables, e.g. set via FIND_PATH() etc.

+

* make sure the variables created by pkg_check_modules() are all prefixed with "PC_", so they don't mix up with other variables, e.g. set via find_path() etc.

* FindLibXml2.cmake as shipped with CMake 2.8.5 is a good example how pkg-config should be handled

* FindLibXml2.cmake as shipped with CMake 2.8.5 is a good example how pkg-config should be handled

* putting something like if(NOT WIN32) around the pkg-config stuff is not necessary (and should be removed if it is somewhere). If pkg-config is not found, e.g. on Windows, the macros simply do nothing.

* putting something like if(NOT WIN32) around the pkg-config stuff is not necessary (and should be removed if it is somewhere). If pkg-config is not found, e.g. on Windows, the macros simply do nothing.

should be removed, the find-logic should be executed always. These shortcuts can cause problems e.g. when the same file is used from multiple directories but e.g. with different required versions or components etc.