VTK/Tutorials/CMakeListsFile: Difference between revisions

From KitwarePublic
< VTK‎ | Tutorials
Jump to navigationJump to search
No edit summary
(No difference)

Revision as of 16:02, 22 January 2010

To use CMake to generate your project, this is what the CMakeLists.txt file should look like:

CMakeLists.txt

<source lang=cmake> cmake_minimum_required(VERSION 2.6) PROJECT(Test)

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

ADD_EXECUTABLE(Test Test.cpp) TARGET_LINK_LIBRARIES(Test vtkHybrid)

</source>

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". <source lang=cmake> cmake_minimum_required(VERSION 2.6) </source>

Name the project. <source lang=cmake> PROJECT(Test) </source>

Tell cmake that this project needs to use VTK. <source lang=cmake> FIND_PACKAGE(VTK REQUIRED) INCLUDE(${VTK_USE_FILE}) </source>

Tell cmake we want to compile Test.cpp into a binary called Test. <source lang=cmake> ADD_EXECUTABLE(Test Test.cpp) </source>

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. <source lang=cmake> TARGET_LINK_LIBRARIES(Test vtkHybrid) </source>