且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查找CMake包Eigen3

更新时间:2022-03-07 07:14:19

由于Eigen3只是完全的头,所以你需要的是include目录的路径。而这一个,你已经手动定义。因此,没有真正需要一个 FindEigen3.cmake FIND_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_DIR FindEigen3.cmake

  6. 的位置完全无关,但可能是您的

  7. 或者,自建的基于CMake的项目经常会使用这个变量来确定您的Eigen3安装的位置。提供一个< PackageName> Config.cmake 如果你指向一个名为< PackageName> _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.