[CMake] Finding Qt4 binaries under Windows

Alexander Neundorf a.neundorf-work at gmx.net
Sat Sep 5 12:49:29 EDT 2009


On Saturday 22 August 2009, Sebastian Schuberth wrote:
> On 21.08.2009 22:22, Michael Jackson wrote:
> > YOU are the one who compiled it in C:\Qt\4.5.1 according to your
> > original post. I am simply making you aware of the error.
>
> Well, I specified "C:/Qt" instead of "C:/Qt/4.5.1" on purpose. The point
> is: I have compiled Qt myself, and not used the installer, thus there
> are no registry keys and qmake is not in my PATH. So it's clear that
> CMake cannot find my Qt installation without any hints from my side.
> On the other hand, I want my CMakeLists.txt file to be as generic as
> possible, and not mention any version specific directories. As it's sort
> of common for people to have Qt installed beneath "C:/Qt" on Windows, I
> thought it might be possible to instruct find_package() to recursively
> search for Qt / qmake starting at "C:/Qt".
>
> > So, if you compiled to C:\Qt\4.5.1 then you have a couple of options:
> >
> > set QTDIR to C:\Qt\4.5.1 in the environment variables.
> >
> > OR
> >
> > find_package(Qt4 PATHS "C:/Qt/4/.5.1") like Pau suggested.
> >
> > If you don't like the version number on there then recompile Qt 4.5.1 so
> > that it has a path of C:\Qt and NOT C:\Qt\4.5.1
> >
> > Understand?
>
> Yes, I perfectly understand, it's just not what I want, and I'm a little
> disappointed how limited find_package(Qt4) seems to be.
>
> There is not need to recompile Qt in order to make it available at
> "C:/Qt" instead of "C:/Qt/4.5.1", I just would have to move the files.
> But like I said, the default install location for Qt on Windows is
> "C:/Qt/<version>", and this is what e.g. the PDB files expect when
> debugging Qt in Visual Studio.
>
> But just for the fun of it, I also tried Pau's
>
> find_package(Qt4 PATHS "C:/Qt/4.5.1")

If you use PATHS, cmake looks for a Qt4Config.cmake file, which does not 
exist. So don't use PATHS or HINTS, just do:

find_package(Qt4)  (maybe add the REQUIRED keyword).

This will load FindQt4.cmake.
FindQt4.cmake then tries to find qmake.
This is where you can help.
There are multiple options:
execute cmake from an environment where PATH points to the directory where 
qmake is:

1)
$ export PATH=/opt/qt451/bin:$PATH
$ cmake <dir>

2) run it from an environment where the env. var. CMAKE_PREFIX_PATH points to 
the base install directory of Qt:
$ export CMAKE_PREFIX_PATH=/opt/qt451:$CMAKE_PREFIX_PATH
$ cmake <dir>

3) set CMAKE_PREFIX_PATH (the cmake variable) from the command line (via -D) 
or in the CMakeLists.txt, e.g.:

set(CMAKE_PREFIX_PATH /opt/qt451)
find_package(Qt4)

4) set QT_QMAKE_EXECUTABLE directly, as Pau suggested

Alex


More information about the CMake mailing list