CMake:安装两个Qt版本时查找Qt软件包 [英] CMake: find Qt packages when two Qt versions are installed

查看:558
本文介绍了CMake:安装两个Qt版本时查找Qt软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的计算机(Ubuntu-Gnome)上,安装了两个Qt版本。一个带有程序包管理器(5.x),另一个带有 / opt / Qt (5.9)手动。

On my computer (Ubuntu-Gnome) are two Qt-versions installed. One with the package manager (5.x) and one manually to /opt/Qt (5.9).

对于一个项目,我需要在CMake中使用 / opt / Qt 安装。但是 find_package(需要Qt5Core 5.9组件)找不到正确的安装:

For one project I need to use the /opt/Qt-installation with CMake. But find_package(Qt5Core 5.9 COMPONENTS CORE REQUIRED) does not find the correct installation:

  Could not find a configuration file for package "Qt5Core" that is
  compatible with requested version "5.9".

  The following configuration files were considered but not accepted:

    /usr/lib/x86_64-linux-gnu/cmake/Qt5Core/Qt5CoreConfig.cmake, version: 5.7.1

我尝试设置 CMAKE_PREFIX_PATH CMAKE_MODULE_PATH 将具有所有路径变体的搜索路径添加到CMake,但根本不起作用。

I tried to set CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH to add a search path to CMake with all variants of paths but it does not work at all.

我该如何正确地将搜索路径设置为第二个安装的 / opt / Qt /

How can I correctly set the search path to the second installation at /opt/Qt/?

更新以便@Florian输入

Updates in order to @Florian input

这有效:

find_package(
   Qt5Core 5.9
   COMPONENTS
      Core
   REQUIRED
)

cmake -DQt5_DIR:PATH=/opt/Qt/5.9.2/gcc_64/lib/cmake/Qt5Core

但在这种情况下,我只找到了QT5Core。

but in this case I found only QT5Core. With that it seems to work for all components as well:

find_package(
   Qt5 5.9
   COMPONENTS
      Core
   REQUIRED
)

连同

cmake -DQt5_DIR:PATH=/opt/Qt/5.9.2/gcc_64/lib/cmake/Qt5






第二次编辑


2nd Edit

避免始终将完整路径放在呼叫中,我将此添加到我的 CMakeLists.txt 中:

To avoid to always put the the full path in the call I add this to the my CMakeLists.txt:

set(QT_INSTALL_PATH /opt/Qt)
file( GLOB_RECURSE sres ${QT_INSTALL_PATH}/*/Qt5Config.cmake )
get_filename_component( Qt5_DIR ${sres} DIRECTORY )

此后工作正常:

find_package(
   Qt5 5.9
   COMPONENTS
      Core
      Network
   REQUIRED
)


推荐答案

使用 cmake -DQt5_DIR:PATH = / opt / Qt5 / 5.9.2 / gcc_64 / lib / cmake / Qt5

文档

这篇关于CMake:安装两个Qt版本时查找Qt软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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