Finding Qt4 binaries under Windows

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Finding Qt4 binaries under Windows

Sebastian Schuberth
Hi,

I'm trying to use CMake for a Windows application that links against Qt
4. I've installed Qt 4.5.1 from sources (unzipped to the standard
location C:\Qt\4.5.1) and compiled it myself.

As qmake is not in my PATH, I'm using

---8<---(snip)---

cmake_minimum_required(VERSION 2.6.4)

set(name "Qt Test")
project(${name})

file(GLOB_RECURSE sources "src/*.h" "src/*.cpp" "src/*.ui")
add_executable(${name} ${sources})

include(FindQt4)
find_package(Qt4 PATHS "C:/Qt")

---8<---(snip)---

to point CMake to the right directory. It seems to work, sort of, but
I'm getting the following error:

---8<---(snip)---

   Could not find a configuration file for package Qt4.

   Set Qt4_DIR to the directory containing a CMake configuration file
for Qt4.
   The file will have one of the following names:

     Qt4Config.cmake
     qt4-config.cmake

---8<---(snip)---

Why is CMake searching for such a file? Where should that file be
located? Do I need to create it?

--
Sebastian Schuberth

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding Qt4 binaries under Windows

Michael Jackson
set QTDIR to C:\Qt\4.5.1

#  
------------------------------------------------------------------------------
#  Qt 4 Section
#  
------------------------------------------------------------------------------
# by default only QtCore and QtGui modules are enabled
# other modules must be enabled like this:
IF (WIN32)
     SET (QT_USE_QTMAIN TRUE)
ENDIF (WIN32)

# this command finds Qt4 libraries and sets all required variables
# note that it's Qt4, not QT4 or qt4
FIND_PACKAGE( Qt4 REQUIRED )

# add some useful macros and variables
# (QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 ) that
# contains a path to CMake script)
INCLUDE( ${QT_USE_FILE} )

# Set the GUI type for different platforms
SET(GUI_TYPE )

# Set some Win32 Specific Settings
IF(WIN32)
  SET(GUI_TYPE WIN32)
ENDIF(WIN32)

_________________________________________________________
Mike Jackson                  [hidden email]
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio

On Aug 21, 2009, at 2:31 PM, Sebastian Schuberth wrote:

> Hi,
>
> I'm trying to use CMake for a Windows application that links against  
> Qt 4. I've installed Qt 4.5.1 from sources (unzipped to the standard  
> location C:\Qt\4.5.1) and compiled it myself.
>
> As qmake is not in my PATH, I'm using
>
> ---8<---(snip)---
>
> cmake_minimum_required(VERSION 2.6.4)
>
> set(name "Qt Test")
> project(${name})
>
> file(GLOB_RECURSE sources "src/*.h" "src/*.cpp" "src/*.ui")
> add_executable(${name} ${sources})
>
> include(FindQt4)
> find_package(Qt4 PATHS "C:/Qt")
>
> ---8<---(snip)---
>
> to point CMake to the right directory. It seems to work, sort of,  
> but I'm getting the following error:
>
> ---8<---(snip)---
>
>  Could not find a configuration file for package Qt4.
>
>  Set Qt4_DIR to the directory containing a CMake configuration file  
> for Qt4.
>  The file will have one of the following names:
>
>    Qt4Config.cmake
>    qt4-config.cmake
>
> ---8<---(snip)---
>
> Why is CMake searching for such a file? Where should that file be  
> located? Do I need to create it?
>
> --
> Sebastian Schuberth
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding Qt4 binaries under Windows

Pau Garcia i Quiles
In reply to this post by Sebastian Schuberth
Hello,

On Fri, Aug 21, 2009 at 8:31 PM, Sebastian
Schuberth<[hidden email]> wrote:

> Hi,
>
> I'm trying to use CMake for a Windows application that links against Qt 4.
> I've installed Qt 4.5.1 from sources (unzipped to the standard location
> C:\Qt\4.5.1) and compiled it myself.
>
> As qmake is not in my PATH, I'm using
>
> ---8<---(snip)---
>
> cmake_minimum_required(VERSION 2.6.4)
>
> set(name "Qt Test")
> project(${name})
>
> file(GLOB_RECURSE sources "src/*.h" "src/*.cpp" "src/*.ui")
> add_executable(${name} ${sources})
>
> include(FindQt4)
> find_package(Qt4 PATHS "C:/Qt")
>
> ---8<---(snip)---
>
> to point CMake to the right directory. It seems to work, sort of, but I'm
> getting the following error:
>
> ---8<---(snip)---
>
>  Could not find a configuration file for package Qt4.
>
>  Set Qt4_DIR to the directory containing a CMake configuration file for Qt4.
>  The file will have one of the following names:
>
>    Qt4Config.cmake
>    qt4-config.cmake
>
> ---8<---(snip)---
>
> Why is CMake searching for such a file? Where should that file be located?
> Do I need to create it?

It's a bit of a cryptic error :-)

First of all, the Qt4Config.cmake thing:

When you issue a find_package( Whatever ), CMake will look for
FindWhatever.cmake in CMAKE_MODULE_PATH. If FindWhatever.cmake is not
found, it will look for WhateverConfig.cmake in some paths.

What you did is wrong:

include(FindQt4)  <-- This is NOT how you use finders
find_package(Qt4 PATHS "C:/Qt")

What you should do is:

set( CMAKE_MODULE_PATH c:/where/you/copied/FindQt4.cmake )  <-- Only
needed if you are using a special FindQt4.cmake, otherwise, it is
included in the CMake distribution

find_package(Qt4 PATHS "C:/Qt")

It won't fail now.

--
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding Qt4 binaries under Windows

Sebastian Schuberth
On 21.08.2009 21:44, Pau Garcia i Quiles wrote:

Thanks for your explanations.

> What you should do is:
>
> set( CMAKE_MODULE_PATH c:/where/you/copied/FindQt4.cmake )<-- Only
> needed if you are using a special FindQt4.cmake, otherwise, it is
> included in the CMake distribution
>
> find_package(Qt4 PATHS "C:/Qt")
>
> It won't fail now.

Unforunately, it still fails, with the exact same error.

--
Sebastian Schuberth

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding Qt4 binaries under Windows

Sebastian Schuberth
In reply to this post by Michael Jackson
On 21.08.2009 21:14, Michael Jackson wrote:

> set QTDIR to C:\Qt\4.5.1

Thanks, but that's out of the question, as I'd like to have it working
independent of the actual Qt4 version.

--
Sebastian Schuberth

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding Qt4 binaries under Windows

Michael Jackson
In reply to this post by Sebastian Schuberth
>> find_package(Qt4 PATHS "C:/Qt/4.5.1")
_________________________________________________________
Mike Jackson                  [hidden email]
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio

On Aug 21, 2009, at 4:00 PM, Sebastian Schuberth wrote:

>> find_package(Qt4 PATHS "C:/Qt")
>>
>> It won't fail now.
>
> Unforunately, it still fails, with the exact same error.

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding Qt4 binaries under Windows

Michael Jackson
In reply to this post by Sebastian Schuberth
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.

On Fri, Aug 21, 2009 at 8:31 PM, Sebastian
Schuberth<[hidden email]> wrote:
> Hi,
>
> I'm trying to use CMake for a Windows application that links against  
> Qt 4.
> I've installed Qt 4.5.1 from sources (unzipped to the standard  
> location
> C:\Qt\4.5.1) and compiled it myself.

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?

--
Mike Jackson <www.bluequartz.net>

On Aug 21, 2009, at 4:01 PM, Sebastian Schuberth wrote:

> On 21.08.2009 21:14, Michael Jackson wrote:
>
>> set QTDIR to C:\Qt\4.5.1
>
> Thanks, but that's out of the question, as I'd like to have it  
> working independent of the actual Qt4 version.
>
> --
> Sebastian Schuberth
>
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding Qt4 binaries under Windows

John Drescher-2
> 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
>

I just let cmake-gui try to find it and when it fails I manually set
the location of the qmake executable. This way I can have more than 1
Qt version installed and I do not have to play with environment
variables to switch between versions. After telling cmake-gui where
qmake.exe is for a project it will never ask me again unless I clear
the cache. I guess I could create a batch file that launches cmake-gui
with a different environment to do this but its not like I do this
ever day..

John
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding Qt4 binaries under Windows

Pau Garcia i Quiles
On Fri, Aug 21, 2009 at 10:31 PM, John Drescher<[hidden email]> wrote:

>> 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
>>
>
> I just let cmake-gui try to find it and when it fails I manually set
> the location of the qmake executable. This way I can have more than 1
> Qt version installed and I do not have to play with environment
> variables to switch between versions. After telling cmake-gui where
> qmake.exe is for a project it will never ask me again unless I clear
> the cache. I guess I could create a batch file that launches cmake-gui
> with a different environment to do this but its not like I do this
> ever day..

It's late and I'm tired but I'd say you need to:

- Run regedit and remove
HKEY_CURRENT_USER\Software\Trolltech\Versions\DefaultQtVersion, if you
have if, because this is where the default QT version is picked from.

- Take a look at qt.conf ( http://doc.trolltech.com/4.5/qt-conf.html )
because I've got the feeling the paths qmake is returning in your
machine are not the actual paths

- Call CMake like this: "cmake
-DQT_QMAKE_EXECUTABLE:FILEPATH=C:/Qt/4.5.1/bin/qmake.exe", or whatever
you want, so that you don't need to use the GUI to edit the cache and
CMake does not need to look for Qt twice (first time and fail, then
after you tell CMake the actual path to QMake). This way you can have
several versions of Qt installed and you don't need to play with
environment variables.

--
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding Qt4 binaries under Windows

Sebastian Schuberth
In reply to this post by Michael Jackson
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")

which still gives me the

"Could not find a configuration file for package Qt4."

error.

--
Sebastian Schuberth

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding Qt4 binaries under Windows

Alexander Neundorf-3
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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Finding Qt4 binaries under Windows

Sebastian Schuberth
On 05.09.2009 18:49, Alexander Neundorf wrote:

>> 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.

Thanks a lot, Alex, that finally was a helpful answer!

FYI, in a batch file I'm now doing:

---8<---

: Search QTDIR first, then some guessed paths.
set CMAKE_PREFIX_PATH=%QTDIR%;C:\Qt\4.5.2;C:\Qt\4.5.1;C:\Qt\4.5.0;%CMAKE_PREFIX_PATH%

: Generate the project files in the output directory.
pushd VS2008-Win32
cmake -G "Visual Studio 9 2008" ..
if errorlevel 1 pause
popd

---8<---

CMake would search QTDIR itself, but only *after* CMAKE_PREFIX_PATH, which is why I made QTDIR the first path in CMAKE_PREFIX_PATH. This now seems to work how I would like it to work.

Thanks again.

--
Sebastian Schuberth

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake