仅使用标头检查CMAKE中的EIGEN版本
我想在我的一个项目中使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,关于您的问题的评论: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 usefind_package
before performing atarget_link_libraries
. So you can validate that Eigen has the proper version withfind_package (Eigen3 3.4 REQUIRED)
, this is the best way to do it.find_package
will read the fileEigen3Config.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.