VTK/Tutorials/CMakeListsFile: Difference between revisions

From KitwarePublic
< VTK‎ | Tutorials
Jump to navigationJump to search
No edit summary
(vtkHybrid --> ${VTK_LIBRARIES})
 
(4 intermediate revisions by one other user not shown)
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:


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


FIND_PACKAGE(VTK REQUIRED)
</source>
INCLUDE(${VTK_USE_FILE})


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


==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>
</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>