[CMake] Finding Qt4 binaries under Windows

Pau Garcia i Quiles pgquiles at elpauer.org
Fri Aug 21 15:44:09 EDT 2009


Hello,

On Fri, Aug 21, 2009 at 8:31 PM, Sebastian
Schuberth<sschuberth at gmail.com> 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)


More information about the CMake mailing list