Since Eigen3 is completely header only, all you ever need is the path to the include directory. And this one, you are already defining manually anyway. So there is no real need for a FindEigen3.cmake
or FIND_PACKAGE
call.
Simply use
INCLUDE_DIRECTORIES ( "$ENV{EIGEN3_INCLUDE_DIR}" )
or
SET( EIGEN3_INCLUDE_DIR "$ENV{EIGEN3_INCLUDE_DIR}" )
IF( NOT EIGEN3_INCLUDE_DIR )
MESSAGE( FATAL_ERROR "Please point the environment variable EIGEN3_INCLUDE_DIR to the include directory of your Eigen3 installation.")
ENDIF()
INCLUDE_DIRECTORIES ( "${EIGEN3_INCLUDE_DIR}" )
A few notes:
- If you want to access the content of a CMake variable, make sure to use
${...}
$ENV{....}
accesses environment variables.- The second example will stop with an error if the environment variable is not set (and, thus, EIGEN3_INCLUDE_DIR cmake variable is empty)
- Be careful to use quotation marks around (evaluated) variables if they could contain whitespace. Otherwise, CMake will interpret it as a list.
- If you want to use custom find modules, make sure to either place them in you CMake installation or, as @Fraser pointed out above, make sure to point
CMAKE_MODULE_PATH
to the directory where it is. Not sure, but it could be that CMake checks the current directory as well automatically (where yourCMakeLists.txt
resides. Anyhow, settingEIGEN3_INCLUDE_DIR
is totally unrelated to the location ofFindEigen3.cmake
- However, it could be that your
FindEigen3
script evaluates this variable to determine the location of your Eigen3 installation. - Alternatively, self-built CMake-based projects often provide a
<PackageName>Config.cmake
. If you point a variable called<PackageName>_DIR
to the directory containing this file, you can useFIND_PACKAGE( <PackageName> ...)
as normal. See documentation of FIND_PACKAGE for details.