FindLibXml2 uses inconsistent information with multiple installations
Follow up to !4167 (merged) to discuss the problem and design a proper strategy.
Given multiple installations of libxml2 the FindLibXml2
module may not report all its information from the same and consistent installation. For example, with a system installation of the libxml2-dev
, version 2.9.4 on Debian and a manual installation of libxml2/2.9.9
from conan, I get the following report (using the cmake_paths
conan's generator which adjust CMAKE_MODULE/PREFIX_PATH
):
...
-- Found LibXml2: /home/debian/.conan/data/libxml2/2.9.9/_/_/package/3209e3d694b93935209e34721c93868ff0c2b291/lib/libxml2.so (found version "2.9.4")
...
The conan installation is correctly found but the reported version is still the one from the system.
The current approach of the module is to call pkg-config
then to use the info from it to manually look for the library and headers. But nothing guarantees that the installation found by pkg-config
will be the one found by find_library/path
(which is not the case when CMAKE_MODULE/PREFIX_PATH
are adjusted).
There seems to be multiple issues in the way this module looks for the library information:
- The version number is taken by default from the
pkg-config
info and only if not present retrieved from a particular header file. I first suggested to invert the logic and use retrieve the version from the actual header. Or we can simply remove the fallback topkg-config
version and always use the header. Are there libxml2 installations without thexmlversion.h
header? - The
LIBXML2_DEFINITIONS
variable only comes frompkg-config
and is also not used to craft the imported target. But on my system the variable is empty, so maybe the current behavior is fine.