C++ Ubuntu CMake 什么路径添加到 CMAKE_MODULE_PATH

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28247137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 20:56:18  来源:igfitidea点击:

Ubuntu CMake what path to add to CMAKE_MODULE_PATH

c++qtcmake

提问by BuddhaWithBigBelly

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.

我的操作系统是 Ubuntu。我想在我的项目中从 QT4 更改为 QT5。虽然本机软件包现在是 Ubuntu 中的 4.x 版本。

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

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

This path is not found by

找不到此路径

find_package (Qt5 REQUIRED)

I tried adding

我尝试添加

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

to my CMAKELIST.txtbut that does not help.

对我来说,CMAKELIST.txt但这无济于事。

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

我必须在哪里链接,或者我使用了错误的语法?

Some edits after hint with calling:

调用提示后的一些编辑:

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

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

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

 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

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:

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

/opt/QT/5.4/gcc_64/

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

添加子文件夹 gcc_64 必须正确,因为该子文件夹有“lib”、“include”等子文件夹。

I remeber that I have called also

我记得我也打过电话

sudo apt-get install QT5-default 

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.

前一段时间。这没有帮助,我需要 QT 的安装程序。虽然我再次删除了qt5-default,以防止cmake找到错误的包配置文件,但还是出现了同样的错误。

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

请参阅下面的讨论,移至此处: Cmake 和 QT5 - Include 仅需要一个参数

回答by daniel.wirtz

You have to use the variable CMAKE_PREFIX_PATH, i.e. invoke

你必须使用变量CMAKE_PREFIX_PATH,即调用

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

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

在构建树的根部。然后你可以使用find_package(Qt5 ...)等。另见Qt5 cmake docs

Rough distinction within you focus:

您关注的粗略区别:

  • CMAKE_MODULE_PATHis for "general" inclusion of filesand "FindXXX.cmake" files in find_package(... MODULE).
  • CMAKE_PREFIX_PATHhas a special meaningin the context of find_package(... CONFIG).
  • CMAKE_MODULE_PATH用于“一般”包含文件和“FindXXX.cmake”文件find_package(... MODULE)
  • CMAKE_PREFIX_PATH在 的上下文中具有特殊含义find_package(... CONFIG)

After addition of new content

添加新内容后

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 config.cmake 文件之前遇到该错误:-)

anyways, as the error tells you

无论如何,正如错误告诉你的那样

The Qt5 package requires at least one component

Qt5 包至少需要一个组件

you need to specify a componentof the Qt5 package. As the cmake docssay, 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::Widgetsetc to use/link against. i dont know if the syntax find_package(Qt5Widgets REQUIRED)works, could be equivalent.

您需要指定Qt5 包的一个组件。正如cmake 文档所说,您需要使用 find_package(Qt5 REQUIRED COMPONENTS Widgets Core ...) 接口,以便 cmake(更好:Qt5 FindQt5.cmake 的逻辑)知道要查找的内容。这将为您提供Qt5::Widgets要使用/链接的目标等。我不知道语法是否find_package(Qt5Widgets REQUIRED)有效,可能是等效的。