Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown CMake Qt5 command

Tags:

cmake

qt5

I am currently trying to build a project using CMake. This is the output that I get

CMake Warning at ext/quazip/CMakeLists.txt:4 (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.


CMake Error at ext/quazip/CMakeLists.txt:19 (qt5_wrap_cpp):
  Unknown CMake command "qt5_wrap_cpp".

I have Qt Creator installed and I am not sure why I am getting this error. I looked around on the web and they states that I should add

set(QT_USE_QTXML true)
FIND_PACKAGE(Qt5)

after the #project in ext/quazip/CMakeLists.txt I have done that however I am still getting this error any suggestions ?

Update: So I added the following to my top level CMakeLists.txt

find_package( Qt5Core REQUIRED )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Gui REQUIRED )
find_package( Qt5OpenGL REQUIRED )
find_package( Qt5Multimedia REQUIRED )
find_package( Qt5WebKitWidgets REQUIRED )
find_package( Qt5Xml REQUIRED )

I cleared the cache and then configured. At that point I get the following error.

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

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

    Qt5CoreConfig.cmake
    qt5core-config.cmake

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


Configuring incomplete, errors occurred!
like image 293
MistyD Avatar asked Jan 27 '16 22:01

MistyD


2 Answers

To use Qt5 in CMakeLists.txt you should use (a combination of) those functions:

In top level CMakeLists.txt

#### Qt5
find_package( Qt5Core REQUIRED )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Gui REQUIRED )
find_package( Qt5OpenGL REQUIRED )
find_package( Qt5Multimedia REQUIRED )
find_package( Qt5WebKitWidgets REQUIRED )
find_package( Qt5Xml REQUIRED )
set( CMAKE_AUTOMOC ON )  # to automoc remove the need to wrap by hand

EDIT: The Qt5 cmake modules are provided by Qt5 itself, so you need to tell cmake where qt can be found. See the Qt5 CMake doc about that.

like image 98
Kirell Avatar answered Nov 02 '22 11:11

Kirell


So finally, with some searching, I was able to get CANDevStudio -- which was also having this Qt5 problem -- working on Ubuntu 20.04 by:

Step 1: Manually download and install Qt from their website (requires free account creation): https://download.qt.io/archive/qt/

According to: This Website, it may be necessary to remove any other versions of libqt5:

sudo apt purge libqt5svg5-def
sudo apt purge libqt5serialbus5-dev

Step 2: Build the Software with the DCMAKE_PREFIX_PATH flag set to the directory of the newly installed software (in my case, I put it in my home directory):

cmake .. -DCMAKE_PREFIX_PATH=/home/<username>/Qt5.12.0/5.12.0/gcc_64

Source: CanDevStudio's Help Page

like image 1
DarsilRain Avatar answered Nov 02 '22 09:11

DarsilRain