[Development] Installing Qt5Config.cmake from the Qt repo?

Thiago Macieira thiago.macieira at intel.com
Wed Nov 2 11:50:11 CET 2011


On Wednesday, 2 de November de 2011 11:26:10 Stephen Kelly wrote:
> The use file is a convenience that is relatively common in cmake modules
> that  adds includes and definitions etc, but the more direct way is also
> possible.

So we go back to what I said: the names of the individual variables are part 
of the public API of FindQt5.cmake.

However, let me make a suggestion: use macros, not variables. We've run into 
this problem before in Qt 4 where CMake did not add the -D macros that qmake 
did and then some results were different (unit tests, for example).

So the example I had should be instead rewritten to:

project(MyLib)
find_target(Qt5)

add_library(mylib SHARED ${mylib_SRCS})
qt5_add_module(mylib PUBLIC Core Gui Declarative PRIVATE Xml)

add_executable(tst_mylib NOGUI ${tst_mylib_SRC})
target_link_libraries(tst_mylib mylib)
qt5_add_module(tst_mylib Test Xml)


Much simpler and more future-proof. What's more, since QtCore, QtGui and 
QtDeclarative are part of MyLib's public interface, anything linking to it 
automatically inherits them (e.g., qmake's QT += or LIBS += line). The private 
dependencies are an implementation detail, which may need to be exposed if 
static linking is being attempted (qmake's QT_PRIVATE += or LIBS_PRIVATE += 
line).

Another benefit is that I don't have to remember to list which modules I want 
in find_target. They should be automatically gathered from the qt5_add_module 
commands -- like qmake. Unlike qmake, if I want to decide whether to add some 
code based on the presence or absence a dependency, then I'd verify some 
variables set by FindQt5.cmake.

The above is only missing a listing of headers so that qt5_add_module knows 
what to moc. I don't know how that is implemented these days (qmake's 
HEADERS += line).

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
     Intel Sweden AB - Registration Number: 556189-6027
     Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20111102/538dad43/attachment.sig>


More information about the Development mailing list