强制cmake FIND_LIBRARY在自定义目录中查找 [英] force cmake FIND_LIBRARY to look in custom directory

查看:775
本文介绍了强制cmake FIND_LIBRARY在自定义目录中查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cmake版本2.8.4

cmake version 2.8.4

我有以下apache可移植运行时库,这些库我自己编译过并希望我的应用程序链接到该库。

I have the following apache portable runtime libraries that I have compiled myself and want my application to link against.

我的apr库所在的项目目录:

My project directory where my apr libraries are:

gw_proj/tools/apr/libs

在我的CMakeLists.txt中,我有以下内容:

In my CMakeLists.txt I have the following:

FIND_LIBRARY(APRUTIL NAMES "aprutil-1"
  PATHS ${PROJECT_SOURCE_DIR}/tools/apr/libs)

我的问题是在已经安装了apache便携式运行时的计算机上,它将在此文件夹中查找它:

My problem is on a machine that already has the apache portable runtime already installed it will look for it in this folder:

/usr/lib

因此总是忽略我的自定义路径。

So will always ignore my custom path.

如何强制 FIND_LIBRARY 始终显示在我的自定义目录中:

How can I force the FIND_LIBRARY to always look in my custom directory:

gw_proj/tools/apr/libs

非常感谢您的任何建议

推荐答案

您可以使用 NO_DEFAULT_PATH NO_CMAKE_ENVIRONMENT_PATH
中的一个或多个来指定搜索顺序, NO_CMAKE_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH CMAKE_FIND_ROOT_PATH_BOTH ONLY_CMAKE_FIND_ROOT_PATH NO_CMAKE_FIND_ROOT_PATH

You can specify the search order using one or more of NO_DEFAULT_PATH, NO_CMAKE_ENVIRONMENT_PATH , NO_CMAKE_PATH, NO_SYSTEM_ENVIRONMENT_PATH, NO_CMAKE_SYSTEM_PATH, CMAKE_FIND_ROOT_PATH_BOTH, ONLY_CMAKE_FIND_ROOT_PATH, orNO_CMAKE_FIND_ROOT_PATH.

find_library


设计了默认搜索顺序项目可以通过简单地多次调用该命令并使用NO_ *选项来覆盖该命令,即可以覆盖特定的顺序。

The default search order is designed to be most-specific to least-specific for common use cases. Projects may override the order by simply calling the command multiple times and using the NO_* options:

find_library(<VAR> NAMES name PATHS paths... NO_DEFAULT_PATH)
find_library(<VAR> NAMES name)

一旦调用成功,将设置结果变量并将其存储在缓存中,这样就不会再有搜索。

Once one of the calls succeeds the result variable will be set and stored in the cache so that no call will search again.

因此,您可以这样做

FIND_LIBRARY(APRUTIL NAMES "aprutil-1"
  PATHS ${PROJECT_SOURCE_DIR}/tools/apr/libs NO_DEFAULT_PATH)

这篇关于强制cmake FIND_LIBRARY在自定义目录中查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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