With PKG_CONFIG_EXECUTABLE set, find_package(LibXml2) before using FindPkgConfig causes pkg_search_module failure
Using CMake 3.7. Observed in a cross-compile (hence setting PKG_CONFIG_EXECUTABLE), but reproducible in a minimal example on my Ubuntu 14.04 box without all the cross-compile junk.
cmake_minimum_required(VERSION 3.0)
project(hello)
set(PKG_CONFIG_EXECUTABLE "/usr/bin/pkg-config")
find_package(LibXml2)
find_package(PkgConfig REQUIRED)
pkg_search_module(dbus REQUIRED dbus-1) # dbus is just an example
add_executable(hello main.c)
Results in:
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.1")
CMake Error at /home/patrick/opt/cmake-3.7.1/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) (found version
"0.26")
Call Stack (most recent call first):
/home/patrick/opt/cmake-3.7.1/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/home/patrick/opt/cmake-3.7.1/share/cmake-3.7/Modules/FindPkgConfig.cmake:36 (find_package_handle_standard_args)
CMakeLists.txt:13 (find_package)
-- Configuring incomplete, errors occurred!
However reversing the order of the find calls succeeds:
cmake_minimum_required(VERSION 3.0)
project(hello)
set(PKG_CONFIG_EXECUTABLE "/usr/bin/pkg-config")
find_package(PkgConfig REQUIRED)
pkg_search_module(dbus REQUIRED dbus-1) # dbus is just an example
find_package(LibXml2)
add_executable(hello main.c)