Ubuntu CMake要添加到CMAKE_MODULE_PATH的什么路径 [英] Ubuntu CMake what path to add to CMAKE_MODULE_PATH

查看:7081
本文介绍了Ubuntu CMake要添加到CMAKE_MODULE_PATH的什么路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的操作系统是Ubuntu。我想在我的项目中从QT4更改为QT5。

My OS is Ubuntu. I would like to change from QT4 to QT5 in my project. The native package though is 4.x version in Ubuntu right now.

我从QT主页下载了Linux安装程序,并在下安装了QT5.4。 /opt/Qt/5.4 /

I have downloaded the Linux installer from QT homepage and installed QT5.4 under /opt/Qt/5.4/

find_package (Qt5 REQUIRED)



I tried adding

set(CMAKE_MODULE_PATH "/opt/QT/5.4;${CMAKE_MODULE_PATH}")

到我的 CMAKELIST.txt ,但是没有帮助。

to my CMAKELIST.txt but that does not help.

我必须在哪里连结或使用错误的语法?

Where do I have to link, or am I using the wrong syntax?

调用:

 cmake -DCMAKE_PREFIX_PATH=/opt/QT/5.4/gcc_64/ ../src/

我也删除了CMAKE_MODULE_PATH变量。
我仍​​然得到相同的错误:

I also have deleted the CMAKE_MODULE_PATH variable. I still get the same error:

 CMake Error at CMakeLists.txt:3 (find_package):
 Found package configuration file:
 /usr/lib/x86_64-linux-gnu/cmake/Qt5/Qt5Config.cmake
 but it set Qt5_FOUND to FALSE so package "Qt5" is considered to be NOT
 FOUND.  Reason given by package:

 The Qt5 package requires at least one component

我不知道为什么这发生后阅读 https://blogs.kde.org/2008/12/12/how-get-cmake-find-what-you-want-it
。这里说,路径将在默认搜索目录之前搜索。我使用的路径似乎是现在:

I dont know why this is happening after reading https://blogs.kde.org/2008/12/12/how-get-cmake-find-what-you-want-it . There it is stated, that the path will be searched before the default search directories. The path I used seems to be right now:

/opt/QT/5.4/gcc_64/

添加子文件夹gcc_64必须正确,因为此子文件夹具有lib,include作为子文件夹。

Adding subfolder gcc_64 must be right, as this subfolder has "lib", "include" ect as subfolders.

我还记得我也打电话了

sudo apt-get install QT5-default 

这没有帮助,我需要从QT的安装程序。虽然我再次删除qt5默认,以防止cmake找到错误的包配置文件,同样的错误出现。

some time ago. This did not help, I needed the installer from QT. Although I removed qt5-default again to prevent cmake from finding the wrong package configuration file, the same error appears.

查看下面的讨论,转移到这里:
Cmake和QT5 - Include只需要一个参数

See discussion below, moved to here: Cmake and QT5 - Include only takes one argument

推荐答案

必须使用变量 CMAKE_PREFIX_PATH ,即调用

cmake -DCMAKE_PREFIX_PATH=/opt/QT/5.4 <path_to_source>

。然后你可以使用 find_package(Qt5 ...)等。另见 Qt5 cmake docs

at the root of your build tree. Then you can use find_package(Qt5 ...) etc. See also the Qt5 cmake docs.

您关注的粗略区分:

  • CMAKE_MODULE_PATH is for "general" inclusion of files and "FindXXX.cmake" files in find_package(... MODULE).
  • CMAKE_PREFIX_PATH has a special meaning in the context of find_package(... CONFIG).

这是一个新错误,一个新问题。如果你有这个错误,你已经找到的Qt5 config.cmake文件: - )

this is a new error and thus should require a new question. if you had that error before you'd have already found the Qt5 config.cmake file :-)

反正,错误告诉你


Qt5包需要至少一个组件

The Qt5 package requires at least one component

一个组件。由于 cmake文档说,您需要使用find_package(Qt5 REQUIRED COMPONENTS Widgets Core ...)接口,以便cmake(更好:Qt5的逻辑FindQt5.cmake)知道要查找什么。这将给你目标 Qt5 :: Widgets 等使用/链接。
我不知道语法 find_package(Qt5Widgets REQUIRED)是否可以等效。

you need to specify a component of the Qt5 package. As the cmake docs say, you need to use the find_package(Qt5 REQUIRED COMPONENTS Widgets Core ...) interface so that cmake (better: the logic of Qt5 FindQt5.cmake) knows what to look for. that will give you the targets Qt5::Widgets etc to use/link against. i dont know if the syntax find_package(Qt5Widgets REQUIRED) works, could be equivalent.

这篇关于Ubuntu CMake要添加到CMAKE_MODULE_PATH的什么路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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