1

I am trying to manually setup a CMake project that uses QT6 on Ubuntu 20.04 LTS. This is what the CMakeLists.txt looks like:

cmake_minimum_required(VERSION 3.16)

project(Button, LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_PREFIX_PATH "home/ilmu011/Qt/6.2.3/gcc64")

find_package(Qt6 REQUIRED COMPONENTS Widgets)

add_executable(Button
main.cpp
)

However, CMake states that it doesn't find the QT6 installation. It is installed under home/ilmu011/Qt/6.2.3/gcc64. But I get an error message:

CMake Error at CMakeLists.txt:14 (find_package):
  By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Qt6", but
  CMake did not find one.

  Could not find a package configuration file provided by "Qt6" with any of
  the following names:

    Qt6Config.cmake
    qt6-config.cmake

  Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
  to a directory containing one of the above files.  If "Qt6" provides a
  separate development package or SDK, be sure it has been installed.


-- Configuring incomplete, errors occurred!
See also "/home/ilmu011/Desktop/Button/build/CMakeFiles/CMakeOutput.log".
make: *** [Makefile:176: cmake_check_build_system] Error 1

It tells me to set the CMAKE_PREFIX_PATH to the QT6 location, which I did here, but it still doesn't work. I searched around for a solution and found this post:

CMAKE_PREFIX_PATH doesn't help CMake in finding Qt5

It says since the error message also states that eventually a separate development package is required that would eventually provide the "qt6-config.cmake" that CMake complains is not there, I should try installing these two things:

sudo apt-get install qtbase5-dev sudo apt-get install qtdeclarative5-dev

However, these are for QT5 and that didn't work. How can I get CMake to detect QT6?

ilmu011
  • 80
  • 2
  • 8
  • 1
    "home/ilmu011/Qt/6.2.3/gcc64" is no valid path, you for sure missed the `/` at the front. – chehrlic Mar 12 '22 at 11:29
  • @chehrlic I just tried it with "/home/ilmu011/Qt/6.2.3/gcc64" and "/home/ilmu011/Qt/6.2.3/gcc64/", both throw the same error as before – ilmu011 Mar 12 '22 at 12:22
  • I ended up downgrading to QT5, which works now. Still don't know how to make it work with QT6 – ilmu011 Mar 12 '22 at 18:16
  • Another thing I found out: Turns out setting CMAKE_PREFIX_PATH via the CMakeLists.txt doesn't work at all, no matter which directory. It only works when I set it via a console command like "cmake -DCMAKE_PREFIX_PATH=/dir/i/want/to/add" – ilmu011 Mar 14 '22 at 08:39
  • Turns out any changes I made to the CMakeLists.txt were ignored by cmake as long as I didn't delete the contents of the build folder after each change... – ilmu011 Mar 15 '22 at 12:08

1 Answers1

0

On ubuntu, the package qt6-base-dev provides Qt6Config.cmake. With this, cmake finds the qt6 libraries installed with apt, without helping it with the option CMAKE_PREFIX_PATH.

sudo apt install qt6-base-dev