仅使用标头检查CMAKE中的EIGEN版本

发布于 2025-01-30 04:19:29 字数 689 浏览 0 评论 0原文

我想在我的一个项目中使用eigen。

用户直接决定打开/关闭特征,并配置了通往包含的路径。到目前为止,cmakelists.txt看起来像:

set(EIGEN_MODULE "OFF" CACHE BOOL "Enabled EIGEN MODULE ?")
if (EIGEN_MODULE)
        include_directories(${EIGEN_INCLUDE_DIR})
        set(EIGEN_INCLUDE_DIR /usr/local CACHE PATH "eigen include dir")
        if(NOT EXISTS ${EIGEN_INCLUDE_DIR})
            message(FATAL_ERROR "Bad eigen include dir")
        endif()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEIGEN_MODULE")  
        include_directories(${EIGEN_INCLUDE_DIR})
endif(EIGEN_MODULE)

但是,我不知道如何检查eigen的版本(我至少需要确保3.4.0),因为我想避免find_package(eigen3 3.4必需no_module) ),它需要用户编译特征。

有什么办法吗?

I want to use Eigen in one of my projects.

The user directly decides to turn Eigen ON/OFF and configures the path to the includes. So far, CMakeLists.txt looks like:

set(EIGEN_MODULE "OFF" CACHE BOOL "Enabled EIGEN MODULE ?")
if (EIGEN_MODULE)
        include_directories(${EIGEN_INCLUDE_DIR})
        set(EIGEN_INCLUDE_DIR /usr/local CACHE PATH "eigen include dir")
        if(NOT EXISTS ${EIGEN_INCLUDE_DIR})
            message(FATAL_ERROR "Bad eigen include dir")
        endif()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEIGEN_MODULE")  
        include_directories(${EIGEN_INCLUDE_DIR})
endif(EIGEN_MODULE)

However, I don't know how to check the version of Eigen (I need to ensure 3.4.0 at least), knowing that I want to avoid find_package (Eigen3 3.4 REQUIRED NO_MODULE) which would require the user to compile Eigen.

Is there any way to do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稳稳的幸福 2025-02-06 04:19:29

首先,关于您的问题的评论:eigen是仅标题库,这意味着用户不得不编译库,无论如何。

然后,要回答您的问题:您不应害怕使用find_package(eigen3),实际上 eigen的文档专门建议使用find_package在执行target_link_libraries之前。因此,您可以验证EIGEN具有具有find_package(eigen3 3.4必需)的适当版本,这是这样做的最佳方法。 find_package将读取文件eigen3config.cmake在cmake_prefix_path中找到的,其中包含适当的版本。

使用target_link_libraries来编译eigen似乎有些困惑,因为它仅是标题(您可以认为您要做的就是包括目录,因为eigen仅由标题文件组成,就像您在示例中所做的一样)。原因是Cmake支持所谓的接口库,这就是Eigen推荐的内容。

First a comment about your question: Eigen is a header only library, it means that the user will have to compile the library, no matter what.

Then, to answer your question: you shouldn't be scared to use find_package(Eigen3), actually the documentation of Eigen specifically recommends to use find_package before performing a target_link_libraries. So you can validate that Eigen has the proper version with find_package (Eigen3 3.4 REQUIRED), this is the best way to do it. find_package will read the file Eigen3Config.cmake found in the CMAKE_PREFIX_PATH, and that will contain the proper version.

It can seem a little confusing to use target_link_libraries to compile Eigen, since it is header-only (you could think that all you have to do is to include the directories, since Eigen is merely composed of header files, like you have done in your example). The reason is that CMake supports what is called interface library, and this is what is recommended by Eigen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文