如何知道CMake找到的库版本? [英] How to know version of library found by CMake?

查看:102
本文介绍了如何知道CMake找到的库版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个C ++项目,该项目在其他库中使用CMake文件和OpenCV.我的目标是能够同时使用2.4.something版本和3.0版本进行编译.

I'm currently developing a C++ project that uses CMake files and OpenCV among other libraries. My target would be to be able to compile my code both with version 2.4.something and with 3.0.

为此,我想到使用CMake配置为设置一个变量,该变量指示在配置阶段找到的OpenCV软件包的版本是否大于或等于3.0.然后,使用此变量,我可以包括或排除代码的特定部分.

In order to do so, I thought of using CMake configured to set a variable indicating whether the OpenCV package found in the configuration phase has a version greater or equal to 3.0. Using this variable I can then include or exclude ad-hoc parts of my code.

但是我找不到任何地方可以在CMake文件中知道找到的程序包的版本.

However I was not able to find anywhere how can I know in a CMake file the version of a found package.

我的CMake文件的伪代码如下所示:

The pseudo code of my CMake file would look something like this:

....
find_package(OpenCV 2.4 REQUIRED)
if(OpenCV_Version >= 3)
    set (OpenCV_3 1)
else
    set (OpenCV_3 0)
endif(OpenCV_Version)
....

是否可能这样做或我做错了什么?

Is it possible to do this or am I doing something wrong?

推荐答案

查找包:

If the version is acceptable the following variables are set:

<package>_VERSION
    full provided version string
<package>_VERSION_MAJOR
    major version if provided, else 0
<package>_VERSION_MINOR
    minor version if provided, else 0
<package>_VERSION_PATCH
    patch version if provided, else 0
<package>_VERSION_TWEAK
    tweak version if provided, else 0
<package>_VERSION_COUNT
    number of version components, 0 to 4

您可以使用带有完整版本字符串的变量 OpenCV_VERSION 来使用 if()命令的 VERSION _ * 模式进行比较:

You may use either variable OpenCV_VERSION with full version string for comparing using VERSION_* modes of if() command:

if(OpenCV_VERSION VERSION_LESS "3.0")
    # 2.4 version
else()
    # 3.0 version
endif()

或具有数字比较功能的版本组件变量:

or version-component variables with number comparision:

if(OpenCV_VERSION_MAJOR LESS 3)
    # 2.4 version
else()
    # 3.0 version
endif()

这篇关于如何知道CMake找到的库版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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