Linux 对于本地编译的库,FindXXX.cmake 文件的正确位置是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5529186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:30:10  来源:igfitidea点击:

What is the right place for FindXXX.cmake files for locally compiled libs?

linuxcmake

提问by Latanius

I have a lib I installed by hand (to /usr/local) on a Linux system (Eigen3, by the way). There is a FindEigen3.cmake bundled with the lib but that is not installed anywhere by default.

我在 Linux 系统(顺便说一下,Eigen3)上手动安装了一个库(到 /usr/local)。有一个 FindEigen3.cmake 与 lib 捆绑在一起,但默认情况下没有安装在任何地方。

There is /usr/share/cmake-x.y/Modules where CMake looks for additional modules, but putting these files there doesn't seem the way to do things. Is there an equivalent place under /usr/local that is also scanned by default? Or what is the standard way of creating custom library modules?

在 /usr/share/cmake-xy/Modules 中,CMake 会查找其他模块,但将这些文件放在那里似乎不是做事的方式。/usr/local 下是否有同样默认扫描的等效位置?或者创建自定义库模块的标准方法是什么?

(Although the question isn't strictly connected to programming, I think library authors may also encounter the same question from the other side: where to put these files when installing manually.)

(虽然这个问题与编程并没有严格的关系,但我认为库作者也可能会从另一面遇到同样的问题:手动安装时将这些文件放在哪里。)

采纳答案by DLRdave

See the comments in the CMake documentation for the "find_package" command:

请参阅 CMake 文档中“find_package”命令的注释:

http://cmake.org/cmake/help/v2.8.8/cmake.html#command:find_package

http://cmake.org/cmake/help/v2.8.8/cmake.html#command:find_package

It speaks of writing a "project-config" file, and where to install it, such that find_package(Eigen3) will work without having a FindEigen3.cmake find module... It is verbose, but the information is in there.

它谈到编写一个“项目配置”文件,以及在哪里安装它,这样 find_package(Eigen3) 将在没有 FindEigen3.cmake find 模块的情况下工作......它很冗长,但信息在那里。

See also user contributed wiki pages such as this one:

另请参阅用户贡献的 wiki 页面,例如:

https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/How-to-create-a-ProjectConfig.cmake-file

https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/How-to-create-a-ProjectConfig.cmake-file

回答by ltc

You need to set the CMAKE_MODULE_PATH to include the directory that the FindEigen3.cmake file is in before calling find_package. I believe that:

在调用 find_package 之前,您需要设置 CMAKE_MODULE_PATH 以包含 FindEigen3.cmake 文件所在的目录。我相信:

set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} <your path> )

will do the trick, but I do not have a setup to test that available at the moment so you may have to massage that technique a bit.

可以解决问题,但我目前没有测试可用的设置,因此您可能需要稍微按摩一下该技术。

回答by beduin

In our project we place FIndXXX.cmake modules in folder project root dir/cmake/modules. For this to work you have to specify in project root dir/CMakeLists.txt(similiar to what DLRdave has already said):

在我们的项目中,我们将 FIndXXX.cmake 模块放在文件夹项目根目录 dir/cmake/modules 中。为此,您必须在项目根目录/CMakeLists.txt 中指定(类似于 DLRdave 已经说过的内容):

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)