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

Hicham Mouline hicham at mouline.org
Thu Dec 31 17:05:00 EST 2009


> -----Original Message-----
> From: Clinton Stimpson [mailto:clinton at elemtech.com]
> Sent: 31 December 2009 20:29
> To: Hicham Mouline
> Cc: cmake at cmake.org
> Subject: Re: [CMake] restricting Qt include and library linking to 1
> library/project
> 
> 
> 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.

This is driving me a bit crazy.
I stripped the subdir cmake file down to the minimum:

ADD_LIBRARY(plot STATIC
...
...
...)
TARGET_LINK_LIBRARIES(plot "C:/Progra~2/Qt/4.6.0/lib/QtCored4.lib")


1. from cmd dos: dir "C:/Progra~2/Qt/4.6.0/lib/QtCored4.lib"  => nothing
   But dir "C:\Progra~2\Qt\4.6.0\lib\QtCored4.lib"  => works

2. I tried all the following:
TARGET_LINK_LIBRARIES(plot "C:/Progra~2/Qt/4.6.0/lib/QtCored4.lib")
TARGET_LINK_LIBRARIES(plot C:/Progra~2/Qt/4.6.0/lib/QtCored4.lib)

Neither generates a plot.vcjproj containing this .lib at all

TARGET_LINK_LIBRARIES(plot "C:\Progra~2\Qt\4.6.0\lib\QtCored4.lib")
TARGET_LINK_LIBRARIES(plot C:\Progra~2\Qt\4.6.0\lib\QtCored4.lib)
Fail with a syntax error by cmake.

I reckon it's got something to do with how the path is specified.

Rds,



More information about the CMake mailing list