将find_library行为从CMake 2.8更改为CMake 3.2 [英] Changed find_library behavior from CMake 2.8 to CMake 3.2

查看:99
本文介绍了将find_library行为从CMake 2.8更改为CMake 3.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从CMake 2.8.x迁移到3.2.x时遇到以下问题。因此,似乎 find_library 的内部行为发生了变化。这是一个演示我的问题的最小示例。

I have got the following problem while migrating from CMake 2.8.x to 3.2.x. Thereby, it seems that the internal behavior of find_library changed. Here is a minimal example which demonstrates my problem.

考虑我们正在搜索名为 libopenblas.so 的库,该库位于 /从头开始/ local_install / lib / usr / lib / openblas-base LD_LIBRARY_PATH 环境变量设置为 / scratch / local_install / lib

Consider that we are search for library called libopenblas.so which is located in /scratch/local_install/lib and /usr/lib/openblas-base. The LD_LIBRARY_PATH environment variable is set to /scratch/local_install/lib.

CMakeLists.txt 文件如下:

PROJECT(TEST) 
cmake_minimum_required(VERSION 2.8)

SET(_libname "openblas") 
SET(_libdir  ENV LD_LIBRARY_PATH "/usr/lib/openblas-base")

find_library(OPENBLAS_LIBRARY
      NAMES ${_libname}
      HINTS ${_libdir}
      PATHS ${_libdir}
      )
MESSAGE("OPENBLAS: ${OPENBLAS_LIBRARY}") 

如果执行此操作使用CMake 2.8.7或2.8.12,我得到

If I execute this using CMake 2.8.7 or 2.8.12, I get

OPENBLAS: /scratch/koehlerm/local_install/lib/libopenblas.so

如果我使用CMake 3.2.1配置代码,则会得到

If I configure the code using CMake 3.2.1, I get

OPENBLAS: /usr/lib/openblas-base/libopenblas.so

我只想在 LD_LIBRARY_PATH libopenblas.so 的情况下获取>。即使使用CMake 3.2.x配置了代码,如何恢复CMake 2.8.x的旧行为?

which I only want to get if there is none libopenblas.so in the LD_LIBRARY_PATH. How can I restore the old behavior of CMake 2.8.x even if the code is configured with CMake 3.2.x?

推荐答案

NO_DEFAULT_PATH 用于 find_library code>,则它将忽略默认位置。请参见文档

Use NO_DEFAULT_PATH for find_library, then it will ignore the default location. See the documentation.

要获取所需的行为,请使用find_library两次。首先使用NO_DEFAULT_PATH,之后再使用。如果是第一次找到,结果将被缓存,并且第二个调用(包括默认路径)将被跳过。如果没有发现任何东西,它将重新运行并查看默认路径。

To get the bahvior you want, use find_library twice. First with NO_DEFAULT_PATH and after that without. If it is found the first time, the result is cached and the second call including the default path is skipped. If nothing is found first, it will be re-run and look at the default paths, too.

这篇关于将find_library行为从CMake 2.8更改为CMake 3.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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