[vtkusers] using QT4 and VTK

Wagner Sales wsales at gmail.com
Mon Oct 5 14:56:55 EDT 2009


Hi John,

I have a very simple CMakeLists to do this job, since I need to start
one or more project with these libs at a week. This file basically put
the files and supports resources of Qt if you have, and take care
about dependencies in .h uic generated files.

Here is:

PROJECT(SegmentationFramework)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
# Find ITK
FIND_PACKAGE(ITK)
IF(NOT ITK_DIR)
	MESSAGE(FATAL_ERROR "Please set ITK_DIR")
ENDIF(NOT ITK_DIR)
INCLUDE(${ITK_USE_FILE})

# Find VTK
FIND_PACKAGE(VTK)
IF(NOT VTK_DIR)
  MESSAGE(FATAL_ERROR "Please set VTK_DIR.")
ENDIF(NOT VTK_DIR)
INCLUDE(${VTK_USE_FILE})

# Find and works only with Qt4 or newer
SET(DESIRED_QT_VERSION 4 CACHE STRING "This project needs Qt4")
INCLUDE(${CMAKE_ROOT}/Modules/FindQt4.cmake )
SET(QT_USE_QTXML true) # I need XML
SET(QT_USE_QTSVG true) # I need SVG
SET(QT_USE_QTOPENGL true) # I need OpenGL

INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
# put in the new group all files are derived from a .ui gui file
SET( qtcpps
	)
# commom cpps ( qt and others )
SET(cpps
        main.cpp)


# qtheaders: haves an qobject macro
SET(    qtheaders
	)
# ui files
SET(    uis
	QPoluxSegmentationFilterWidgetBase.ui
	QPoluxSmoothWidgetParametersBase.ui)

# commom headers - not Qt objects or widgets
SET(    headers
)
#put in this group the qrc files, if haves
SET(QtApp_RCCS )
QT4_ADD_RESOURCES(rccsrcs ${QtApp_RCCS})
QT4_WRAP_UI(uiheaders ${uis})
QT4_WRAP_CPP(mocsrcs ${qtheaders})

ADD_DEFINITIONS(-DQT_GUI_LIBS -DQT_CORE_LIB)
SET_SOURCE_FILES_PROPERTIES(${qtcpps} PROPERTIES
			    OBJECT_DEPENDS "${uiheaders}")
if(COMMAND cmake_policy)
      cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

ADD_EXECUTABLE(myexec ${cpps} ${mocsrcs} ${rccsrcs} ${qtcpps} )

TARGET_LINK_LIBRARIES( myexec
  QVTK
  ${QT_LIBRARIES}
  vtkRendering
  vtkGraphics
  vtkIO
  vtkCommon
  ${ITK_LIBRARIES}
)

2009/10/5 John Drescher <drescherjm at gmail.com>:
> On Mon, Oct 5, 2009 at 12:56 PM, John Durkin <jrd5084 at psu.edu> wrote:
>> John,
>>
>> I appreciate you setting aside some time to help me out.  Perhaps most of my
>> problems stem from my lack of understanding of CMake and its syntax, but
>> would you have a simpler example of a CMakeLists.txt that enable the
>> compilation of .ui files and links ITK, VTK, and QT into a solution.  I
>> tried working with the example you sent me but I'm not positive what to
>> delete, change, or keep.  This guessing game is very inefficient.
>>
>
> Here is a much simpler example. This project is just a simple
> executable and does not have all the macros and internal libraries.
>
> PROJECT(CropDICOMImages)
>
> cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
>
> set (CropDICOMImages_VERSION_MAJOR 0)
> set (CropDICOMImages_VERSION_MINOR 1)
> set (CropDICOMImages_VERSION_PATCH 0)
>
> option (PACKAGE_FOR_INSTALL                     "Package CropDICOMImages for installation." ON)
>
> IF(WIN32)
>    CMAKE_MINIMUM_REQUIRED(VERSION 2.5 FATAL_ERROR)
>    SET(CMAKE_CXX_FLAGS "/WL /GR /EHsc" )
>    ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
> ENDIF(WIN32)
>
> ADD_DEFINITIONS(-DNEED_WL_FILTER)
>
> IF(COMMAND cmake_policy)
>  cmake_policy(SET CMP0003 NEW)
> endif(COMMAND cmake_policy)
>
> SET (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
> "Single output directory for building all libraries.")
> SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
> "Single output directory for building all executables.")
>
> FIND_PACKAGE( Boost REQUIRED )
> FIND_PACKAGE( Qt4 REQUIRED )
> FIND_PACKAGE( ITK REQUIRED )
> FIND_PACKAGE( VTK REQUIRED )
>
> INCLUDE( ${ITK_USE_FILE} )
> INCLUDE( ${VTK_USE_FILE} )
>
> FIND_PATH(ITK_VTK_GLUE_DIR "CMakeLists.txt" PATHS
> ${ITK_SOURCE_DIR}/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue)
> INCLUDE_DIRECTORIES(${ITK_VTK_GLUE_DIR}/src)
>
> INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} . Include)
>
> INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} )
>
> INCLUDE( ${QT_USE_FILE} )
> SET( UPMC_CROP_SRCS
>        ./src/main.cxx
>        ./src/mainwindow.cxx
>        ./src/textwidget.cxx
>        ./src/CropImage.cxx
> )
>
> SET( UPMC_CROP_MOC_HDR
>        ./Include/mainwindow.h
>        ./Include/textwidget.h
> )
>
> SET( UPMC_CROP_HDRS
>        ./Include/CropImage.h
> )
>
> # some .ui files
> SET( UPMC_CROP_UIS
>
> )
>
> # and finally an resource file
> SET( UPMC_CROP_RCS
>        ./rc/CropDICOMImages.qrc
> )
>
> # this command will generate rules that will run rcc on all files from
> UPMC_CROP_RCS
> # in result UPMC_CROP_RC_SRCS variable will contain paths to files
> produced by rcc
> QT4_ADD_RESOURCES( UPMC_CROP_RC_SRCS ${UPMC_CROP_RCS} )
>
> # and finally this will run moc:
> QT4_WRAP_CPP( UPMC_CROP_MOC_SRCS ${UPMC_CROP_MOC_HDR} )
>
> # this will run uic on .ui files:
> QT4_WRAP_UI( UPMC_CROP_UI_HDRS ${UPMC_CROP_UIS} )
>
> LINK_LIBRARIES ( CropDICOMImages ${QT_LIBRARIES} ITKCommon
> ITKBasicFilters ITKIO QVTK vtkCommon
> )
>
> ADD_EXECUTABLE( CropDICOMImages ${UPMC_CROP_SRCS}
> ${UPMC_CROP_MOC_SRCS} ${UPMC_CROP_HDRS}
> ${UPMC_CROP_MOC_HDR} ${UPMC_CROP_RC_SRCS} ${UPMC_CROP_UI_HDRS}
> )
>
> #########################################################################################
>
> install(TARGETS CropDICOMImages
>   RUNTIME
>   DESTINATION bin
>   COMPONENT Applications
> )
>
> #########################################################################################
>
> IF(PACKAGE_FOR_INSTALL)
>
> SET(CPACK_PACKAGE_VERSION_MAJOR ${CropDICOMImages_VERSION_MAJOR})
> SET(CPACK_PACKAGE_VERSION_MINOR ${CropDICOMImages_VERSION_MINOR})
> SET(CPACK_PACKAGE_VERSION_PATCH ${CropDICOMImages_VERSION_PATCH})
>
>
> IF(UNIX AND NOT APPLE)
>    INSTALL(TARGETS HyvesDesktop
>        DESTINATION bin
>    )
>    FOREACH(LIB QtCore QtXml QtTest QtGui QtNetwork QtScript)
>        INSTALL(FILES
>            "${QT_LIBRARY_DIR}/lib${LIB}.so.${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}"
>            RENAME "lib${LIB}.so.${QT_VERSION_MAJOR}"
>            DESTINATION bin
>        )
>    ENDFOREACH(LIB)
> ENDIF(UNIX AND NOT APPLE)
>
> IF(WIN32)
>        SET(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
>        SET(CPACK_PACKAGE_EXECUTABLES "CropDICOMImages" "CropDICOMImages")
>
>        INSTALL(FILES
>                        "${QT_LIBRARY_DIR}/QtCore${QT_VERSION_MAJOR}.dll"
>                        "${QT_LIBRARY_DIR}/QtXml${QT_VERSION_MAJOR}.dll"
>                        "${QT_LIBRARY_DIR}/QtTest${QT_VERSION_MAJOR}.dll"
>                        "${QT_LIBRARY_DIR}/QtGui${QT_VERSION_MAJOR}.dll"
>                        "${QT_LIBRARY_DIR}/QtNetwork${QT_VERSION_MAJOR}.dll"
>                        "${QT_LIBRARY_DIR}/QtScript${QT_VERSION_MAJOR}.dll"
>                        DESTINATION bin
>                        COMPONENT Applications
>        )
> ENDIF(WIN32)
>
> set(CPACK_COMPONENTS_ALL Applications)
>
> INCLUDE(CPack)
> ENDIF(PACKAGE_FOR_INSTALL)
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list