是否还为依赖项提供了查找模块

是否还为依赖项提供了查找模块

本文介绍了安装CMake库:是否还为依赖项提供了查找模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CMake库 code>?

Is there a good practice regarding how to distribute FindOtherLibrary.cmake along MyLibrary?

理想情况下,对于 MyLibrary的用户来说,这可能会让事情变得更加轻松,方法是从安装的配置文件 MyLibraryConfig.cmake 中自动导入 OtherLibrary 像

Ideally, one could make things even easier for users of MyLibrary by importing OtherLibrary automatically from the installed config file MyLibraryConfig.cmake, if it contains something like

include(CMakeFindDependencyMacro)
find_dependency(OtherLibrary)

并知道 FindOtherLibrary.cmake 在哪里。

这有可能吗?

推荐答案

我最终找到了解决问题的方法。

I ended up finding a solution to my question.

原则上,它会执行@utopia的建议,但会以自动化的方式进行:我图书馆的最终用户不需要设置(甚至不知道) FindOtherLibrary。 cmake 。它将由 MyLibraryConfig.cmake 自动导入。

In principle, it does what @utopia suggested, but in an automated fashion: the end user of my library does not need to set up (or even know about) FindOtherLibrary.cmake. It will be imported automatically by MyLibraryConfig.cmake.

为此,我安装了 FindOtherLibrary.cmake 和 MyLibraryConfig.cmake :

install(FILES
          /path/to/MyLibraryConfig.cmake
        DESTINATION
          lib/cmake/MyLibrary
        )
install(FILES
          /path/to/FindOtherLibrary.cmake
        DESTINATION
          lib/cmake/MyLibrary/Modules
        )

然后在 MyLibraryConfig.cmake 中设置如何导入它:

And in MyLibraryConfig.cmake I set up how to import it:

include(CMakeFindDependencyMacro)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/Modules/")
find_dependency(OtherLibrary REQUIRED)

请注意,我设置了变量 CMAKE_MODULE_PATH ,因为无法指定查找模块的位置在 find_package 或 find_de中待命(仅适用于配置模式)。

Note that I set the variable CMAKE_MODULE_PATH because it is not possible to specify the location of find modules in find_package or find_dependency (works only for config mode).

这篇关于安装CMake库:是否还为依赖项提供了查找模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 15:28