[CMake] FindQt4.cmake to automatically include QT_USE_FILE?

Bjørn Forsman bjorn.forsman at gmail.com
Tue Jun 7 12:34:17 EDT 2011


On 7 June 2011 16:32, Rolf Eike Beer <eike at sf-mail.de> wrote:
>> Hi all,
>>
>> As far as I can tell, all Qt programs built with CMake must include
>> QT_USE_FILE after find_package(). So why doesn't FindQt4.cmake simply
>> include QT_USE_FILE itself? Is there maybe a use case where
>> QT_USE_FILE is *not* wanted?
>
> Besides the points already given here is another example:
>
> CMakeLists.txt:
>
> find_package(Qt4 REQUIRED)
> add_subdirectory(a)
> add_subdirectory(b)
>
> a/CMakeLists.txt
>
> SET(QT_DONT_USE_QTGUI TRUE)
> INCLUDE(${QT_USE_FILE})
> ...
> TARGET_LINK_LIBRARIES(foo ${QT_LIBRARIES})
>
> b/CMakeLists.txt
> INCLUDE(${QT_USE_FILE})
> ...
> TARGET_LINK_LIBRARIES(bar ${QT_LIBRARIES})
>
> So bar would get linked against QtGui, but foo not. And this all without
> fiddling with all the single Qt libraries and their dependencies.

I see. I want to do the same, but slightly more readable (IMHO). If
find_package also includes the use file we could do this:

CMakeLists.txt:

add_subdirectory(a)
add_subdirectory(b)

a/CMakeLists.txt

find_package(Qt4 COMPONENTS QtCore REQUIRED)
...
TARGET_LINK_LIBRARIES(foo ${QT_LIBRARIES})

b/CMakeLists.txt
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
...
TARGET_LINK_LIBRARIES(bar ${QT_LIBRARIES})


foo will be linked to QtCore and bar will be linked to QtCore+QtGui.

What do you think?


More information about the CMake mailing list