提示查找< name> .cmake带有自定义目录的文件 [英] Hinting Find<name>.cmake Files with a custom directory

查看:176
本文介绍了提示查找< name> .cmake带有自定义目录的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CMake,有没有办法使内置的查找脚本优先我们指定的自定义目录?因为特别是在windows中,模块查找脚本通常不能检测模块,例如visual studio目录。因此,我通常必须手动设置外部库的路径,这是相当累。相反,我希望这些脚本查找自定义目录,让我们说在主项目中的依赖项文件夹中,这样我可以直接将那些文件夹中的外部,这是更容易把它们放入VC文件夹或手动设置路径。

In CMake, is there a way to make built-in Find scripts to prioritize a custom directory that we specify? Because especially in windows, module finding scripts usually can't detect the module in, for example visual studio directories. Therefore I usually have to manually set the paths for the external libraries which is pretty tiring. Instead, I want those scripts to look in a custom directory, let's say 'dependencies' folder in the main project first so that I can directly put those externals in that folder which is much easier than putting them into the VC folder or manually setting the paths.

推荐答案

设置 CMAKE_PREFIX_PATH 变量完全符合这些用途:提示 find _ * 关于搜索项目位置的函数。

Setting CMAKE_PREFIX_PATH variable serves exactly these purposes: hinting for find_* function about location of searched item.

虽然这个变量的描述没有注意到 find_package 函数,该变量会间接影响它 :查找< name> .cmake 脚本最多使用 find_library find_path a>函数。请注意,对于搜索项,所有 find _ * 函数都有精确的算法,以及 CMAKE_PREFIX_PATH

While description of this variable doesn't note about find_package function, the variable affects on it indirectly: the most of Find<name>.cmake scripts use find_library and find_path functions. Note, that all find_* functions has precise algorithm for search items, and paths constructed with CMAKE_PREFIX_PATH are checked before system ones.

此外, CMAKE_PREFIX_PATH 会影响其他搜索过程。例如,如果3d方包提供< name> Config.cmake 脚本而不是查找< name> .cmake ,也使用此变量搜索此脚本。 pkg_check_modules 也使用 CMAKE_PREFIX_PATH

Moreover, CMAKE_PREFIX_PATH affects on some other search procedures. E.g., if 3d party package provides <name>Config.cmake script instead of Find<name>.cmake one, this script is also searched with use of this variable. pkg_check_modules also uses CMAKE_PREFIX_PATH for search .pc files, described the package.

CMAKE_PREFIX_PATH / code>变量可以设置为环境变量(以平台依赖和使用特定的方式)作为 cmake 的参数调用:

CMAKE_PREFIX_PATH variable can be set as environment one(in platform-depended and usage-specific way), as parameter to cmake call:

cmake -DCMAKE_PREFIX_PATH=<additional-path> <other-parameters>

CMakeLists.txt 文件。在最后一种情况下,最好追加搜索目录,因此您的包的用户也可以为您的项目附带的搜索包设置变量:

or within CMakeLists.txt file. In the last case it is better to append search directories, so user of you package is able to set the variable too for search packages not shipped with your project:

list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/dependencies")

这篇关于提示查找&lt; name&gt; .cmake带有自定义目录的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆