[CMake] restricting Qt include and library linking to 1 library/project

Clinton Stimpson clinton at elemtech.com
Thu Dec 31 15:28:30 EST 2009


On Dec 31, 2009, at 1:12 PM, Hicham Mouline wrote:

>> -----Original Message-----
>> From: Clinton Stimpson [mailto:clinton at elemtech.com]
>> Sent: 31 December 2009 16:08
>> To: Hicham Mouline
>> Cc: cmake at cmake.org
>> Subject: Re: [CMake] restricting Qt include and library linking to 1
>> library/project
>> 
>> 
>> If you have multiple directories with different Qt dependencies, you can
>> do:
>> find_package(Qt4 REQUIRED)
>> in the top directory,
>> then each sub directory can do something like
>> set(QT_USE_QTOPENGL 1)
>> include(${QT_USE_FILE})
>> 
>> But in your case, its only lib3, so just do it in that CMakeLists.txt
>> file.
>> 
>> Clint
>> 
> That's what I did at the end. 
> I did this:
> 
> FIND_PACKAGE(Qt4 4.6.0 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)
> INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR}
> ${QT_QTGUI_INCLUDE_DIR})
> MESSAGE(STATUS "QT_QTCORE_LIBRARY=${QT_QTCORE_LIBRARY}")
> TARGET_LINK_LIBRARIES(plot $QT_QTCORE_LIBRARY)
> 
> The include dirs are set correctly, but I'm having trouble with
> QT_QTCORE_LIBRARY.
> This appears as :
> QT_QTCORE_LIBRARY=optimized;C:/Progra~2/Qt/4.6.0/lib/QtCore4.lib;debug;C:/Pr
> ogra~2/Qt/4.6.0/lib/QtCored4.lib
> 
> When I open the solution with vs2008, the Librarian doesn't show this
> libraries as input.
> 
> Note the help for TARGET_LINK_LIBRARIES displays the syntax as:
> target_link_libraries(<target> [item1 [item2 [...]]]
>                       [[debug|optimized|general] <item>] ...)
> 
> There are no semicolons after the optimized|debug keywords, I wonder if by
> not using QT_USE_FILE, QT_QTCORE_LIBRARY are others are set incorrecty.
> 
> Rds,
> 

You probably meant ${QT_QTCORE_LIBRARY} instead of $QT_CORE_LIBRARY

What about this:

find_package(Qt4 4.6.0 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)
include(${QT_USE_FILE})
...
target_link_libraries(plot ${QT_LIBRARIES})

The file pointed to by QT_USE_FILE sets up the current directory with include directories and compile flags and sets up QT_LIBRARIES for the chosen components.
You can do it on your own, but its more work.

Clint



More information about the CMake mailing list