为 CMake 查找包 Eigen3 [英] Find package Eigen3 for CMake

查看:37
本文介绍了为 CMake 查找包 Eigen3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CMake 找不到我的 Eigen3 包.我设置了一个名为

CMake cannot find my Eigen3 package. I set an environment variable called

EIGEN3_INCLUDE_DIR

指向FindEigen3.cmake所在的路径.

然后在 CMakelists.txt 中我写道:

Then in the CMakelists.txt I wrote:

find_package( Eigen3 REQUIRED )
include_directories( EIGEN3_INCLUDE_DIR )

我收到下一条错误消息:

I get next message of error:

CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:91 (MESSAGE):
  Could NOT find Eigen3 (missing: EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
  (Required is at least version "2.91.0")
Call Stack (most recent call first):
  C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:252 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindEigen3.cmake:76 (find_package_handle_standard_args)
  test/test_quaternion/CMakeLists.txt:25 (find_package)

知道我遗漏了什么或做错了什么吗?

Any idea on what I am missing or doing wrong?

推荐答案

由于 Eigen3 完全只是标题,因此您只需要包含目录的路径.而这个,无论如何你已经在手动定义了.所以实际上不需要 FindEigen3.cmakeFIND_PACKAGE 调用.

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.

简单使用

INCLUDE_DIRECTORIES ( "$ENV{EIGEN3_INCLUDE_DIR}" )

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}" )

一些注意事项:

  1. 如果您想访问 CMake 变量的内容,请确保使用 ${...}
  2. $ENV{....} 访问环境变量.
  3. 如果未设置环境变量(因此,EIGEN3_INCLUDE_DIR cmake 变量为空),则第二个示例将因错误而停止
  4. 如果(已计算的)变量可能包含空格,请小心使用引号将它们括起来.否则,CMake 会将其解释为列表.
  5. 如果您想使用自定义查找模块,请确保将它们放置在您的 CMake 安装中,或者,正如上面@Fraser 指出的那样,确保将 CMAKE_MODULE_PATH 指向它所在的目录.不确定,但可能是 CMake 也会自动检查当前目录(您的 CMakeLists.txt 所在的位置.无论如何,设置 EIGEN3_INCLUDE_DIREIGEN3_INCLUDE_DIR 的位置完全无关代码>FindEigen3.cmake
  6. 但是,您的 FindEigen3 脚本可能会评估这个变量以确定您的 Eigen3 安装位置.
  7. 或者,基于 CMake 的自建项目通常提供 Config.cmake.如果您将名为 _DIR 的变量指向包含此文件的目录,您可以正常使用 FIND_PACKAGE( <PackageName> ...) .有关详细信息,请参阅FIND_PACKAGE 的文档.
  1. If you want to access the content of a CMake variable, make sure to use ${...}
  2. $ENV{....} accesses environment variables.
  3. The second example will stop with an error if the environment variable is not set (and, thus, EIGEN3_INCLUDE_DIR cmake variable is empty)
  4. Be careful to use quotation marks around (evaluated) variables if they could contain whitespace. Otherwise, CMake will interpret it as a list.
  5. 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 your CMakeLists.txt resides. Anyhow, setting EIGEN3_INCLUDE_DIR is totally unrelated to the location of FindEigen3.cmake
  6. However, it could be that your FindEigen3 script evaluates this variable to determine the location of your Eigen3 installation.
  7. 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 use FIND_PACKAGE( <PackageName> ...) as normal. See documentation of FIND_PACKAGE for details.

这篇关于为 CMake 查找包 Eigen3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆