在cmake中,如何具体qt5 pacakge路径

时间:2016-02-25 04:36:06

标签: c++ qt cmake

当我使用以下代码时:

find_package(Qt5Widgets REQUIRED)
add_executable(ex ex.cc)
target_link_libraries(ex Qt5::Widgets Qt5::DBus)

我明白了:

Error:By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt5Widgets", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets" with any of the following names:

我的qtbase路径位于" / media / roroco / disk750 / Downloads / qt5 / qtbase",我编译了它,如何在find_package

中具体说明这条路径

2 个答案:

答案 0 :(得分:0)

    IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
        SET(CMAKE_PREFIX_PATH $ENV{QT64_LOCATION})
        message(STATUS "QT find path: $ENV{QT64_LOCATION}")
    ELSE()
        SET(CMAKE_PREFIX_PATH $ENV{QT_LOCATION})
        message(STATUS "QT find path: $ENV{QT_LOCATION}")
    ENDIF()

并将路径添加到环境变量(如果未定义或硬编码) - CMAKE_PREFIX_PATH“C:\ Qt \ .. \ msvc2010 \”或Linux中的qmake路径 即“/ media / roroco / disk750 / Downloads / qt5 / bin / qmake”

您也可以设置默认的qt路径

    /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf

将其设置为/ media / roroco / disk750 / Downloads / qt5 / bin /

答案 1 :(得分:0)

CMAKE_PREFIX_PATH设置为Qt文件夹。例如:

SET(CMAKE_PREFIX_PATH "C:/Qt/5.5/msvc2013")

根据您的操作系统,路径可能会有所不同。