Search code examples
cmakeeigen3pkg-config

How to enable pkg-config support in eigen3 on Windows?


I am compiling a 3rd party library which uses the following commands to find Eigen3:

find_package( PkgConfig )
pkg_check_modules( EIGEN3 REQUIRED eigen3 )
include_directories(${EIGEN3_INCLUDE_DIRS})

The find_package( PkgConfig ) command runs correctly because I specified the PKG_CONFIG_EXECUTABLE variable. But pkg_check_modules( EIGEN3 REQUIRED eigen3 ) returns an error:

-- Checking for module 'eigen3'

-- No package 'eigen3' found

The Eigen3's official webpage says "It is not necessary to use CMake or install anything." It took me quite a while to realize this statement is wrong. So I ran the following to compile and install Eigen3 (version 3.3.5):

cmake -DCMAKE_CONFIGURATION_TYPES=Release -DCMAKE_INSTALL_PREFIX=E:\3rd-parties\eigen-3.3.5\install_ -G"Visual Studio 14 2015 Win64" ..

The compilation and installation process were both successful because I didn't see any failure in VS2015. But, when I go back to the build folder of the 3rd party library and run cmake again, I got exactly the same error. Eigen3 official website only provides an instruction using find_package, but not pkg-config.exe, so I next searched Google and find this thread. The answer says we need to "enable pkg-config support in the eigen3 cmake". I don't know how to enable it. Is there any specific CMake variable for this purpose? Since it is a new problem, and Eigen's main page says "To get help, stackoverflow is your best resource." so I come here for help. My question is: how to enable pkg-config support in eigen3? Or to put it another way: how to pass the pkg_check_modules( EIGEN3 REQUIRED eigen3 ) cmake command? Thanks a lot.

PS: I am working on Windows 10.


Solution

  • According to the Eigen3 sources, an option EIGEN_BUILD_PKGCONFIG is responsible on pkg-config support.

    On Windows the whole option is disabled, but you may try to set it:

    cmake -DEIGEN_BUILD_PKGCONFIG=ON <... other arguments>
    

    When use pkg-config for find Eigen3 in CMake script, make sure that installation directory of Eigen3 is listed in CMAKE_PREFIX_PATH variable. (If CMake version used by a project is less than 3.1, then you need to additionally set PKG_CONFIG_USE_CMAKE_PREFIX_PATH to ON for tell pkgconfig module to use variable CMAKE_PREFIX_PATH. See more in the documentation for pkgconfig module.)