VTK/Tutorials/CMakeListsFileForQt4

From KitwarePublic
< VTK‎ | Tutorials
Revision as of 08:05, 1 July 2010 by Jrcho (talk | contribs) (Created page with '== CMakeLists.txt == <source lang=cmake> project(application) cmake_minimum_required(VERSION 2.8.0) find_package(VTK) include(${VTK_USE_FILE}) find_package(Qt4 REQUIRED) inclu…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

CMakeLists.txt

project(application)

cmake_minimum_required(VERSION 2.8.0)

find_package(VTK)
include(${VTK_USE_FILE})

find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})

# support for out-of-source build
INCLUDE_DIRECTORIES(
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}
)

set(SRC
    optionsDialog.h optionsDialog.cpp
    main.cpp
    mainwindow.h mainwindow.cpp
    application.qrc
)

set(MOC optionsDialog.h  mainwindow.h )
set(UI optionsDialog.ui mainwindow.ui)
set(RCC application.qrc )

qt4_wrap_cpp(MOC_GENERATED ${MOC})
qt4_wrap_ui(UI_GENERATED ${UI})
qt4_add_resources(RCC_GENERATED ${RCC})

source_group("Form Files" FILES ${UI} )
source_group("Resource Files" FILES ${RCC} )
source_group("Generated Files" FILES ${MOC_GENERATED}   ${UI_GENERATED}  ${RCC_GENERATED} )

add_executable(application WIN32
    ${SRC}
    ${MOC_GENERATED}   ${UI_GENERATED}  ${RCC_GENERATED} )

target_link_libraries(application  ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY} QVTK vtkHybrid)


Here is a line by line break down of what is going on:

This will prevent annoying cmake warnings about "you must specifiy a minimum required version".

cmake_minimum_required(VERSION 2.6)

Name the project.

PROJECT(Test)

Tell cmake that this project needs to use VTK.

FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})

Tell cmake we want to compile Test.cpp into a binary called Test.

ADD_EXECUTABLE(Test Test.cpp)

Tell cmake we need to link Test against vtkHybrid. This is the "catch all" VTK library. If you don't know what to link to, most of the time vtkHybrid will have what you need.

TARGET_LINK_LIBRARIES(Test vtkHybrid)