VTK/Tutorials/CMakeListsFile: Difference between revisions
Daviddoria (talk | contribs) No edit summary |
Hal Canary (talk | contribs) (vtkHybrid --> ${VTK_LIBRARIES}) |
||
(One intermediate revision by one other user not shown) | |||
Line 4: | Line 4: | ||
<source lang=cmake> | <source lang=cmake> | ||
cmake_minimum_required(VERSION 2.6) | cmake_minimum_required(VERSION 2.6) | ||
project(Test) | |||
set(VTK_DIR "PATH/TO/VTK/BUILD/DIRECTORY") | |||
find_package(VTK REQUIRED) | |||
include(${VTK_USE_FILE}) | |||
add_executable(Test Test.cxx) | |||
target_link_libraries(Test ${VTK_LIBRARIES}) | |||
</source> | |||
==Explanation== | |||
Here is a line by line break down of what is going on: | Here is a line by line break down of what is going on: | ||
Line 22: | Line 24: | ||
Name the project. | Name the project. | ||
<source lang=cmake> | <source lang=cmake>project(Test)</source> | ||
</source> | |||
Tell cmake that this project needs to use VTK. | Tell cmake that this project needs to use VTK. | ||
<source lang=cmake> | <source lang=cmake> | ||
set(VTK_DIR "/PATH/TO/VTK/BUILD/DIRECTORY") | |||
find_package(VTK REQUIRED) | |||
include(${VTK_USE_FILE}) | |||
</source> | </source> | ||
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=cmake> | <source lang=cmake> | ||
add_executable(Test Test.cxx) | |||
</source> | </source> | ||
Tell cmake we need to link Test against | Tell cmake we need to link Test against the VTK libraries. | ||
<source lang=cmake> | <source lang=cmake> | ||
target_link_libraries(Test ${VTK_LIBRARIES}) | |||
</source> | </source> |
Latest revision as of 17:53, 14 August 2012
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) set(VTK_DIR "PATH/TO/VTK/BUILD/DIRECTORY") find_package(VTK REQUIRED) include(${VTK_USE_FILE}) add_executable(Test Test.cxx) target_link_libraries(Test ${VTK_LIBRARIES})
</source>
Explanation
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> set(VTK_DIR "/PATH/TO/VTK/BUILD/DIRECTORY") 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.cxx) </source>
Tell cmake we need to link Test against the VTK libraries. <source lang=cmake> target_link_libraries(Test ${VTK_LIBRARIES}) </source>