Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: find Qt packages when two Qt versions are installed

Tags:

cmake

qt

On my computer (Ubuntu-Gnome) are two Qt-versions installed. One with the package manager (5.x) and one manually to /opt/Qt (5.9).

For one project I need to use the /opt/Qt-installation with CMake. But find_package(Qt5Core 5.9 COMPONENTS CORE REQUIRED) does not find the correct installation:

  Could not find a configuration file for package "Qt5Core" that is
  compatible with requested version "5.9".

  The following configuration files were considered but not accepted:

    /usr/lib/x86_64-linux-gnu/cmake/Qt5Core/Qt5CoreConfig.cmake, version: 5.7.1

I tried to set CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH to add a search path to CMake with all variants of paths but it does not work at all.

How can I correctly set the search path to the second installation at /opt/Qt/?


Updates in order to @Florian input

This works:

find_package(
   Qt5Core 5.9
   COMPONENTS
      Core
   REQUIRED
)

together with

cmake -DQt5_DIR:PATH=/opt/Qt/5.9.2/gcc_64/lib/cmake/Qt5Core

but in this case I found only QT5Core. With that it seems to work for all components as well:

find_package(
   Qt5 5.9
   COMPONENTS
      Core
   REQUIRED
)

together with

cmake -DQt5_DIR:PATH=/opt/Qt/5.9.2/gcc_64/lib/cmake/Qt5

2nd Edit

To avoid to always put the the full path in the call I add this to the my CMakeLists.txt:

set(QT_INSTALL_PATH /opt/Qt)
file( GLOB_RECURSE sres ${QT_INSTALL_PATH}/*/Qt5Config.cmake )
get_filename_component( Qt5_DIR ${sres} DIRECTORY )

Afterwards this works fine:

find_package(
   Qt5 5.9
   COMPONENTS
      Core
      Network
   REQUIRED
)
like image 524
Alex44 Avatar asked Oct 29 '17 18:10

Alex44


1 Answers

Use cmake -DQt5_DIR:PATH=/opt/Qt5/5.9.2/gcc_64/lib/cmake/Qt5

Documentation

like image 181
Cinder Biscuits Avatar answered Nov 16 '22 02:11

Cinder Biscuits