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
)
Use cmake -DQt5_DIR:PATH=/opt/Qt5/5.9.2/gcc_64/lib/cmake/Qt5
Documentation
Related
I am using qt6, win10, mingw.
I have dowloaded GLFW 64bit windows binary from the official site.
I know how to add it via qmake, but how could I add it via cmake.
.dll file location: linking\GLFW
.h file location: include\GLFW
I knwo that there is an integrate qt opengl, but I do not want to use that.
These are things which I did to make OpenGL work using CMake (This is on a Ubuntu system, it should be similar on Windows):
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(Threads REQUIRED)
link_libraries(
${CMAKE_SOURCE_DIR}/libs/build_glfw/src/libglfw3.a
${CMAKE_SOURCE_DIR}/libs/glew-2.1.0/build/lib/libGLEW.a
${OPENGL_LIBRARIES}
${GLUT_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS}
)
include_directories(
${CMAKE_SOURCE_DIR}/libs/glew-2.1.0/include
${CMAKE_SOURCE_DIR}/libs/glfw/include
${OPENGL_INCLUDE_DIRS}
${GLUT_INCLUDE_DIRS}
)
This path you have to change according to your dll location:
${CMAKE_SOURCE_DIR}/libs/build_glfw/src/libglfw3.a
${CMAKE_SOURCE_DIR}/libs/glew-2.1.0/build/lib/libGLEW.a
These variables are provided by CMake:
${OPENGL_LIBRARIES}
${GLUT_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS}
I have installed the current Qt 5.8 inside a users home directory and now try to use it since three days. Cmake always uses the system wide Qt installation and kdevelop does the same. No CodeCompletion on the new stuff and so on...
I tried to install it system wide in /opt/Qt but nothing changed.
So can please anyone tell me what environment variables do I have to change to integrate the current Qt Version in my Development System?
Many Thanks
By the way - it is a kdevelop 5.0 running on a Debian Linux testing
From cmake does not find qt 5.1.1 question:
You need to set the CMAKE_MODULE_PATH to the Qt installation where the *.cmake files are located. This CMake variable is used to select which Qt installation to use for compiling. There is also a`CMAKE_PREFIX_PATH environment variable.
See http://doc.qt.io/qt-5/cmake-manual.html
The code completion: in project settings add to include paths something like:
/.../.../5.8/gcc_64/include/QtGui/
/.../.../5.8/gcc_64/include/QtCore/
/.../.../5.8/gcc_64/include/QtQuick/
...
Edit: The following is only correct for Qt4 and not for Qt5!
The default qt version found by cmake is the one assoziated with the qmake binary in your $PATH. Run which qmake in order to find out which one it is. It will probably be the system-wide one. The fastest way to coerce cmake into finding your custom version is then adding your Qt's bin folder to the $PATH as the first entry and running kdevelop from that command line: PATH=/opt/Qt/5.8/bin:$PATH kdevelop. Code completion should then also work, as AFAIK kdevelop uses the include folders evaluated by cmake for code completion.
You might want to consider switching to QtCreator, which fixes this problem by listing all Qt versions as "Kits" which you can select in the project settings.
I just recently upgraded to Qt 5.7 and I am trying to build a project that needs to find several packages. I am on a mac also recently upgraded to el capitan. I have set CMAKE_PREFIX_PATH in my .bash_profile and I have checked the environment to verify that it is correct. When I do a cmake . on the folder my project is in (previously this was how I built) it gives me several errors such as:
CMake Warning at CMakeLists.txt:79 (FIND_PACKAGE):
By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"Qt5Widgets", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets" with
any of the following names:
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
"Qt5Widgets_DIR" to a directory containing one of the above files. If
"Qt5Widgets" provides a separate development package or SDK, be sure it has
been installed.
However I have already verified that the path is correct and that the files do indeed exist. I have tried several variations of cmake_prefix_path, for instance:
CMAKE_PREFIX_PATH=/Users/mnicholson/Qt/5.7/clang_64/
as well as
CMAKE_PREFIX_PATH=/Users/mnicholson/Qt/5.7/clang_64/lib/cmake/
but neither seems to work despite the fact that the cmake files are there. With older versions of qt setting the path worked, however since upgrading from 5.5 to 5.6 and then to 5.7 I'm baffled... HELP!! Is this a qt5.7 problem? El capitan?
Thanks!
Try find_package PATHS option. Something like
find_package(Qt5Widgets
CONFIG
PATHS /Users/mnicholson/Qt/5.7/clang_64/lib/cmake/Qt5Widgets
NO_DEFAULT_PATH)
I'm using CMake to build a Qt project, and it uses some of the newer Qt features and requires at least version 5.3 to build properly. I'd like to be nice to the people trying to build the project and fail at CMake configure time with a logical error telling them their CMake version isn't recent enough, rather than with some esoteric build error.
I know that I'll be getting at least version 5.0 by simply using the module find_package syntax (i.e. find_package(Qt5Widgets REQURIED)), but it's not so obvious how to make sure I'm using the right minor version.
What's the easiest way to do this?
I know this is a somewhat old post, but you can check the version using Qt5Widgets_VERSION. Here's some example CMake code:
find_package(Qt5Widgets REQUIRED)
if (Qt5Widgets_FOUND)
if (Qt5Widgets_VERSION VERSION_LESS 5.7.0)
message(FATAL_ERROR "Minimum supported Qt5 version is 5.70!")
endif()
else()
message(SEND_ERROR "The Qt5Widgets library could not be found!")
endif(Qt5Widgets_FOUND)
These days it is possible to pass a version to find_package, like this:
find_package(Qt5Core 5.10 REQUIRED)
The find_package call will fail if no compatible version of Qt5Core can be found:
CMake Warning at CMakeLists.txt:15 (find_package):
Could not find a configuration file for package "Qt5Core" that is
compatible with requested version "5.10".
The following configuration files were considered but not accepted:
C:/some/where/lib/cmake/Qt5Core/Qt5CoreConfig.cmake, version: 5.9.4
This is in-depth documented at https://cmake.org/cmake/help/latest/command/find_package.html#version-selection
There's no direct way to do this with the Qt-provided cmake packages, but it's easy enough to query the Qt version using qmake. Assuming you have something similar to the following already in the cmake files to locate the Qt install
set(QTDIR $ENV{QTDIR} CACHE STRING "Qt install path")
list(APPEND CMAKE_PREFIX_PATH ${QTDIR})
you can check the version and fail the configure step if it's too low like so
set(QT_MINIMUM_VERSION 5.3.0)
# Test for supported Qt version
find_program(QMAKE_EXECUTABLE NAMES qmake HINTS ${QTDIR} ENV QTDIR PATH_SUFFIXES bin)
execute_process(COMMAND ${QMAKE_EXECUTABLE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
if(QT_VERSION LESS QT_MINIMUM_VERSION)
MESSAGE(FATAL_ERROR "Minimum supported Qt version: ${QT_MINIMUM_VERSION}.
Installed version: ${QT_VERSION}")
endif()
I'm trying to create a CMakeLists.txt file which tries finding Qt5, and if that fails, tries falling back to a Qt4 installation. The script works so far, but I'll always get a warning if Qt5 is not installed.
Note that FindQt5.cmake is supplied by Qt5 and will not be available if only Qt4 is installed.
The basic structure is like this:
cmake_minimum_required(VERSION 2.8.11)
message("-- Searching for Qt5")
find_package(Qt5 COMPONENTS Core Xml Network)
if (Qt5_FOUND)
message("-- Searching for Qt5 - found version ${Qt5Core_VERSION}")
else (Qt5_FOUND)
message("-- Searching for Qt5 - not found")
# ...
endif (Qt5_FOUND)
The warning message in case Qt5 is not installed (or not set up properly) is the following:
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.
Is there a way to suppress this warning?
I'll also accept other ways to detect if Qt5 is installed or not.
In order to suppress the warning, the QUIET keyword can be used:
find_package(Qt5 COMPONENTS Core Xml Network QUIET)
find_package has CONFIG and MODULE arguments to tell cmake how to search for the package.
http://www.cmake.org/cmake/help/v3.0/command/find_package.html
http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html
Add the CONFIG keyword.