ITK & VTK 测试例子

来源:互联网 发布:有趣的js网页特效 编辑:程序博客网 时间:2024/05/11 02:39

Cmake新手,刚开始学习CmakeLists.txt编写,多看demo学习效率会高些,所以这里收集一些简单的CmakeLists.txt例子,有空再整理。

CMake1是个开源的跨平台自动化建构系统,它用配置文件控制建构过程(build process)的方式和Unix的Make相似,只是CMake的配置文件取名为CMakeLists.txt。Cmake并不直接建构出最终的软件,而是产生标准的建构档(如Unix的Makefile或Windows Visual C++的projects/workspaces),然后再依一般的建构方式使用。这使得熟悉某个集成开发环境(IDE)的开发者可以用标准的方式建构他的软件,这种可以使用各平台的原生建构系统的能力是CMake和SCons等其他类似系统的区别之处。CMake可以编译源代码、制做程序库、产生适配器(wrapper)、还可以用任意的顺序建构可执行文件。CMake支持in-place建构(二进档和源代码在同一个目录树中)和out-of-place建构(二进档在别的目录里),因此可以很容易从同一个源代码目录树中建构出多个二进档。CMake也支持静态与动态程序库的建构。
“CMake”这个名字是”cross platform make”的缩写。虽然名字中含有”make”,但是CMake和Unix上常见的“make”系统是分开的,而且更为高级。- https://cmake.org/cmake-tutorial/

ITK Installation Test

# This is the root ITK CMakeLists file.cmake_minimum_required(VERSION 2.8.9)if(COMMAND CMAKE_POLICY)  cmake_policy(SET CMP0003 NEW)endif()# This project is designed to be built outside the Insight source tree.project(ITK_Qt_Test)# Find ITK.find_package(ITK REQUIRED)include(${ITK_USE_FILE})add_executable(HelloWorld HelloWorld.cxx )target_link_libraries(HelloWorld ${ITK_LIBRARIES})

VTK Tutorial

cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)if(POLICY CMP0025)  cmake_policy(SET CMP0025 NEW) # CMake 3.0endif()if(POLICY CMP0053)  cmake_policy(SET CMP0053 NEW) # CMake 3.1endif()project (Step1)find_package(VTK COMPONENTS  vtkFiltersSources  vtkInteractionStyle  vtkRendering${VTK_RENDERING_BACKEND})include(${VTK_USE_FILE})add_executable(Cone MACOSX_BUNDLE Cone.cxx)target_link_libraries(Cone ${VTK_LIBRARIES})

ITK & VTK combined project

cmake_minimum_required(VERSION 2.4)if(COMMAND CMAKE_POLICY)  cmake_policy(SET CMP0003 NEW)endif()project(testproject)find_package(ITK REQUIRED)include(${ITK_USE_FILE})    if (ITKVtkGlue_LOADED)        find_package(VTK REQUIRED)         include(${VTK_USE_FILE})    else()        find_package(ItkVtkGlue REQUIRED)        include(${ItkVtkGlue_USE_FILE})        set(Glue ItkVtkGlue)    endif() add_executable(mytest MACOSX_BUNDLE test.cxx)target_link_libraries(mytest  ${Glue}  ${VTK_LIBRARIES} ${ITK_LIBRARIES})

References:

  1. cmake tutorial: https://cmake.org/cmake-tutorial/

  1. cmake wiki link: https://zh.wikipedia.org/wiki/CMake ↩
0 0