Search code examples
cmakehomebrewpkg-config

Cmake can't find "cairo" using pkg_search_module when installed with brew


On Mac Mojave using brew for installing packages, CMake fails with

find_package(PkgConfig)
pkg_search_module(CAIRO REQUIRED cairo>=1.12.16)

With error message:

CMake Error at /usr/local/Cellar/cmake/3.15.2/share/cmake/Modules/FindPkgConfig.cmake:696 (message):
  None of the required 'cairo>=1.12.16' found

Running:

pkg-config --modversion cairo

yields the valid version currently installed 1.16.0, but it is still not found in CMake.


Solution

  • Running

    pkg-config --exists --print-errors cairo
    

    Actually gives the answer to why it is not found:

    Package libffi was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libffi.pc'
    to the PKG_CONFIG_PATH environment variable
    Package 'libffi', required by 'gobject-2.0', not found
    

    As suggested adding libffi to the pkg-config path will solve the issue. Add this to your .bash_profile or just to your env variables.

    export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
    

    This is also given when you run brew info libffi.