VTK/Tutorials/CMakeListsFile

From KitwarePublic
< VTK‎ | Tutorials(Redirected from Typical CMakeLists.txt file)
Jump to navigationJump to search

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>