2

I want to compile this which requires Qt 5.14 and I have Qt 5.12 installed from my linux repository.I just compiled Qt from source and installed it in /usr/local/Qt-6.0.0/(default location).
But CMake prints the following error although I've added set(CMAKE_PREFIX_PATH "/usr/local/Qt-6.0.0/include") and/or set(CMAKE_PREFIX_PATH "/usr/local/Qt-6.0.0/") :

The following configuration files were considered but not accepted:

/usr/lib/x86_64-linux-gnu/cmake/Qt5/Qt5Config.cmake, version: 5.12.8
/lib/x86_64-linux-gnu/cmake/Qt5/Qt5Config.cmake, version: 5.12.8
Parsa Mousavi
  • 1,052
  • 1
  • 13
  • 31
  • you have to point to the location where the configuration files are located. ex: Qt5_DIR="/Users/bob/Qt/5.12.7/clang_64/lib/cmake/Qt5" you can use `Qt5_DIR` or `CMAKE_PREFIX_PATH`, both should work. – cppiscute Apr 26 '20 at 10:59
  • @cppiscute In my case , QT5_DIR worked.Thanks. – Parsa Mousavi Apr 26 '20 at 21:02
  • Does this answer your question? [cmake does not find qt 5.1.1](https://stackoverflow.com/questions/18722329/cmake-does-not-find-qt-5-1-1) – Kevin Apr 27 '20 at 12:36
  • @squareskittles QT5_DIR was enough.The important part is that it should point to the "Qt_installation/lib/cmake/Qt5/" directory which contains some modules to help CMake find the Qt libraries. – Parsa Mousavi Apr 27 '20 at 12:43
  • This [response](https://stackoverflow.com/a/35169447/3987854) also touches on this topic, specifically mentioning the use of `Qt5_DIR`. – Kevin Apr 27 '20 at 12:48
  • @squareskittles You're right. – Parsa Mousavi Apr 27 '20 at 12:53
  • @ParsaMousavi Since it has solved your problem, I have added it as an answer please check. – cppiscute Apr 29 '20 at 09:39

1 Answers1

5

Since it has solved your question, I am just going to put it as an answer here. I will improve this section more in detail later.

If you are using cmake use find_package to find the package and then link to your binary in later stage.

In order for find_package to be successful, Qt 5 must be found below the
CMAKE_PREFIX_PATH, or the Qt5_DIR must be set in the CMake cache to the 
location   of the Qt5Config.cmake file. The easiest way to use CMake is to set the
CMAKE_PREFIX_PATH environment variable to the install prefix of Qt 5.

If you just want to find the Qt modules then just set the Qt5_DIR
ex: Qt5_DIR="/Users/bob/Qt/5.12.7/clang_64/lib/cmake/Qt5"

when building with CMake you can use Qt5_DIR or CMAKE_PREFIX_PATH, both should work.

More explanation about building with CMake can be found here

cppiscute
  • 707
  • 2
  • 10
  • 33