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 ==
== CMakeLists.txt ==
<source lang=text>
<source lang=cmake>
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 2.6)
PROJECT(Test)
PROJECT(Test)
Line 17: Line 17:


This will prevent annoying cmake warnings about "you must specifiy a minimum required version".
This will prevent annoying cmake warnings about "you must specifiy a minimum required version".
<source lang=text>
<source lang=cmake>
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 2.6)
</source>
</source>


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


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


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

Revision as of 16:01, 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>