[vtkusers] using QT4 and VTK

John Drescher drescherjm at gmail.com
Mon Oct 5 13:38:41 EDT 2009


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)



More information about the vtkusers mailing list