[CMake] Using QT with ITK

Filipe Sousa filipe at ipb.pt
Tue Apr 18 17:34:08 EDT 2006


On Tuesday 18 April 2006 20:04, Julien Marchand wrote:
> Hi!
>
> I have to do a program integrating both Qt and ITK. Therefore, I have
> to use Cmake. However, I'm having trouble building my cmakelists. More
> precisely, I have trouvle with Qt_WRAP_CPP and QT_WRAP_UI.
>
> I get a "Attempt to add custom rule to output "moc_pline.cxx" which
> already has a custom rule" error. In fact, it happens for all my
> sources once with the moc_ prefix and once without it (moc_pline.cxx
> and pline.h).
>
> I suspect I have a bug with my CMakeList, but I fail to spot it. Here
> is my CMakeLists.txt.
>
>
> Thanks a lot,
>
> Julien Marchand
>
>
> PROJECT(QtChange)
>
> FIND_PACKAGE (ITK)
> 	IF (ITK_FOUND)
> 		INCLUDE( ${USE_ITK_FILE} )
> 	ENDIF(ITK_FOUND)
>
> FIND_PACKAGE (QT)
> 	IF (QT_FOUND)
> 		INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} )
> 	ENDIF(QT_FOUND)
>
> LINK_LIBRARIES (${ITKLIBRARIES} ${QT_LIBRARIES} )

Don't use LINK_LIBRARIES, you should use TARGET_LINK_LIBRARIES
fsousa at neptuno ~ $ cmake --help-command LINK_LIBRARIES
cmake version 2.3-20060417
  LINK_LIBRARIES
       Link libraries to all targets added later.

         LINK_LIBRARIES(library1 <debug | optimized> library2 ...)

       This is an old CMake command for linking libraries.  Use
       TARGET_LINK_LIBRARIES unless you have a good reason for every target
       to link to the same set of libraries.

       Specify a list of libraries to be linked into any following targets
       (typically added with the ADD_EXECUTABLE or ADD_LIBRARY calls).  This
       command is passed down to all subdirectories.  The debug and optimized
       strings may be used to indicate that the next library listed is to be
       used only for that specific type of build.


> SET(QtITK_SRCS
> 		main.cpp
> 		roadNetwork.cpp
> 		road.cpp
> 		pline.cpp)
>
> SET(QtITK_HDRS
> 		roadNetwork.h
> 		road.h
> 		pline.h)
>
> SET(QtITK_MOC_SRCS
> 		window.ui)
>
> 	IF(QT_WRAP_CPP )
> 		QT_WRAP_CPP(QtChange ${QtITK_SRCS} ${QtITK_MOC_HDRS})

The QtITK_MOC_HDRS is the list of header files to produce moc files which is 
empty. If you need to moc pline.h the right command is QT_WRAP_CPP(QtChange 
QtITK_SRCS pline.h) or SET(QtITK_MOC_HDRS pline.h) and QT_WRAP_CPP(QtChange 
QtITK_SRCS ${QtITK_MOC_HDRS})

> 	ENDIF(QT_WRAP_CPP )
>
> 	IF(QT_WRAP_UI)
>  		QT_WRAP_UI(QtChange ${QtITK_HDRS} ${QtITK_SRCS} ${QtITK_MOC_SRCS})

QT_WRAP_UI(QtChange QtITK_HDRS QtITK_SRCS window.ui)
>  	ENDIF(QT_WRAP_UI)
>
> ADD_EXECUTABLE(QtChange ${QtITK_SRCS} ${QtIRK_HDRS})
>
> TARGET_LINK_LIBRARIES(QtChange
> 	   ITKAlgorithms
> 	   ITKBasicFilters
> 	   ITKCommon
> 	   ITKIO
> 	   ITKMetaIO
> 	   ITKNumerics
> 	   itkvnl
> 	   itkvnl_algo
> 	   itknetlib
> 		${QT_LIBRARIES})
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake

Have a look at 
http://public.kitware.com/cgi-bin/viewcvs.cgi/Tests/Wrapping/CMakeLists.txt?rev=1.38&root=CMake&view=markup
there is a Qt wrapper example
-- 
Filipe Sousa
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20060418/9bec4511/attachment.pgp


More information about the CMake mailing list