De là: https://stackoverflow.com/a/28327499/462608
J'ai essayé ceci:
cmake_minimum_required(VERSION 2.8.12)
project(qtquick_hello_cmake)
set(CMAKE_PREFIX_PATH "/opt/Qt5.9.1/5.9.1/")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Quick Core REQUIRED)
qt5_add_resources(RESOURCES qml.qrc)
add_executable(${PROJECT_NAME} "main.cpp" "qml.qrc")
qt5_use_modules(${PROJECT_NAME} Quick Core)
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Quick)
Voici le résultat de cmake .
:~/junk/qtquick_hello_cmake$ cmake .
CMake Error at CMakeLists.txt:11 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" with any of
the following names:
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/.../junk/qtquick_hello_cmake/CMakeFiles/CMakeOutput.log".
Ceci montre que /opt/Qt5.9.1/
existe.
:~/junk/qtquick_hello_cmake$ cd /opt/Qt5.9.1/5.9.1/
:/opt/Qt5.9.1/5.9.1$ ls
Android_armv7 Android_x86 gcc_64 Src
Ici, je lance cmake avec l'option -DCMAKE, mais le résultat est toujours le même:
:~/junk/qtquick_hello_cmake$ cmake -DCMAKE_PREFIX_PATH=/opt/Qt5.9.1/5.9.1/ -DWITH_QT5=1 .
CMake Error at CMakeLists.txt:11 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" with any of
the following names:
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/.../junk/qtquick_hello_cmake/CMakeFiles/CMakeOutput.log".
Contenu du répertoire:
:~/junk/qtquick_hello_cmake$ ls
CMakeCache.txt CMakeFiles CMakeLists.txt main.cpp main.qml qml.qrc
J'ai installé les paquets manquants suivants:
Sudo apt-get install qtbase5-dev
Sudo apt-get install qtdeclarative5-dev
Joindre n'importe quel type de préfixe n'est pas obligatoire maintenant:
:~/junk/qtquick_hello_cmake$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(qtquick_hello_cmake)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Quick Core REQUIRED)
qt5_add_resources(RESOURCES qml.qrc)
add_executable(${PROJECT_NAME} "main.cpp" "qml.qrc")
qt5_use_modules(${PROJECT_NAME} Quick Core)
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Quick)
:~/junk/qtquick_hello_cmake$ ls
build CMakeLists.txt main.cpp main.qml qml.qrc
:~/junk/qtquick_hello_cmake$ cd build/
:~/junk/qtquick_hello_cmake/build$ rm -rf *
:~/junk/qtquick_hello_cmake/build$ cmake ../
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/.../junk/qtquick_hello_cmake/build
Les erreurs ont disparu maintenant.
Grâce à:
https://answers.ros.org/question/236324/could-not-find-a-package-configuration-file-provided-by-qt5widgets/
https://askubuntu.com/questions/508503/whats-the-development-package-for-qt5-in-14-04
J'ai rencontré ce problème récemment et je l'ai résolu en l'ajoutant à tout fichier CMakeLists.txt ayant généré cette erreur:
set(Qt5_DIR "*PATH TO YOUR QT QT5CONFIG FILE HERE*" CACHE PATH "Initial cahe" FORCE)
Message d'erreur CMake à propos de find_package
ayant échoué et de la configuration CMAKE_PREFIX_PATH variable
Ajoutez le préfixe d'installation de "Qt5" à CMAKE_PREFIX_PATH
est en quelque sorte trompeur. Il ne parle que de "préfixe d'installation", mais cette installation nécessite toujours que contienne des fichiers Qt5Config.cmake
ou qt5-config.cmake
afin d'être découvrable par find_package
.
Mais le message
Si "Qt5" fournit un package de développement ou un kit de développement distinct de , Assurez-vous qu'il a été installé.
est clair:
Vous devez installer un package de développement contenant les fichiers de configuration requis.
Tout ce qui précède est applicable uniquement àCONFIGmode de find_package
, lorsque le script "Find" n’est fourni ni par CMake ni par le projet CMake qui utilise cette commande.