Search code examples
c++cmakelibxml2clion

CMake find_package for FindLibXml2


I'm trying to create a CMake file that will detect the location of libxml2. From what see in examples and CMake documentation the find_package simply works. I'm running CLion on Ubuntu, the libxml2 is installed using apt-get, the FindLibXml2.cmake is located under CMake's modules. However CMake returns cryptic message:

Could not find a package configuration file provided by "FindLibXml2" with any of the following names:

FindLibXml2Config.cmake
findlibxml2-config.cmake

Add the installation prefix of "FindLibXml2" to CMAKE_PREFIX_PATH or set "FindLibXml2_DIR" to a directory containing one of the above files. If "FindLibXml2" provides a separate development package or SDK, be sure it has been installed.

Why it is trying to find this -config file? what I'm doing wrong?

CMake snippet

find_package(FindLibXml2 CONFIG REQUIRED)

I've also tried

find_package(FindLibXml2 REQUIRED)

Not sure which one to use


Solution

  • You should not have the Find in FindLibXml2; do:

    find_package(LibXml2 REQUIRED)
    

    As explained in the documentation:

    CMake searches for a file called Find<package>.cmake