VTK/Tutorials/CMakeListsFile: Difference between revisions

From KitwarePublic
< VTK‎ | Tutorials
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
To use Cmake to generate your project, this is what the CMakeLists.txt file should look like:
To use Cmake to generate your project, this is what the CMakeLists.txt file should look like:


== CMakeLists.txt ==
<source lang=text>
<source lang=text>
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 2.6)
Line 11: Line 12:
TARGET_LINK_LIBRARIES(Test vtkHybrid)
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=text>
cmake_minimum_required(VERSION 2.6)
</source>
Name the project.
<source lang=text>
PROJECT(Test)
</source>
Tell cmake that this project needs to use VTK.
<source lang=text>
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
</source>
Tell cmake we want to compile Test.cpp into a binary called Test.
<source lang=text>
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=text>
TARGET_LINK_LIBRARIES(Test vtkHybrid)
</source>
</source>

Revision as of 13:17, 20 October 2009

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

CMakeLists.txt

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

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

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

Tell cmake we want to compile Test.cpp into a binary called Test. <source lang=text> 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=text> TARGET_LINK_LIBRARIES(Test vtkHybrid) </source>